From cde2aacafd1751bd69bbda9493c61b9420db7368 Mon Sep 17 00:00:00 2001 From: Zak Portnoy Date: Tue, 5 Nov 2024 12:21:26 +0200 Subject: [PATCH] mgmt: smp: shell: Respond on uart shell device when changed at runtime Responses are currently set to the shell device that was configured in the device tree. The shell_uart driver allows for changing it's device during runtime which leads to a situation where we recieve packets on one device and respond on another. This patch causes smp_shell_tx_raw to use the shell_uart device Signed-off-by: Zak Portnoy (cherry picked from commit 32b1140066d13b9bd61ba95853e83ac83e5ff054) --- subsys/mgmt/mcumgr/transport/src/smp_shell.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/subsys/mgmt/mcumgr/transport/src/smp_shell.c b/subsys/mgmt/mcumgr/transport/src/smp_shell.c index 669f46391e9dd..ace999791f8b9 100644 --- a/subsys/mgmt/mcumgr/transport/src/smp_shell.c +++ b/subsys/mgmt/mcumgr/transport/src/smp_shell.c @@ -39,6 +39,8 @@ static struct smp_transport smp_shell_transport; static struct mcumgr_serial_rx_ctxt smp_shell_rx_ctxt; +static const struct shell_uart_common *shell_uart; + #ifdef CONFIG_SMP_CLIENT static struct smp_client_transport_entry smp_client_transport; #endif @@ -210,11 +212,10 @@ static uint16_t smp_shell_get_mtu(const struct net_buf *nb) static int smp_shell_tx_raw(const void *data, int len) { - static const struct device *const sh_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_shell_uart)); const uint8_t *out = data; while ((out != NULL) && (len != 0)) { - uart_poll_out(sh_dev, *out); + uart_poll_out(shell_uart->dev, *out); ++out; --len; } @@ -226,6 +227,7 @@ static int smp_shell_tx_pkt(struct net_buf *nb) { int rc; + shell_uart = (struct shell_uart_common *)shell_backend_uart_get_ptr()->iface->ctx; rc = mcumgr_serial_tx_pkt(nb->data, nb->len, smp_shell_tx_raw); smp_packet_free(nb);