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 .

Parents
  • Hello Utsav,

    In a different DevZone case, I was able to emulate two UART COM on the same USB peripheral simply by setting one more cdc_acm_uart node under the usbd node. 

    		usbd: zephyr_udc0: usbd@40027000 {
    			compatible = "nordic,nrf-usbd";
    			reg = < 0x40027000 0x1000 >;
    			interrupts = < 0x27 0x1 >;
    			num-bidir-endpoints = < 0x1 >;
    			num-in-endpoints = < 0x7 >;
    			num-out-endpoints = < 0x7 >;
    			num-isoin-endpoints = < 0x1 >;
    			num-isoout-endpoints = < 0x1 >;
    			status = "okay";
    			cdc_acm_uart: cdc_acm_uart {
    				compatible = "zephyr,cdc-acm-uart";
    			};
    			cdc_acm_uart0: cdc_acm_uart0 {
    				compatible = "zephyr,cdc-acm-uart";
    				label = "CDC_ACM_0";
    			};

    Once that second virtual COM port is setup, you can select it for MCUmgr by overlaying the chosen property as such:

    /{
    	chosen {
    		zephyr,uart-mcumgr = &new_usb_uart_com;
    	};
    }

    Please note that it is the Christmas - New Year holiday season here. We are thus severely understaffed, and there would be delays in responses. Our apologies for the inconveniences. 

    Hieu

  • Hello   thanks for your response. I understand Christmas season is here and most of  the people would be on vacations. I really appreciate your response. 

    In the Bluetooth HCI_USB project I have done the following changes : 

    I have tried modifying the overlay file and here are the results : 

    The contents of my overlay file are as follows: 

    / {
    chosen {
    zephyr,code-partition = &slot0_partition;
    zephyr,out-usb = &cdc_acm1;
    zephyr,uart-mcumgr = &cdc_acm0;
    };
    };

    &zephyr_udc0 {
    cdc_acm0: cdc_acm0 {
    compatible = "zephyr,cdc-acm-uart";
    };
    cdc_acm1: cdc_acm1 {
    compatible = "zephyr,cdc-acm-uart";
    };
    };

    &uart0 {
    status = "okay";
    };

    The contents of my prj.conf file are as follows:

    CONFIG_STDOUT_CONSOLE=y
    CONFIG_GPIO=y
    CONFIG_SERIAL=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n

    CONFIG_BT=y
    CONFIG_BT_HCI_RAW=y

    CONFIG_USB_DEVICE_STACK=y
    CONFIG_USB_DEVICE_PID=0x000B
    CONFIG_USB_DEVICE_BLUETOOTH=y
    CONFIG_USB_DEVICE_BLUETOOTH_VS_H4=n

    # 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

    #This flag is enabled to make the mcuboot features for DFU available
    CONFIG_BOOTLOADER_MCUBOOT=y


    #Commands to add composite USB feature to HCI_USB program
    #Composite USB configuration ----------------
    CONFIG_USB_COMPOSITE_DEVICE=y
    #CONFIG_USB_CDC_ACM=y

    # Enable MCUmgr and dependencies.
    CONFIG_NET_BUF=y
    CONFIG_ZCBOR=y
    CONFIG_CRC=y
    CONFIG_MCUMGR=y
    CONFIG_STREAM_FLASH=y
    CONFIG_FLASH_MAP=y

    # Some command handlers require a large stack.
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2304
    CONFIG_MAIN_STACK_SIZE=2048

    # Enable flash operations.
    CONFIG_FLASH=y

    # Required by the `taskstat` command.
    CONFIG_THREAD_MONITOR=y

    # Support for taskstat command
    CONFIG_MCUMGR_GRP_OS_TASKSTAT=y

    # Enable statistics and statistic names.
    CONFIG_STATS=y
    CONFIG_STATS_NAMES=y

    # Enable most core commands.
    CONFIG_FLASH=y
    CONFIG_IMG_MANAGER=y
    CONFIG_MCUMGR_GRP_IMG=y
    CONFIG_MCUMGR_GRP_OS=y
    CONFIG_MCUMGR_GRP_STAT=y

    # Enable logging
    CONFIG_LOG=y
    CONFIG_MCUBOOT_UTIL_LOG_LEVEL_WRN=y

    # Disable debug logging
    CONFIG_LOG_MAX_LEVEL=3

    # Enable USB subsystem
    CONFIG_USB_DEVICE_STACK=y
    CONFIG_SERIAL=y
    CONFIG_UART_LINE_CTRL=y
    CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
    CONFIG_CONSOLE=y
    # USB backend is serial device
    CONFIG_MCUMGR_TRANSPORT_UART=y
    CONFIG_BASE64=y

    Then I have build the project using the following command : 

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

    After successful build, I flashed the program into the NRF5340 DK board and plugged in the other USB.

    You can see from the screenshot below that I get two virtual ports as ACM0 and ACM1 :

    But at the same time, the board is not visible as a Bluetooth controller under bluetoothctl . Only the default Bluetooth controller (of the laptop) is visible.

    How do I solve this? 

    Any other modifications that needs to be made? If yes then please let me know in which file and what needs to be done. 

    Thanks!

  •   since the dts file is created while building the project, any changes I make to this file will again be replaced once I rebuild the code

  • / {
    	chosen {
    	   zephyr,code-partition = &slot0_partition;
    	   zephyr,out-usb = &cdc_acm1;
    	   zephyr,uart-mcumgr = &cdc_acm0;
    	   zephyr,bt-mon-uart = &cdc_acm_uart;
    	   zephyr,bt-c2h-uart = &cdc_acm_uart;
    	};
     };
    
    &zephyr_udc0 {
    	cdc_acm0: cdc_acm0 {
    		compatible = "zephyr,cdc-acm-uart";
    	};
    	cdc_acm1: cdc_acm1 {
    		compatible = "zephyr,cdc-acm-uart";
    	};
    };
    
    &uart0 {
    	status = "okay";
    };

      I tried this modification in my overlay file but now the code does not compile. I have attached the overlay file contents.

  • Utsav R Shah said:
    but now the code does not compile.

    What is the error message?

  • west build -b nrf5340dk_nrf5340_cpuapp -- -DOVERLAY_CONFIG=overlay-cdc.conf -DDTC_OVERLAY_FILE=bl5340_dvk_cpuapp.overlay -DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE=\"/home/mutsl04176/ncs/v2.4.2/bootloader/mcuboot/root-rsa-2048.pem\"
    
    
    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base (cached)).
    -- Application: /home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb
    -- CMake version: 3.27.7
    -- Using NCS Toolchain 2.5.20231017.513615545433 for building. (/home/mutsl04176/ncs/toolchains/7795df4459/cmake)
    -- Found Python3: /home/mutsl04176/ncs/toolchains/7795df4459/usr/local/bin/python3 (found suitable exact version "3.8.2") found components: Interpreter 
    -- Cache files will be written to: /home/mutsl04176/.cache/zephyr
    -- Zephyr version: 3.3.99 (/home/mutsl04176/ncs/v2.4.2/zephyr)
    -- Found west (found suitable version "1.1.0", minimum required is "0.7.1")
    -- Board: nrf5340dk_nrf5340_cpuapp
    -- Found host-tools: zephyr 0.16.1 (/home/mutsl04176/ncs/toolchains/7795df4459/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.16.1 (/home/mutsl04176/ncs/toolchains/7795df4459/opt/zephyr-sdk)
    -- Found BOARD.dts: /home/mutsl04176/ncs/v2.4.2/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
    -- Found devicetree overlay: bl5340_dvk_cpuapp.overlay
    devicetree error: /chosen: undefined node label 'cdc_acm_uart'
    -- In: /home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb/build/zephyr, command: /home/mutsl04176/ncs/toolchains/7795df4459/usr/local/bin/python3;/home/mutsl04176/ncs/v2.4.2/zephyr/scripts/dts/gen_defines.py;--dts;/home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb/build/zephyr/zephyr.dts.pre;--dtc-flags;'-Wno-unique_unit_address_if_enabled';--bindings-dirs;/home/mutsl04176/ncs/v2.4.2/nrf/dts/bindings;/home/mutsl04176/ncs/v2.4.2/zephyr/dts/bindings;--header-out;/home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb/build/zephyr/include/generated/devicetree_generated.h.new;--dts-out;/home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb/build/zephyr/zephyr.dts.new;--edt-pickle-out;/home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb/build/zephyr/edt.pickle;--vendor-prefixes;/home/mutsl04176/ncs/v2.4.2/nrf/dts/bindings/vendor-prefixes.txt;--vendor-prefixes;/home/mutsl04176/ncs/v2.4.2/zephyr/dts/bindings/vendor-prefixes.txt
    CMake Error at /home/mutsl04176/ncs/v2.4.2/zephyr/cmake/modules/dts.cmake:276 (message):
      gen_defines.py failed with return code: 1
    Call Stack (most recent call first):
      /home/mutsl04176/ncs/v2.4.2/zephyr/cmake/modules/zephyr_default.cmake:115 (include)
      /home/mutsl04176/ncs/v2.4.2/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
      /home/mutsl04176/ncs/v2.4.2/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:97 (include_boilerplate)
      CMakeLists.txt:4 (find_package)
    
    
    -- Configuring incomplete, errors occurred!
    FATAL ERROR: command exited with status 1: /home/mutsl04176/.local/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb/build -GNinja -DOVERLAY_CONFIG=overlay-cdc.conf -DDTC_OVERLAY_FILE=bl5340_dvk_cpuapp.overlay '-DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE="/home/mutsl04176/ncs/v2.4.2/bootloader/mcuboot/root-rsa-2048.pem"' -S/home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb

Reply
  • west build -b nrf5340dk_nrf5340_cpuapp -- -DOVERLAY_CONFIG=overlay-cdc.conf -DDTC_OVERLAY_FILE=bl5340_dvk_cpuapp.overlay -DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE=\"/home/mutsl04176/ncs/v2.4.2/bootloader/mcuboot/root-rsa-2048.pem\"
    
    
    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base (cached)).
    -- Application: /home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb
    -- CMake version: 3.27.7
    -- Using NCS Toolchain 2.5.20231017.513615545433 for building. (/home/mutsl04176/ncs/toolchains/7795df4459/cmake)
    -- Found Python3: /home/mutsl04176/ncs/toolchains/7795df4459/usr/local/bin/python3 (found suitable exact version "3.8.2") found components: Interpreter 
    -- Cache files will be written to: /home/mutsl04176/.cache/zephyr
    -- Zephyr version: 3.3.99 (/home/mutsl04176/ncs/v2.4.2/zephyr)
    -- Found west (found suitable version "1.1.0", minimum required is "0.7.1")
    -- Board: nrf5340dk_nrf5340_cpuapp
    -- Found host-tools: zephyr 0.16.1 (/home/mutsl04176/ncs/toolchains/7795df4459/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.16.1 (/home/mutsl04176/ncs/toolchains/7795df4459/opt/zephyr-sdk)
    -- Found BOARD.dts: /home/mutsl04176/ncs/v2.4.2/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
    -- Found devicetree overlay: bl5340_dvk_cpuapp.overlay
    devicetree error: /chosen: undefined node label 'cdc_acm_uart'
    -- In: /home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb/build/zephyr, command: /home/mutsl04176/ncs/toolchains/7795df4459/usr/local/bin/python3;/home/mutsl04176/ncs/v2.4.2/zephyr/scripts/dts/gen_defines.py;--dts;/home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb/build/zephyr/zephyr.dts.pre;--dtc-flags;'-Wno-unique_unit_address_if_enabled';--bindings-dirs;/home/mutsl04176/ncs/v2.4.2/nrf/dts/bindings;/home/mutsl04176/ncs/v2.4.2/zephyr/dts/bindings;--header-out;/home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb/build/zephyr/include/generated/devicetree_generated.h.new;--dts-out;/home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb/build/zephyr/zephyr.dts.new;--edt-pickle-out;/home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb/build/zephyr/edt.pickle;--vendor-prefixes;/home/mutsl04176/ncs/v2.4.2/nrf/dts/bindings/vendor-prefixes.txt;--vendor-prefixes;/home/mutsl04176/ncs/v2.4.2/zephyr/dts/bindings/vendor-prefixes.txt
    CMake Error at /home/mutsl04176/ncs/v2.4.2/zephyr/cmake/modules/dts.cmake:276 (message):
      gen_defines.py failed with return code: 1
    Call Stack (most recent call first):
      /home/mutsl04176/ncs/v2.4.2/zephyr/cmake/modules/zephyr_default.cmake:115 (include)
      /home/mutsl04176/ncs/v2.4.2/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
      /home/mutsl04176/ncs/v2.4.2/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:97 (include_boilerplate)
      CMakeLists.txt:4 (find_package)
    
    
    -- Configuring incomplete, errors occurred!
    FATAL ERROR: command exited with status 1: /home/mutsl04176/.local/bin/cmake -DWEST_PYTHON=/usr/bin/python3 -B/home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb/build -GNinja -DOVERLAY_CONFIG=overlay-cdc.conf -DDTC_OVERLAY_FILE=bl5340_dvk_cpuapp.overlay '-DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE="/home/mutsl04176/ncs/v2.4.2/bootloader/mcuboot/root-rsa-2048.pem"' -S/home/mutsl04176/ncs/v2.4.2/zephyr/samples/bluetooth/hci_usb

Children
Related