Skip to content

Commit e268ed1

Browse files
nordicjmeivindj-nordic
authored andcommitted
mgmt: mcumgr: transport: Move BM UART code out into transport file
Allows including the BM UART transport in other applications and updates the UART MCUmgr sample to use this transport library Signed-off-by: Jamie McCrae <[email protected]>
1 parent 6879627 commit e268ed1

File tree

14 files changed

+153
-118
lines changed

14 files changed

+153
-118
lines changed

samples/mcumgr/uart_mcumgr/CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,5 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
1010
project(uart_mcumgr)
1111

1212
zephyr_include_directories(include)
13-
zephyr_include_directories(${ZEPHYR_BASE}/subsys/mgmt/mcumgr/util/include)
14-
zephyr_include_directories(${ZEPHYR_BASE}/subsys/mgmt/mcumgr/grp/img_mgmt/include)
1513
zephyr_include_directories(${ZEPHYR_BASE}/subsys/mgmt/mcumgr/transport/include)
16-
target_sources(app PRIVATE
17-
src/uart_mcumgr.c
18-
src/smp_uart.c
19-
${ZEPHYR_BASE}/subsys/mgmt/mcumgr/transport/src/serial_util.c
20-
)
21-
zephyr_linker_sources(SECTIONS mcumgr_handler.ld)
22-
zephyr_link_libraries(MCUBOOT_BOOTUTIL)
14+
target_sources(app PRIVATE src/main.c)

samples/mcumgr/uart_mcumgr/Kconfig

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,7 @@
66

77
menu "UART MCUmgr sample"
88

9-
config UART_MCUMGR_RX_BUF_SIZE
10-
int "Size of receive buffer for mcumgr fragments received over UART, in bytes"
11-
default 128
12-
help
13-
Specifies the size of the mcumgr UART receive buffer, in bytes. This
14-
value must be large enough to accommodate any line sent by an mcumgr
15-
client.
16-
17-
config UART_MCUMGR_RX_BUF_COUNT
18-
int "Number of receive buffers for mcumgr fragments received over UART"
19-
default 8
20-
help
21-
Specifies the number of the mcumgr UART receive buffers. Receive
22-
buffers hold received mcumgr fragments prior to reassembly. This
23-
setting's value must satisfy the following relation:
24-
UART_MCUMGR_RX_BUF_COUNT * UART_MCUMGR_RX_BUF_SIZE >=
25-
MCUMGR_TRANSPORT_UART_MTU
26-
27-
config UARTE_HWFC
28-
bool "UARTE HWFC"
29-
help
30-
Enable hardware flow control on the UARTE peripheral used by the application.
31-
32-
config UARTE_PARITY
33-
bool "UARTE parity"
34-
help
35-
Enable parity on the UARTE peripheral used by the application.
36-
37-
config UARTE_IRQ_PRIO
38-
int "UARTE IRQ priority"
39-
default 3
40-
41-
module=UART_MCUMGR_SAMPLE
9+
module=APP_UART_MCUMGR_SAMPLE
4210
module-str=UART MCUmgr Sample
4311
source "$(ZEPHYR_BASE)/subsys/logging/Kconfig.template.log_config"
4412

samples/mcumgr/uart_mcumgr/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CONFIG_CRC=y
2020
CONFIG_REBOOT=y
2121
CONFIG_NCS_BM_MCUMGR=y
2222
CONFIG_MCUMGR_TRANSPORT_REASSEMBLY=y
23+
CONFIG_MCUMGR_TRANSPORT_BM_UART=y
2324
CONFIG_MCUMGR_MGMT_NOTIFICATION_HOOKS=y
2425
CONFIG_MCUMGR_GRP_IMG=y
2526
CONFIG_MCUMGR_GRP_IMG_SLOT_INFO=y
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <string.h>
8+
#include <zephyr/kernel.h>
9+
#include <zephyr/drivers/uart.h>
10+
#include <zephyr/mgmt/mcumgr/transport/serial.h>
11+
#include <zephyr/drivers/console/uart_mcumgr.h>
12+
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
13+
#include <zephyr/mgmt/mcumgr/mgmt/callbacks.h>
14+
#include <zephyr/sys/reboot.h>
15+
#include <zephyr/logging/log.h>
16+
#include <nrfx_uarte.h>
17+
#include <smp_uart.h>
18+
#include <board-config.h>
19+
20+
LOG_MODULE_REGISTER(app_uart_mcumgr, CONFIG_APP_UART_MCUMGR_SAMPLE_LOG_LEVEL);
21+
22+
static bool should_reboot;
23+
24+
static enum mgmt_cb_return os_mgmt_reboot_hook(uint32_t event, enum mgmt_cb_return prev_status,
25+
int32_t *rc, uint16_t *group, bool *abort_more,
26+
void *data, size_t data_size);
27+
28+
static struct mgmt_callback os_mgmt_reboot_callback = {
29+
.callback = os_mgmt_reboot_hook,
30+
.event_id = MGMT_EVT_OP_OS_MGMT_RESET,
31+
};
32+
33+
static enum mgmt_cb_return os_mgmt_reboot_hook(uint32_t event, enum mgmt_cb_return prev_status,
34+
int32_t *rc, uint16_t *group, bool *abort_more,
35+
void *data, size_t data_size)
36+
{
37+
if (event == MGMT_EVT_OP_OS_MGMT_RESET) {
38+
should_reboot = true;
39+
*rc = MGMT_ERR_EOK;
40+
41+
return MGMT_CB_ERROR_RC;
42+
}
43+
44+
return MGMT_CB_OK;
45+
}
46+
47+
int main(void)
48+
{
49+
LOG_INF("UART MCUmgr sample started");
50+
51+
mgmt_callback_register(&os_mgmt_reboot_callback);
52+
53+
while (should_reboot == false) {
54+
/* Wait for an event. */
55+
__WFE();
56+
57+
/* Clear Event Register */
58+
__SEV();
59+
__WFE();
60+
61+
smp_uart_process_rx_queue();
62+
}
63+
64+
sys_reboot(SYS_REBOOT_WARM);
65+
}

scripts/ci/license_allow_list.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ Apache-2.0: |
5454
^nrf-bm/subsys/mgmt/mcumgr/transport/src/smp.c
5555
^nrf-bm/subsys/mgmt/mcumgr/util/CMakeLists.txt
5656
^nrf-bm/sysbuild/Kconfig.bm
57-
^nrf-bm/samples/mcumgr/uart_mcumgr/src/smp_uart.c
58-
^nrf-bm/samples/mcumgr/uart_mcumgr/src/uart_mcumgr.c
57+
^nrf-bm/subsys/mgmt/mcumgr/transport/src/bm_uart_mcumgr.c
58+
^nrf-bm/subsys/mgmt/mcumgr/transport/src/smp_uart.c
5959
^nrf-bm/lib/bm_zms/
6060
^nrf-bm/include/bm_zms.h
6161
^nrf-bm/tests/lib/bm_zms/

subsys/bluetooth/services/ble_mcumgr/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ zephyr_sources(mcumgr.c)
88
zephyr_include_directories(${ZEPHYR_BASE}/subsys/mgmt/mcumgr/util/include)
99
zephyr_include_directories(${ZEPHYR_BASE}/subsys/mgmt/mcumgr/grp/img_mgmt/include)
1010
zephyr_include_directories(${ZEPHYR_BASE}/subsys/mgmt/mcumgr/transport/include)
11-
zephyr_linker_sources(SECTIONS mcumgr_handler.ld)
11+
zephyr_linker_sources(SECTIONS ${ZEPHYR_NRF_BM_MODULE_DIR}/subsys/mgmt/mcumgr/transport/mcumgr_handler.ld)
1212
zephyr_link_libraries(MCUBOOT_BOOTUTIL)

subsys/bluetooth/services/ble_mcumgr/mcumgr_handler.ld

Lines changed: 0 additions & 1 deletion
This file was deleted.

subsys/mgmt/mcumgr/transport/CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright (c) 2018-2021 mcumgr authors
3-
# Copyright (c) 2022 Nordic Semiconductor ASA
3+
# Copyright (c) 2022-2025 Nordic Semiconductor ASA
44
#
55
# SPDX-License-Identifier: Apache-2.0
66
#
@@ -14,8 +14,12 @@ zephyr_library_sources_ifdef(CONFIG_MCUMGR_TRANSPORT_REASSEMBLY
1414
${ZEPHYR_BASE}/subsys/mgmt/mcumgr/transport/src/smp_reassembly.c
1515
)
1616

17-
#if(CONFIG_MCUMGR_TRANSPORT_SHELL OR CONFIG_MCUMGR_TRANSPORT_UART)
18-
# zephyr_library_sources(src/serial_util.c)
19-
#endif()
17+
zephyr_library_sources_ifdef(CONFIG_MCUMGR_TRANSPORT_BM_UART
18+
src/smp_uart.c
19+
src/bm_uart_mcumgr.c
20+
${ZEPHYR_BASE}/subsys/mgmt/mcumgr/transport/src/serial_util.c
21+
)
2022

21-
zephyr_include_directories(${ZEPHYR_BASE}/subsys/mgmt/mcumgr/transport/include)
23+
zephyr_include_directories(${ZEPHYR_BASE}/subsys/mgmt/mcumgr/transport/include include)
24+
zephyr_library_include_directories(${ZEPHYR_BASE}/subsys/mgmt/mcumgr/util/include)
25+
zephyr_linker_sources(SECTIONS mcumgr_handler.ld)

subsys/mgmt/mcumgr/transport/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ config MCUMGR_TRANSPORT_NETBUF_SIZE
3737
module = MCUMGR_TRANSPORT
3838
module-str = mcumgr_transport
3939
source "subsys/logging/Kconfig.template.log_config"
40+
41+
rsource "Kconfig.bm_uart"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright Nordic Semiconductor ASA 2025. All rights reserved.
2+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
3+
4+
# The Kconfig file is dedicated to the BM UART transport of MCUmgr
5+
# subsystem and provides Kconfig options to control aspects of
6+
# the transport.
7+
#
8+
# Options defined in this file should be prefixed:
9+
# MCUMGR_TRANSPORT_BM_UART_
10+
11+
menuconfig MCUMGR_TRANSPORT_BM_UART
12+
bool "Bare Metal UART MCUmgr SMP transport"
13+
depends on BASE64
14+
depends on CRC
15+
help
16+
Enables handling of SMP commands received over UART.
17+
18+
if MCUMGR_TRANSPORT_BM_UART
19+
20+
config MCUMGR_TRANSPORT_BM_UART_UARTE_HWFC
21+
bool "UARTE HWFC"
22+
help
23+
Enable hardware flow control on the UARTE peripheral used by the application.
24+
25+
config MCUMGR_TRANSPORT_BM_UART_UARTE_PARITY
26+
bool "UARTE parity"
27+
help
28+
Enable parity on the UARTE peripheral used by the application.
29+
30+
config MCUMGR_TRANSPORT_BM_UART_UARTE_IRQ_PRIO
31+
int "UARTE IRQ priority"
32+
default 3
33+
34+
config MCUMGR_TRANSPORT_BM_UART_RX_BUF_SIZE
35+
int "Size of receive buffer for mcumgr fragments received over UART, in bytes"
36+
default 128
37+
help
38+
Specifies the size of the mcumgr UART receive buffer, in bytes. This
39+
value must be large enough to accommodate any line sent by an mcumgr
40+
client.
41+
42+
# Duplicate Zephyr symbol without console dependency to allow usage of Zephyr header file
43+
config UART_MCUMGR_RX_BUF_SIZE
44+
int
45+
default MCUMGR_TRANSPORT_BM_UART_RX_BUF_SIZE
46+
47+
config MCUMGR_TRANSPORT_BM_UART_RX_BUF_COUNT
48+
int "Number of receive buffers for mcumgr fragments received over UART"
49+
default 8
50+
help
51+
Specifies the number of the mcumgr UART receive buffers. Receive
52+
buffers hold received mcumgr fragments prior to reassembly. This
53+
setting's value must satisfy the following relation:
54+
UART_MCUMGR_RX_BUF_COUNT * UART_MCUMGR_RX_BUF_SIZE >=
55+
MCUMGR_TRANSPORT_UART_MTU
56+
57+
endif # MCUMGR_TRANSPORT_BM_UART

0 commit comments

Comments
 (0)