[nRF Connect SDK] memory requirement for nrf52810 OTA

Target nRF52810(nrf52dk_nrf52810)
SDK NCS v2.0.0
source: \NCS200\v2.0.0\nrf\samples\bluetooth\peripheral_lbs>


Hello
I'm preparing new project with nrf52810.
I build peripheral_lbs sample and found 97.25% of SRAM is being used.


1. Original source
Memory region Used Size Region Size %age Used
FLASH: 173960 B 192 KB 88.48%
SRAM: 24073 B 24 KB 97.95%
IDT_LIST: 0 GB 2 KB 0.00%


2. OTA SW added -> SRAM overflowed 1161.
# Enable mcumgr.
CONFIG_MCUMGR=y

# Enable most core commands.
CONFIG_MCUMGR_CMD_IMG_MGMT=y
CONFIG_MCUMGR_CMD_OS_MGMT=y

c:/ncs200/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.exe: zephyr\zephyr_pre0.elf section `noinit' will not fit in region `SRAM'
c:/ncs200/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.exe: region `SRAM' overflowed by 1161 bytes
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed

Finally we cannot use OTA. What do you say? Do I have to use nrf52832?

  • Hi Tim,

    As you have noted, the nRF52810 has less flash. There are a few changes we some time need to make to fit applications on it.

    I was able to build with the configuration you listed using prj_minimal.conf instead of prj.conf. Could you try that?

    [234/234] Linking C executable zephyr\zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:      137064 B       192 KB     69.71%
                 RAM:       21596 B        24 KB     87.87%
            IDT_LIST:          0 GB         2 KB      0.00%

    However, I understand that your goal is to add OTA DFU. Towards that, a few more configs are necessary, and prj_minimal.conf alone might not fix it. Are you following my colleague Simon's guide here by any chance?

    Hieu

  • Thanks for reply.

    I changed build command and found used SRAM decreased. 
    west build -b nrf52dk_nrf52810 -- -DCONF_FILE='prj_minimal.conf
    However I added CONFIG into prj_minimal.conf and failed due to memory leak.
    Can you correct me? 
    In addition, I have experience OTA SW experience with nrf52832 and know how I use it.

    1. In case prj_minimal.conf : 97.95% -> 68.30%
    Memory region Used Size Region Size %age Used
    FLASH: 132808 B 192 KB 67.55%
    SRAM: 16786 B 24 KB 68.30%
    IDT_LIST: 0 GB 2 KB 0.00%


    2. Add following four lines into prj_minimal.conf
    # Enable mcumgr.
    CONFIG_MCUMGR=y

    # Enable most core commands.
    CONFIG_MCUMGR_CMD_IMG_MGMT=y
    CONFIG_MCUMGR_CMD_OS_MGMT=y

    # Ensure an MCUboot-compatible binary is generated.
    CONFIG_BOOTLOADER_MCUBOOT=y

    Build result
    c:/ncs200/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.exe: zephyr\zephyr_pre0.elf section `text' will not fit in region `FLASH'
    c:/ncs200/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.exe: region `FLASH' overflowed by 63812 bytes
    collect2.exe: error: ld returned 1 exit status
    FAILED: modules/mcuboot/mcuboot_subimage-prefix/src/mcuboot_subimage-stamp/mcuboot_subimage-build mcuboot/zephyr/zephyr.hex mcuboot/zephyr/zephyr.elf
    cmd.exe /C "cd /D C:\NCS200\v2.0.0\nrf\samples\bluetooth\peripheral_lbs\build\mcuboot && C:\NCS200\toolchains\v2.0.0\opt\bin\cmake.exe --build . --"
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: 'C:\NCS200\toolchains\v2.0.0\opt\bin\cmake.EXE' --build 'C:\NCS200\v2.0.0\nrf\samples\bluetooth\peripheral_lbs\build'

    C:\NCS200\v2.0.0\nrf\samples\bluetooth\peripheral_lbs>

  • Hi Tim,

    My success was without CONFIG_BOOTLOADER_MCUBOOT, like your initial opening post. With CONFIG_BOOTLOADER_MCUBOOT, it also fails.

    I also thought that you would want to add MCUboot, so I have been looking into single application slot update. However, it seems there are no OTA solution for that.

    Is DFU over serial an option for you? Or does it have to be OTA?

    I am consulting some seniors in the team for other possibilities, but the hope doesn't look good.

  • Thanks for updating.
    Here is my sample source.
    peripheral_lbs_ota.7z 

    1. nrf52832
    *prj_minimal.conf
    build error like as nrf52810

    *prj.conf
    works well.

    2. nrf52810
    *prj_minimal.conf
    As you mentioned, I can remove "CONFIG_BOOTLOADER_MCUBOOT", then I could build it.

    I add following functions in main.c and build.
    os_mgmt_register_group();
    img_mgmt_register_group();
    smp_bt_register();

    c:/ncs200/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `main':
    C:\NCS200\v2.0.0\nrf\samples\bluetooth\peripheral_lbs\build/../src/main.c:309: undefined reference to `smp_bt_register'
    collect2.exe: error: ld returned 1 exit status

    To avoid link error, I add following config.
    CONFIG_MCUMGR_SMP_BT=y

    warning: HW_STACK_PROTECTION (defined at arch/Kconfig:249) was assigned the value 'y' but got the
    value 'n'. Check these unsatisfied dependencies: ARCH_HAS_STACK_PROTECTION (=n). See
    docs.zephyrproject.org/.../kconfig.html and/or look up
    HW_STACK_PROTECTION 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: BT_GATT_DYNAMIC_DB (defined at C:/NCS200/v2.0.0/zephyr/subsys/bluetooth/host\Kconfig.gatt:91, subsys/bluetooth\host\Kconfig.gatt:91) has direct dependencies (BT_GATT_SERVICE_CHANGED && BT_CONN && BT_HCI_HOST && BT_RPC_STACK) || (BT_GATT_SERVICE_CHANGED && BT_CONN && BT_HCI_HOST && BT_HCI && BT) with value n, but is currently being y-selected by the following symbols:
    - MCUMGR_SMP_BT (defined at subsys/mgmt/mcumgr/Kconfig:140), with value y, direct dependencies MCUMGR (value: y), and select condition MCUMGR (value: y)

    error: Aborting due to Kconfig warnings

    *prj.conf
    I could manage to build and flash it. 

    E: ***** MPU FAULT *****
    E: Stacking error (context area might be not valid)
    E: Data Access Violation
    E: MMFAR Address: 0x20005010
    E: r0/a1: 0x090317bb r1/a2: 0xc1f7ce6f r2/a3: 0xe4fcbcac
    E: r3/a4: 0xffd0fc09 r12/ip: 0xd3b6e9c3 r14/lr: 0xb1c7ded7
    E: xpsr: 0xdf7fdc00
    E: Faulting instruction address (r15/pc): 0x8fe9928b
    E: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
    E: Current thread: 0x20001ca0 (unknown)
    E: Resetting system


    PS
    I'm not available by the end of this week. I can reply next Monday.
    Thank you.

  • Hi Tim,

    Sorry, it seems I made you misunderstood. CONFIG_BOOTLOADER_MCUBOOT is essential and cannot be removed, whether on the nRF52810 or the nRF52832.

    First, regarding the build error with prj_minimal.conf that you will encounter even with the nRF52832:
    - You need to add all the config mentioned in my colleague Simon's guide into the project.
    - You also need to enable CONFIG_BT_GATT_SERVICE_CHANGED, which was turned off in prj_minimal.conf
    Below is the Kconfig fragment I used:

    # Enable mcumgr.
    CONFIG_MCUMGR=y
    
    # Enable most core commands.
    CONFIG_MCUMGR_CMD_IMG_MGMT=y
    CONFIG_MCUMGR_CMD_OS_MGMT=y
    
    # Ensure an MCUboot-compatible binary is generated.
    CONFIG_BOOTLOADER_MCUBOOT=y
    
    # Allow for large Bluetooth data packets.
    CONFIG_BT_L2CAP_TX_MTU=252
    CONFIG_BT_BUF_ACL_RX_SIZE=256
    
    # Enable the Bluetooth (unauthenticated) and shell mcumgr transports.
    CONFIG_BT_GATT_SERVICE_CHANGED=y # This was turned off in prj_minimal.conf
    CONFIG_MCUMGR_SMP_BT=y
    CONFIG_MCUMGR_SMP_BT_AUTHEN=n
    
    # Some command handlers require a large stack.
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096
    


    Next, regarding adding DFU to the nRF52810, I have asked consult with my team about DFU in this case. It looks like our only options in NCS are to use Serial Recovery for DFU, or using External Flash.

    Are any of those option possible for you?

    Alternatively, we can consider using the nRF5 SDK instead of NCS. We do not recommend it for new designs and projects, but if your project must have the nRF52810 and OTA DFU over BLE, then that is the only option.

    Hieu

Related