diff --git a/include/mgmt/mcumgr/smp_shell.h b/include/mgmt/mcumgr/smp_shell.h index 4b4c999514e..0f220cc3dcf 100644 --- a/include/mgmt/mcumgr/smp_shell.h +++ b/include/mgmt/mcumgr/smp_shell.h @@ -47,6 +47,16 @@ bool smp_shell_rx_byte(struct smp_shell_data *data, uint8_t byte); */ void smp_shell_process(struct smp_shell_data *data); +/** + * @brief Initializes SMP transport over shell. + * + * This function should be called before feeding SMP transport with received + * data. + * + * @return 0 on success + */ +int smp_shell_init(void); + #ifdef __cplusplus } #endif diff --git a/include/shell/shell_uart.h b/include/shell/shell_uart.h index 68a3b0e5833..b1566a309ef 100644 --- a/include/shell/shell_uart.h +++ b/include/shell/shell_uart.h @@ -10,9 +10,7 @@ #include #include #include -#ifdef CONFIG_MCUMGR_SMP_SHELL #include "mgmt/mcumgr/smp_shell.h" -#endif #ifdef __cplusplus extern "C" { diff --git a/subsys/mgmt/mcumgr/smp_shell.c b/subsys/mgmt/mcumgr/smp_shell.c index f7bccc411c0..3f9d65fb5f3 100644 --- a/subsys/mgmt/mcumgr/smp_shell.c +++ b/subsys/mgmt/mcumgr/smp_shell.c @@ -154,14 +154,10 @@ static int smp_shell_tx_pkt(struct zephyr_smp_transport *zst, return rc; } -static int smp_shell_init(struct device *dev) +int smp_shell_init(void) { - ARG_UNUSED(dev); - zephyr_smp_transport_init(&smp_shell_transport, smp_shell_tx_pkt, smp_shell_get_mtu, NULL, NULL); return 0; } - -SYS_INIT(smp_shell_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); diff --git a/subsys/shell/shell_uart.c b/subsys/shell/shell_uart.c index 1b1cbd5d0f1..74116850fb5 100644 --- a/subsys/shell/shell_uart.c +++ b/subsys/shell/shell_uart.c @@ -285,6 +285,10 @@ static int enable_shell_uart(struct device *arg) return -ENODEV; } + if (IS_ENABLED(CONFIG_MCUMGR_SMP_SHELL)) { + smp_shell_init(); + } + shell_init(&shell_uart, dev, true, log_backend, level); return 0;