Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Reducing RAM usage on nRF52811

Hi!

I'm porting our application from nRF52832 (SD132 6.3.1, SDK 15.2.0) to nRF52811. We're intereset in the nRF52811 because of its smaller size with the WLCSP package. Our application is quite heavy in that it allows 2 concurrent connections with DLE, LESC, bonding and peer manager, as well as DFU. So I'm obviously expecting to have to cut down on something to make everything fit in the reduced Flash and RAM. I've already cut down on the Central capability, which is not available now with SD112.

I'm aiming for the nRF52811 with Soft Device 112, version 7.2.0 and SDK 17.1.0. I'm currently developing on the nRF52840 DK, using IAR EW ARM 9.30. I started on the ble_app_template example project and started adding our code and settings.

Right now, Flash seems to fit. However, I'm having a bit of trouble with RAM. The error I get is that either the linker runs out of space and fails to build or the soft device refuses to run because there's too much RAM used by the application. I've read through the guide to fine tune the RAM and flash start addresses, I'm already using the maximum RAM size the Soft Device will allow me. I've already tried bringing down the MTU size to the minimum and maximum connections to 1, but it's still a bit short. 

This is the IAR Linker output:

68'812 bytes of readonly code memory
14'487 bytes of readonly data memory
18'625 bytes of readwrite data memory

What else can I do to bring the RAM footprint down? Either for the app or for the SoftDevice. There must be something in the sdk_config that I can disable but it's too big to start trying without some common sense guidance.

I've noticed that disabling the log has a big impact and actually makes it fit. After setting "#define NRF_LOG_ENABLED 0", this is the output.

57'464 bytes of readonly code memory
3'479 bytes of readonly data memory
16'280 bytes of readwrite data memory

Why is there so much memory being used by the log? There's like 10k of readonly data memory, which probably is for the logged strings right? (not the actual log storage, but the contents of the eventually logged messages, if that makes sense). Is this being placed in RAM or FLASH? If it's in RAM, is there a way to change them to flash? 

Thanks and take care!

Parents
  • I've noticed that disabling the log has a big impact and actually makes it fit. After setting "#define NRF_LOG_ENABLED 0", this is the output.

    This sounds correct, Logs are used for prototyping and not for release versions. Which the chip revisions with smaller memories, some of the applications won't be able to afford having logging feature. You can continue to prototype your application on nRf52840 (If logging is necessary) and then do your final testing on the nrf52811 without the logs and with compiler/linker optimizations enabled.

    What else can I do to bring the RAM footprint down? Either for the app or for the SoftDevice. There must be something in the sdk_config that I can disable but it's too big to start trying without some common sense guidance.

    Softdevice code size is fixed and its RAM size depends on the number of roles and the attribute size you select in the sdk_config.h file. Apart from that there is nothing much to configure on the softdevice size.

    On your application side, disable logs and UART if you are not using them. If you have used another example as template, it might be possible that it has some other peripherals that you do not use initialized and enabled.

Reply
  • I've noticed that disabling the log has a big impact and actually makes it fit. After setting "#define NRF_LOG_ENABLED 0", this is the output.

    This sounds correct, Logs are used for prototyping and not for release versions. Which the chip revisions with smaller memories, some of the applications won't be able to afford having logging feature. You can continue to prototype your application on nRf52840 (If logging is necessary) and then do your final testing on the nrf52811 without the logs and with compiler/linker optimizations enabled.

    What else can I do to bring the RAM footprint down? Either for the app or for the SoftDevice. There must be something in the sdk_config that I can disable but it's too big to start trying without some common sense guidance.

    Softdevice code size is fixed and its RAM size depends on the number of roles and the attribute size you select in the sdk_config.h file. Apart from that there is nothing much to configure on the softdevice size.

    On your application side, disable logs and UART if you are not using them. If you have used another example as template, it might be possible that it has some other peripherals that you do not use initialized and enabled.

Children
  • Hi Susheel, 

    Thanks for the answer! I understand we might need to disable logging for the 811. Also, debugging on the 840 and moving to 811 for final release makes sense. 

    I still have a few questions about what you suggest for Soft Device optimization. What do you mean exactly by:

    Softdevice code size is fixed and its RAM size depends on the number of roles and the attribute size you select in the sdk_config.h file. Apart from that there is nothing much to configure on the softdevice size.

    By number of roles do you mean the NRF_SDH_BLE_PERIPHERAL_LINK_COUNT and NRF_SDH_BLE_CENTRAL_LINK_COUNT? 

    What does attribute size mean? I see NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE. What does that field mean? How low can it go?

    Thank you!

  • Federico said:
    By number of roles do you mean the NRF_SDH_BLE_PERIPHERAL_LINK_COUNT and NRF_SDH_BLE_CENTRAL_LINK_COUNT? 

    The code size of the softdevice is fixed per version and cannot be changed by any configuration changes. The RAM size used by the softdevice can be increased or decreased based on on the number of roles and attribute table size. Yes, NRF_SDH_BLE_PERIPHERAL_LINK_COUNT and NRF_SDH_BLE_CENTRAL_LINK_COUNT are two configs that control how many roles the softdevice should be configured to support at the time of initialization. The softdevice needs more RAM space per extra role/instance it supports.

    Federico said:
    What does attribute size mean? I see NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE. What does that field mean? How low can it go?

    By default, softdevice stores the attributes of the services/characteristics/Descriptors that your application initializes into its own RAM memory. The NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE defines the maximum number of attribute size the whole of your services in your application can store in softdevice RAM. We had to know the max attribute table size that the softdevice reserves in its memory, since this effects where the application RAM starts.

  • Federico said:
    How low can it go?

    If I remember correctly, it was a maximum size of 510.

Related