diff --git a/include/zephyr/shell/shell_uart.h b/include/zephyr/shell/shell_uart.h index 2b157aac6e7..5032c56f65e 100644 --- a/include/zephyr/shell/shell_uart.h +++ b/include/zephyr/shell/shell_uart.h @@ -7,6 +7,7 @@ #ifndef SHELL_UART_H__ #define SHELL_UART_H__ +#include #include #ifdef __cplusplus @@ -23,6 +24,13 @@ extern "C" { */ const struct shell *shell_backend_uart_get_ptr(void); +/** + * @brief This function provides pointer to the smp shell data of the UART shell transport. + * + * @returns Pointer to the smp shell data. + */ +struct smp_shell_data *shell_uart_smp_shell_data_get_ptr(void); + #ifdef __cplusplus } #endif diff --git a/subsys/mgmt/mcumgr/transport/src/smp_shell.c b/subsys/mgmt/mcumgr/transport/src/smp_shell.c index fc04bcd75c4..527ab2e47fa 100644 --- a/subsys/mgmt/mcumgr/transport/src/smp_shell.c +++ b/subsys/mgmt/mcumgr/transport/src/smp_shell.c @@ -59,13 +59,10 @@ enum smp_shell_mcumgr_state { }; #ifdef CONFIG_MCUMGR_TRANSPORT_SHELL_INPUT_TIMEOUT -extern struct shell_transport shell_transport_uart; - static void smp_shell_input_timeout_handler(struct k_timer *timer) { ARG_UNUSED(timer); - struct shell_uart *sh_uart = (struct shell_uart *)shell_transport_uart.ctx; - struct smp_shell_data *const data = &sh_uart->ctrl_blk->smp; + struct smp_shell_data *const data = shell_uart_smp_shell_data_get_ptr(); atomic_clear_bit(&data->esc_state, ESC_MCUMGR_PKT_1); atomic_clear_bit(&data->esc_state, ESC_MCUMGR_PKT_2); diff --git a/subsys/shell/backends/shell_uart.c b/subsys/shell/backends/shell_uart.c index b06cc4a09b8..5e4e3bd2c95 100644 --- a/subsys/shell/backends/shell_uart.c +++ b/subsys/shell/backends/shell_uart.c @@ -554,6 +554,10 @@ static int read(const struct shell_transport *transport, #ifdef CONFIG_MCUMGR_TRANSPORT_SHELL static void update(const struct shell_transport *transport) { + /* + * This is dependent on the fact that `struct shell_uart_common` + * is always the first member, regardless of the UART configuration + */ struct shell_uart_common *sh_uart = (struct shell_uart_common *)transport->ctx; smp_shell_process(&sh_uart->smp); @@ -583,6 +587,15 @@ SHELL_DEFINE(shell_uart, CONFIG_SHELL_PROMPT_UART, &shell_transport_uart, CONFIG_SHELL_BACKEND_SERIAL_LOG_MESSAGE_QUEUE_TIMEOUT, SHELL_FLAG_OLF_CRLF); +#ifdef CONFIG_MCUMGR_TRANSPORT_SHELL +struct smp_shell_data *shell_uart_smp_shell_data_get_ptr(void) +{ + struct shell_uart_common *common = (struct shell_uart_common *)shell_transport_uart.ctx; + + return &common->smp; +} +#endif + static int enable_shell_uart(void) { const struct device *const dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_shell_uart));