Enable mcumgr features on NRF5340 DK board while Bluetooth HCI_USB program is running

Hello community,

I am trying for multiple firmware updates for my NRF5340 DK board. 

What I am doing is I have build and flashed the SMP server sample program found /zephyr/samples/subsys/mgmt/mcumgr/smp_svr

After flashing this application, I can see my board recognised as a ttyACM0 device while I perform ls /dev.

Using the mcumgr tool I am also able to flash the Bluetooth HCI_USB sample program and after confirming the image and resetting the board, the board now acts as a bluetooth controller. I can verify this using the bluetoothctl command.

Now If I want to do a firmware upgrade, I dont have any way in the HCI_USB application to go back to smp server application. How can I perform multiple firmware updates using mcumgr?

Can virtual com port concept be useful here? If yes then I would like to have a detailed tutorial for this .

  • Now you got the configuration I was talking about yes.
    Seems like we got another error at our hands since it does not work here.

    I am currently stuck out of office due to a snowstorm, meaning I can not use my linux computer at work. So I will try to find a colleague with Linux who can try to reproduce the issue you have now.

  • I was able to use both HCI and mcumgr work at the same time on the nRF52840DK by configuring the hci_uart sample.

    Here is the result:

    hci_uart_feat_cdc_feat_mcumgr_over_uart.zip

    diff --git a/samples/bluetooth/hci_rpmsg/prj.conf b/samples/bluetooth/hci_rpmsg/prj.conf
    index 755a1f4ac1e..f20005b69bc 100644
    --- a/samples/bluetooth/hci_rpmsg/prj.conf
    +++ b/samples/bluetooth/hci_rpmsg/prj.conf
    @@ -22,3 +22,5 @@ CONFIG_BT_BUF_CMD_TX_COUNT=10
     # CONFIG_BT_BUF_ACL_RX_SIZE=255
     # CONFIG_BT_BUF_ACL_TX_SIZE=251
     # CONFIG_BT_BUF_CMD_TX_SIZE=255
    +#
    +CONFIG_SECURE_BOOT=y
    diff --git a/samples/bluetooth/hci_uart/boards/nrf52840dk_nrf52840.overlay b/samples/bluetooth/hci_uart/boards/nrf52840dk_nrf52840.overlay
    index b3c844493c0..d91fa9bab8a 100644
    --- a/samples/bluetooth/hci_uart/boards/nrf52840dk_nrf52840.overlay
    +++ b/samples/bluetooth/hci_uart/boards/nrf52840dk_nrf52840.overlay
    @@ -1,8 +1,18 @@
     /* SPDX-License-Identifier: Apache-2.0 */
     
    -&uart0 {
    -	compatible = "nordic,nrf-uart";
    -	current-speed = <1000000>;
    -	status = "okay";
    -	hw-flow-control;
    +/ {
    +	chosen {
    +		zephyr,uart-mcumgr = &cdc_acm_uart1;
    +		zephyr,bt-mon-uart = &cdc_acm_uart0;
    +		zephyr,bt-c2h-uart = &cdc_acm_uart0;
    +	};
    +};
    +
    +&zephyr_udc0 {
    +	cdc_acm_uart0: cdc_acm_uart0 {
    +		compatible = "zephyr,cdc-acm-uart";
    +	};
    +	cdc_acm_uart1: cdc_acm_uart1 {
    +		compatible = "zephyr,cdc-acm-uart";
    +	};
     };
    diff --git a/samples/bluetooth/hci_uart/prj.conf b/samples/bluetooth/hci_uart/prj.conf
    index bdc73dd68e2..0cdf9e036b4 100644
    --- a/samples/bluetooth/hci_uart/prj.conf
    +++ b/samples/bluetooth/hci_uart/prj.conf
    @@ -1,6 +1,4 @@
    -CONFIG_CONSOLE=n
    -CONFIG_STDOUT_CONSOLE=n
    -CONFIG_UART_CONSOLE=n
    +CONFIG_LOG=y
     CONFIG_GPIO=y
     CONFIG_SERIAL=y
     CONFIG_UART_INTERRUPT_DRIVEN=y
    @@ -21,3 +19,25 @@ CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512
     # Workaround: Unable to allocate command buffer when using K_NO_WAIT since
     # Host number of completed commands does not follow normal flow control.
     CONFIG_BT_BUF_CMD_TX_COUNT=10
    +
    +CONFIG_BOOTLOADER_MCUBOOT=y
    +CONFIG_MCUMGR=y
    +CONFIG_MCUMGR_TRANSPORT_UART=y
    +CONFIG_MCUMGR_GRP_IMG=y
    +
    +# CONFIG_MCUMGR_TRANSPORT_UART dependencies
    +CONFIG_BASE64=y
    +
    +# CONFIG_MCUMGR_GRP_IMG dependencies
    +CONFIG_FLASH=y
    +CONFIG_IMG_MANAGER=y
    +
    +# CONFIG_IMG_MANAGER dependencies
    +CONFIG_STREAM_FLASH=y
    +
    +# CONFIG_MCUMGR dependencies
    +CONFIG_NET_BUF=y
    +CONFIG_ZCBOR=y
    +
    +# Required for CONFIG_IMG_MANAGER
    +CONFIG_FLASH_MAP=y
    diff --git a/samples/hello_world/CMakeLists.txt b/samples/hello_world/CMakeLists.txt
    index ecb7d24bb8f..c296e090cb7 100644
    --- a/samples/hello_world/CMakeLists.txt
    +++ b/samples/hello_world/CMakeLists.txt
    @@ -2,7 +2,15 @@
     
     cmake_minimum_required(VERSION 3.20.0)
     
    +set(CONFIG_SERIAL n)
    +set(mcuboot_CONFIG_SERIAL n)
    +set(hci_rpmsg_CONFIG_SERIAL n)
    +set(hci_rpmsg_b0n_CONFIG_SERIAL n)
    +
     find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
     project(hello_world)
     
     target_sources(app PRIVATE src/main.c)
    +
    +
    +test_runner_generate(src/example_test.c)
    diff --git a/samples/hello_world/prj.conf b/samples/hello_world/prj.conf
    index b2a4ba59104..0608e7a866c 100644
    --- a/samples/hello_world/prj.conf
    +++ b/samples/hello_world/prj.conf
    @@ -1 +1 @@
    -# nothing here
    +CONFIG_BOOTLOADER_MCUBOOT=y
    

    Changes should be similar for the nRF5340.

  • I tried the HCI_UART sample program with the following changes but the issue still remains. 

    Here are the contents of my prj.conf file : 

    CONFIG_CONSOLE=n
    CONFIG_STDOUT_CONSOLE=n
    CONFIG_UART_CONSOLE=n
    CONFIG_GPIO=y
    CONFIG_SERIAL=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_BT=y
    CONFIG_BT_HCI_RAW=y
    CONFIG_BT_HCI_RAW_H4=y
    CONFIG_BT_HCI_RAW_H4_ENABLE=y
    CONFIG_BT_BUF_ACL_RX_SIZE=255
    CONFIG_BT_BUF_CMD_TX_SIZE=255
    CONFIG_BT_BUF_EVT_DISCARDABLE_SIZE=255
    CONFIG_BT_CTLR_ASSERT_HANDLER=y
    CONFIG_BT_MAX_CONN=16
    CONFIG_BT_TINYCRYPT_ECC=n
    CONFIG_BT_CTLR_DTM_HCI=y
    
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512
    
    # Workaround: Unable to allocate command buffer when using K_NO_WAIT since
    # Host number of completed commands does not follow normal flow control.
    CONFIG_BT_BUF_CMD_TX_COUNT=10
    
    ###################################################################################################
    
    CONFIG_USB_DEVICE_STACK=y
    CONFIG_USB_DEVICE_PRODUCT="Zephyr HCI UART sample"
    CONFIG_USB_CDC_ACM=y
    CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
    
    CONFIG_BOOTLOADER_MCUBOOT=y
    CONFIG_MCUMGR=y
    CONFIG_MCUMGR_TRANSPORT_UART=y
    CONFIG_MCUMGR_GRP_IMG=y
    
    # CONFIG_MCUMGR_TRANSPORT_UART dependencies
    CONFIG_BASE64=y
    
    # CONFIG_MCUMGR_GRP_IMG dependencies
    CONFIG_FLASH=y
    CONFIG_IMG_MANAGER=y
    
    # CONFIG_IMG_MANAGER dependencies
    CONFIG_STREAM_FLASH=y
    
    # CONFIG_MCUMGR dependencies
    CONFIG_NET_BUF=y
    CONFIG_ZCBOR=y
    
    # Required for CONFIG_IMG_MANAGER
    CONFIG_FLASH_MAP=y

    And here is the content of my overlay file : 

    / {
    	chosen {
    		zephyr,uart-mcumgr = &cdc_acm_uart1;
    		zephyr,bt-mon-uart = &cdc_acm_uart0;
    		zephyr,bt-c2h-uart = &cdc_acm_uart0;
    	};
    };
    
    &zephyr_udc0 {
    	cdc_acm_uart0: cdc_acm_uart0 {
    		compatible = "zephyr,cdc-acm-uart";
    	};
    	cdc_acm_uart1: cdc_acm_uart1 {
    		compatible = "zephyr,cdc-acm-uart";
    	};
    };

    I build my program with this overlay file added by using the following command : 

    west build -b nrf5340dk_nrf5340_cpuapp --pristine -- -DDTC_OVERLAY_FILE=nrf5340dk_nrf5340_cpuapp.overlay -DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE=\"/home/mutsl04176/ncs/v2.4.2/bootloader/mcuboot/root-rsa-2048.pem\"

    After this I flashed the merged.hex file. But the issue still remains the same.

    I get two ACM ports while checking the ls /dev. But only the default bluetooth controller of the laptop comes up. I should be able to see 2 bluetooth controllers instead but that's still not happening :

  • Utsav R Shah said:
    I get two ACM ports while checking the ls /dev. But only the default bluetooth controller of the laptop comes up. I should be able to see 2 bluetooth controllers instead but that's still not happening :

    From HCI UART docs, did you run the following?

    sudo btattach -B /dev/ttyACMX -S 1000000

    Are you able to use mcumgr with the sample?

  • I ran the command and while the command is running, I can get the device to detect as a bluetooth controller as well as show up as a ttyACMx device . You can check the screenshot below : 

    But I am not able to use mcumgr with the sample. While trying to upload an image through mcumgr, the progress bar is stuck and it does not upload.

    This is the following command I am using to upload an image using mcumgr : 

    sudo ./mcumgr image upload app_update.bin --conntype=serial --connstring=/dev/ttyACM0

    As you can see it does not upload the image.

Related