This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Free memory on nRF52840

I'm having a problem with using all the memory in the nRF52 Thead SDK 0.10.0. Namely, even if I run one of the smallest examples (e.g. aes one from crypto examples) the flash size usage is very low (about 0x9000), BSS ram is also low (according to the linker map output about 2 kilobytes).

But when I want to allocate some static memory (e.g. static uint8_t buf[ 1024 * 100 ], the code links properly, but after execution I see no logs. I'm not sure if the cpu is dead, or just logging stops to work. If I use smaller array (e.g. 50k), it works.

If I understand correctly, BSS are located at the beginning of ram (0x20000000), stack is going down from RAM end (0x20040000), and anything in between should be unused. So, I should be able to extend BSS by 100kb, provided that I don't use stack so much to override that. My stack is virtually empty - just main() and logging.

Interestingly the FreeRTOS examples seem to be tuned to the stable value. Like, FreeRTOS has its own heap in bss section, and it is set to 14kb in the SDK. Setting it to larger value like, 18kb, crashes CPU - even if there should be ~190kb of free memory (running FreeRTOS+OpenThread).

Any ideas why that happens?

  • So, it seems to be related to the _SEGGER_RTT location within BSS. As long as the first 16 bytes of that structure (i.e. the ID field containing the identification marker) is within first 64 MB of ram, RTT logging do work. The moment I move it past 0x2000FFF0, I dont see logs anymore. I'm running the JLink via JLinkExe -if swd -speed 4000 -device NRF52832_XXAA -autoconnect 1. And I guess that either JLinkExe thinks that the target is having only 64MB RAM, or the search address region is limited to that area. I think the latter - when the rest of the structure reaches past first 64MB, RTT still work. Any idea how to reconfigure JLinkExe to look for its marker in a bigger region?

  • Hello Nopik,

    Thanks for using nRF5 SDK for Thread!

    The command that you have executed: JLinkExe -if swd -speed 4000 -device NRF52832_XXAA -autoconnect 1 uses config of NRF52832 which has 64kB of RAM.

    Because of that, JLink software try to find _SEGGER_RTT in flash range of this device (0-64kB). Since NRF52840 device has more RAM, depending of where _SEGGER_RTT is placed in memory layout, you may be not able to see RTT logs.

    Solution: Update JLink software to the newest version and use NRF52840_XXAA device, which effectively increase the memory range within which Jlink looks for _SEGGER_RTT structure.

  • So, if I edit the components/toolchain/gcc/nrf5x_common.ld file in the Thread SDK and in .bss section I swap 2 lines *(COMMON) and *(.bss*) with each other, effectively putting _SEGGER_RTT into beginning of RAM (in my case 0x20000074), then I can allocate much more memory (also allocate much bigger stack in FreeRTOS), and the RTT logging still works.

  • Thanks for the answer! Indeed, using the correct device type solves the problem, too. I used ..32 because it was always a default for JLink and completely forgot about it.

Related