Configure Bluetooth: Peripheral UART application, bootloader and etc.

Hi !

I have selected sample https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/nrf/samples/bluetooth/peripheral_uart/README.html#peripheral-uart

as basis for evaluate USB_CDC_ACM connectivity to app core and USB_CDC_ACM Recovery mode ( app and network core) via MCUBoot bootloader.

I assume SMP server need to be allocated in MCUBoot and App core and Network core can be updated  ( without using any copies in flash memory ) by using mcumgr utility.

1.

I hide some definition in environmental variables for operate with simple command line :

west build --build-dir ./build  . --pristine --board nrf5340dk_nrf5340_cpuapp -- -DBOARD_ROOT=. -DDTC_OVERLAY_FILE="app.overlay" -DCONF_FILE="prj.conf"

this configuration can be compiled and flashed without any problems. I can see some debug traces from DK board via ACM0 and 1 USB serial ports.

I assume VS and command line build environment is configured properly.

2. Change App core connectivity from serial to USB_CDC_ACM according recommendation

west build --build-dir ./build  . --pristine --board nrf5340dk_nrf5340_cpuapp -- -DBOARD_ROOT=. -DDTC_OVERLAY_FILE="usb.overlay" -DCONF_FILE="prj_cdc.conf"

Errors

"

Loaded configuration '/home/yevgen/ncs/v2.2.0/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp_defconfig'
Merged configuration '/home/yevgen/nsctest/cpuapp/prj_cdc.conf'

warning: BT_SMP (defined at subsys/bluetooth/host/Kconfig:317, subsys/bluetooth/host/Kconfig:317) has direct dependencies (BT_CONN && BT_HCI_HOST && BT_RPC_STACK) || (BT_CONN && BT_HCI_HOST && BT_HCI && BT) with value n, but is currently being y-selected by the following symbols:
- BT_NUS_SECURITY_ENABLED (defined at /home/yevgen/nsctest/cpuapp/Kconfig:23), with value y, direct dependencies y (value: y)

error: Aborting due to Kconfig warnings

CMake Error at /home/yevgen/ncs/v2.2.0/zephyr/cmake/modules/kconfig.cmake:328 (message):
command failed with return code: 1

"

if I disable BT security, other errors popups

"

42 | #define DEVICE_NAME CONFIG_BT_DEVICE_NAME
| ^~~~~~~~~~~~~~~~~~~~~
/home/yevgen/ncs/v2.2.0/zephyr/include/zephyr/bluetooth/bluetooth.h:375:30: note: in definition of macro 'BT_DATA'
375 | .data_len = (_data_len), \
| ^~~~~~~~~
../src/main.c:43:33: note: in expansion of macro 'DEVICE_NAME'
43 | #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
| ^~~~~~~~~~~
../src/main.c:76:53: note: in expansion of macro 'DEVICE_NAME_LEN'
76 | BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),

"

So it is exists some errors in application ?

3. I have returned to original configuration DCONF_FILE="prj.conf" and try to add MCUBoot configuration to application and configure MCUBoot itself.

e.g add extra lines to prj.conf

# MCUBoot serial
CONFIG_MCUBOOT_SERIAL=y
CONFIG_MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD=y

# The following configurations are required to support serial recovery of the
# network image
CONFIG_PCD_APP=y

CONFIG_FLASH_SIMULATOR=y
CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=y
CONFIG_FLASH_SIMULATOR_STATS=n

CONFIG_BOOT_IMAGE_ACCESS_HOOKS=y
CONFIG_NRF53_RECOVERY_NETWORK_CORE=y

CONFIG_MCUBOOT_INDICATION_LED=y

OR

west build --build-dir ./build . --pristine --board nrf5340dk_nrf5340_cpuapp -- -DBOARD_ROOT=. -DDTC_OVERLAY_FILE="app.overlay" -DCONF_FILE="prj.conf" -DOVERLAY_CONFIG="nrf5340dk_mcuboot_sr_net.conf"

and

Merged configuration '/home/yevgen/nsctest/cpuapp/prj.conf'

warning: BOOT_IMAGE_ACCESS_HOOKS (defined at modules/Kconfig.mcuboot_bootutil:24) was assigned the
value 'y' but got the value 'n'. Check these unsatisfied dependencies: MCUBOOT_BOOTUTIL_LIB (=n).
See docs.zephyrproject.org/.../kconfig.html and/or look up
BOOT_IMAGE_ACCESS_HOOKS in the menuconfig/guiconfig interface. The Application Development Primer,
Setting Configuration Values, and Kconfig - Tips and Best Practices sections of the manual might be
helpful too.


warning: FLASH_SIMULATOR (defined at drivers/flash/Kconfig.simulator:6) was assigned the value 'y'
but got the value 'n'. Check these unsatisfied dependencies: DT_HAS_ZEPHYR_SIM_FLASH_ENABLED (=n).
See docs.zephyrproject.org/.../kconfig.html and/or look up
FLASH_SIMULATOR in the menuconfig/guiconfig interface. The Application Development Primer, Setting
Configuration Values, and Kconfig - Tips and Best Practices sections of the manual might be helpful
too.


warning: FLASH_SIMULATOR_DOUBLE_WRITES (defined at drivers/flash/Kconfig.simulator:25) was assigned
the value 'y' but got the value 'n'. Check these unsatisfied dependencies: FLASH_SIMULATOR (=n). See
docs.zephyrproject.org/.../kconfig.html and/or look
up FLASH_SIMULATOR_DOUBLE_WRITES in the menuconfig/guiconfig interface. The Application Development
Primer, Setting Configuration Values, and Kconfig - Tips and Best Practices sections of the manual
might be helpful too.


/home/yevgen/nsctest/cpuapp/prj.conf:53: warning: attempt to assign the value 'y' to the undefined symbol MCUBOOT_SERIAL

/home/yevgen/nsctest/cpuapp/prj.conf:54: warning: attempt to assign the value 'y' to the undefined symbol MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD

/home/yevgen/nsctest/cpuapp/prj.conf:65: warning: attempt to assign the value 'y' to the undefined symbol NRF53_RECOVERY_NETWORK_CORE

/home/yevgen/nsctest/cpuapp/prj.conf:67: warning: attempt to assign the value 'y' to the undefined symbol MCUBOOT_INDICATION_LED

error: Aborting due to Kconfig warnings

4. Could it be possible to guide me with MCUBoot configuration for this project ?

The next features are expected:

- SMP server located in MCUBoot only

- Serial recovery method is used for update App and Network cores ( no extra copies of firmware in mcu's flash memory or external serial memory )

- USB_CDC_ACM connectivity to MCUBoot

- Enable multiimage build e.g *zip what contains updates for both cores.

5. Also not so clear how to change child network core project for current image. Looks like it is hardcoded somewhere.

Regards,

Eugene

 

  • Hi !

    Just correction for my question.

    1. No success with usage of USB_CDC_ACM  in actual application e.g lines

    west build --build-dir ./build  . --pristine --board nrf5340dk_nrf5340_cpuapp -- -DBOARD_ROOT=. -DDTC_OVERLAY_FILE="usb.overlay" -DCONF_FILE="prj_cdc.conf"

    2.

    I'm able to build image with MCUboot by using command line:

    $ west build --build-dir ./build  . --pristine --board nrf5340dk_nrf5340_cpuapp -- -DBOARD_ROOT=. -DDTC_OVERLAY_FILE="app.overlay" -DCONF_FILE="prj.conf" -DOVERLAY_CONFIG="nrf5340dk_app_sr_net.conf" -Dmcuboot_OVERLAY_CONFIG="$(pwd)/nrf5340dk_mcuboot_sr_net.conf"

    I have got set of images

    [293/303] Generating ../../zephyr/app_update.bin
    sign the payload
    [294/303] Generating ../../zephyr/net_core_app_update.bin
    sign the payload
    [296/303] Generating ../../zephyr/net_core_app_signed.hex
    sign the payload
    [297/303] Generating ../../zephyr/net_core_app_test_update.hex
    sign the payload
    [299/303] Generating ../../zephyr/app_test_update.hex
    sign the payload
    [300/303] Generating ../../zephyr/app_signed.hex
    sign the payload
    [303/303] Generating zephyr/merged_domains.hex

    where app_update.bin and net_core_app_update.bin can be used by mcumgr for update firmware.

    But really it is not so clear where are separate images for mcuboot and b0n updates what can be used for initial flashing of a board.

    Looks like composite images only.

    Due lack of traces difficalt to conclude how nrf5340dk_mcuboot_sr_net.conf really works. Does external memory in use or not.

    How serial recovery work in this case ?

    Regards,

    Eugene

  • Hi,

    Instead of answering your questions one by one, I created an example to do the following:

    • Serial Recovery over CDC_ACM
    • For both cores of the nRF5340
    • nRF Connect SDK v2.2.0

    mcuboot_serial_recovery_cdc_acm_nrf5340_external_flash_both_cores.zip

    The configurations for this sample is based on nRF Machine Learning sample.
    The base is from my unofficial Serial Recovery sample.

    You upload an update to the network core using:

    mcumgr  -c acm0 image upload build/zephyr/net_core_app_update.bin -n 3
    

    PS: You might have to shorten the projects name before building if you use windows.

    I hope this can help you.

    Let me know which of your questions are still relevant after looking at this sample.

    Regards,
    Sigurd Hellesvik

  • Hi Sigurd Hellesvik !

    Thank you !

    I'm using Ubuntu 20.04 and latest v2.2.0 SDK for my questions and examples.

    Few overall questions about example mcuboot_serial_recovery_cdc_acm_nrf5340_external_flash_both_cores.zip 

    I have build iit from command line

    west build --pristine --board nrf5340dk_nrf5340_cpuapp -- -DDTC_OVERLAY_FILE="app.overlay"

     1. It looks as most advanced configuration when App and network core is huge and updated via proxy storage ( external memory only or some partitions in app memory ?)

    2. I have tried to enable any debug uart traces from both bootloaders but no any luck. Even all flags like UART log are set.

    3. What mean -n flag for mcumgr ? It is not visible in help of utility ?

    4. How networkapplication hci_rpmg defined as child project ? Definition is not visible in project files. Looks as some trick.

     5. MCUBoot is visible as child image but n0b bootloader not. Does it appears somehow automatically ?

    6. Network core image is updated without problem:

    mcumgr -c acm2 image upload build/zephyr/net_core_app_update.bin -n 3
    181.71 KiB / 181.71 KiB [=========================================================================================================================] 100.00% 1.33 KiB/s 2m16s
    Done

    But app and composite always freeze at the end.

    mcumgr -c acm2 image upload build/zephyr/app_update.bin -n 3
    46.77 KiB / 46.91 KiB [====================================================================================================================================] 99.71% 477 B/s

    mcumgr -c acm2 image upload build/zephyr/dfu_application.zip -n 3
    230.07 KiB / 230.18 KiB [===================================================================================================================================] 99.95% 22 B/s

    Should they be updated directly or via hiddent reboot ?

    Or how whole flow works in your sample ?

    7. I have study sample in more details and by using your example , have changed MCUboot partition  size and move it to USB serial port.

    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.2.0/nrf/samples/bluetooth/peripheral_uart/README.html#peripheral-uart

    App and net cores can be updated one by one.

    8. It might be so that sample is close to your picture

    https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/nrf5340#non-simultaneous-update

    But this moment is not so clear : "When updating the network core, the new image will be saved to the secondary slot. On a reboot, the image will be swapped with the network core over the shared SRAM:"

    I look for MCUBoot configuration what updating of both cores are not required usage any spare memory on internal flash memory and external one. 

    peripheral uart bootloader configuration ( important parts) looks like this

    CONFIG_FLASH=y

    # MCUBoot serial
    CONFIG_MCUBOOT_SERIAL=y
    CONFIG_MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD=y

    # The following configurations are required to support serial recovery of the
    # network image
    CONFIG_PCD_APP=y

    CONFIG_FLASH_SIMULATOR=y
    CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES=y
    CONFIG_FLASH_SIMULATOR_STATS=n

    CONFIG_BOOT_IMAGE_ACCESS_HOOKS=y
    CONFIG_NRF53_RECOVERY_NETWORK_CORE=y

    CONFIG_MCUBOOT_INDICATION_LED=y

    # Extra
    CONFIG_BOOT_SERIAL_CDC_ACM=y
    CONFIG_SIZE_OPTIMIZATIONS=y
    CONFIG_UART_CONSOLE=y
    CONFIG_LOG=y

    CONFIG_UPDATEABLE_IMAGE_NUMBER=1

    External memory is not defined anywhere, extra partitions as well.

    Does this configuration is close to your picture https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/nrf5340#non-simultaneous-update

    Or this is something else ?

    How can looks configuration when :

    - Serial recovery method is required for both cores. e.g. direct update without usage of extra flash slots and external serial memory.

    - To avoid external memory usage, the case when application and network core images can be updated separately is also accepted ( but no idea if external memory is really needed in case of serial recovery and multiimage.zip).

    - SMP server is located in MCUBoot only ( no need in application ) e.g update is triggered by GPIO line.

      Triggering works as expected and any GPIO line can be configured and I hope SMP server is not included by default in APP.

    ?

    Regards,

    Eugene

  • Hi Eugene,

    Hiihtaja said:
     1. It looks as most advanced configuration when App and network core is huge and updated via proxy storage ( external memory only or some partitions in app memory ?)

    When using the nRF5340 with bootloaders for both cores, you need three slots: primary, secondary and secondary_1.
    Splitting the flash memory into three will decrease available space. Therefore, the machine learning sample uses external flash for the secondary partitions.

    Hiihtaja said:
    2. I have tried to enable any debug uart traces from both bootloaders but no any luck. Even all flags like UART log are set.

    This is because the serial recovery use the uart.
    I recommend using UART if you need logs from the bootloader:
    See an example at https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/blob/2ab21b02484dd41216454a33d7db8b4cd5c1952d/bootloader_samples/serial_recovery/mcuboot_serial_recovery_cdc_acm_wait/child_image/mcuboot.conf .

    Hiihtaja said:
    3. What mean -n flag for mcumgr ? It is not visible in help of utility ?

    Also see https://docs.zephyrproject.org/3.2.0/services/device_mgmt/mcumgr.html.

    and my own explanation from https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/smp/mcuboot_smp#extra-steps-for-the-nrf5340:

    The -n numbers are set as follows:

    slot 0 - image 0 primary
    slot 1 - image 0 secondary
    slot 2 - image 1 primary ("Virtual" slot)
    slot 3 - image 1 secondary
    

    Hiihtaja said:
    4. How networkapplication hci_rpmg defined as child project ? Definition is not visible in project files. Looks as some trick.

    From Working with nRF5340 DK, you can see that if CONFIG_BT=y, the build system will add hci_rpmsg to the system.
    Try to add a print to the sample, and see your net core print it on the net-core VCOM.

    Hiihtaja said:
     5. MCUBoot is visible as child image but n0b bootloader not. Does it appears somehow automatically ?

    It is because n0b is a child image of hci_rpmsg.
    You can see it at build/hci_rpmsg/b0n.

    Hiihtaja said:

    Should they be updated directly or via hiddent reboot ?

    Or how whole flow works in your sample ?


    PCD
    is enabled in MCUboot.
    So it will update the network core after upload the image, before a reboot.
    Because of this, I recommend that you wait 1-2 minutes after the upload is done before resetting the device.
    Then the new netcore image should run on the net-core on the next reboot.
    EDIT: I am unsure of this, and will have to research it a bit more as well.

    I will have to look into the last questions, and come back to answer them by end of friday.

    Regards,
    Sigurd Hellesvik

  • Sigurd Hellesvik said:
    PCD is enabled in MCUboot.
    So it will update the network core after upload the image, before a reboot.
    Because of this, I recommend that you wait 1-2 minutes after the upload is done before resetting the device.
    Then the new netcore image should run on the net-core on the next reboot.

    PCD is enabled for MCUboot for both serial recovery and normal operations.
    First, a new update for NET core is uploaded to the secondary slot.
    Then on a reboot, MCUboot will check this slot. If the secondary slot has an image for the NET core, MCUboot will perform the swap operation

    Hiihtaja said:

    8. It might be so that sample is close to your picture

    https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/nrf5340#non-simultaneous-update

    But this moment is not so clear : "When updating the network core, the new image will be saved to the secondary slot. On a reboot, the image will be swapped with the network core over the shared SRAM:"

    After some testing, it seems like this figure works for SMP Server + MCUboot but not for Serial Recovery.
    It seems that serial recovery only permits one slot by default.
    If we are able to configure serial recovery to use two slots here, we could upload a new netcore image to the secondary slot, and the update should be applied.

    Another alternative could be to implement a MCUboot hook to handle this.

    Hiihtaja said:

    External memory is not defined anywhere, extra partitions as well.

    Does this configuration is close to your picture https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/tree/main/bootloader_samples/nrf5340#non-simultaneous-update

    Or this is something else ?

    For my external flash sample, it is not like this figure, because the external flash sample parts the flash into three slots.
    Use "Memory Report" in VS Code or "west build -t partition_manager_report" to see the slots.

    Hiihtaja said:

    How can looks configuration when :

    - Serial recovery method is required for both cores. e.g. direct update without usage of extra flash slots and external serial memory.

    - To avoid external memory usage, the case when application and network core images can be updated separately is also accepted ( but no idea if external memory is really needed in case of serial recovery and multiimage.zip).

    - SMP server is located in MCUBoot only ( no need in application ) e.g update is triggered by GPIO line.

      Triggering works as expected and any GPIO line can be configured and I hope SMP server is not included by default in APP.

    ?

    For the external flash example, if you run "mcumgr -acm0 image list", you can see the serial recovery bootloader list 2 slots.
    I suggest that you try to figure out how the serial recovery enables the second slot in this sample.
    Then you should be able to configure the example with internal flash to also have a second slot in the same way.
    If you now upload a netcore image to this seconds slot, it should swap.

    Alternativley you could add an MCUboot hook and make the primary slot also being checked for netcore updates.
    I think the current hook ishttps://github.com/nrfconnect/sdk-nrf/blob/main/modules/mcuboot/hooks/nrf53_hooks.c.

    Regards,
    Sigurd Hellesvik

Related