RAM optimization for nRF52820 with nRF Connect SDK 2.3.0

Dear Support Team,

I would like to learn about RAM optimization options when using the nRF52820 (32 Kb RAM) with the Connect SDK 2.3.0.

After enabling Bluetooth, SPI and adding an EEPROM driver I realized that the RAM is basically already full. (98.77%). The user code seems to only occupy < 1Kb.

This how the memory report looks like:

This is the proj.conf:

CONFIG_SPI=y

CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y

CONFIG_BT_DEVICE_NAME="Test"
CONFIG_BT_CTLR_TX_PWR_PLUS_8=y
CONFIG_BT_GATT_CLIENT=y

CONFIG_BT_USER_DATA_LEN_UPDATE=y
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
CONFIG_BT_BUF_ACL_RX_SIZE=251
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_L2CAP_TX_MTU=247

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512
CONFIG_MAIN_STACK_SIZE=4096

#CONFIG_LOG=n
#CONFIG_SERIAL=n

Is there any way to reduce the RAM usage via compiler/ Kconfig settings? Or do you have any other suggestions?

Thank you very much in advance and all the best,

Viktor

  • Hi,

    There is not a singe configuration to tweak, but many things that affect the memory usage. For instance, I see you have support for long packets with this part of your config:

    CONFIG_BT_USER_DATA_LEN_UPDATE=y
    CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
    CONFIG_BT_BUF_ACL_RX_SIZE=251
    CONFIG_BT_BUF_ACL_TX_SIZE=251
    CONFIG_BT_L2CAP_TX_MTU=247

    It might be that you need it, but this will increase the RAM usage as buffers needs to be scaled for the longest possible packets. As, your CONFIG_MAIN_STACK_SIZE is large. Does it have to be this large? You could also consider setting some other configs to low numbers, like CONFIG_BT_L2CAP_TX_BUF_COUNT (you can see some other potentially relevant configs in nrf/samples/bluetooth/throughput/prj.conf, though here the buffers are set large, and you want them small).

    Lastly, if your device is RAM constrained there are other nRF52 series devices with more RAM (see comparison here).

  • Dear Einar!

    Thank you for the quick response! 

    Regarding the current config, The CONFIG_MAIN_STACK_SIZE is set according to the DevAcademy - Bluetooth Low Energy Fundamentals course. I can try to lower it to half the size and see how it works.

    I need the large buffer size as my use-case will involve sending quite big data packages occasionally (relative to BLE). I'll check the other suggested parameters as well.

    I can't consider devices with more RAM due to power considerations as the others have significantly higher Sleep mode currents.

    It is not possible to configure the compiler to optimize for size?

    All the best,

    Viktor

  • Hi Viktor,

    There is a Kconfig for optimizing for size (CONFIG_SIZE_OPTIMIZATIONS), but that is also the default, so unless you have changes the optimization before it should not matter. The only other suggestions I have is to try to remove any features you don't need, and try to find buffers and stacks that you can reduce in size. Depending on the application it could be that the stacks of some threads can be reduced, so you could look into CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE, CONFIG_BT_HCI_TX_STACK_SIZE, CONFIG_BT_RX_STACK_SIZE and CONFIG_ISR_STACK_SIZE.

    Einar

  • Hi Einar!

    Thank you very much, It seems that I can save some RAM by reducing the stack sizes!

    All the best,

    Viktor

Related