Configure a larger heap on the nRF51 devices

I know the nRF51 MCUs are outdated but I am having issues trying to allocate some space on the heap, and it does not appear that its a memory limitation given the size. Here are the results from the Keil compile:

Program Size: Code=28132 RO-data=1916 RW-data=500 ZI-data=6908  

Yet as I step through the code during setup, I am getting calloc returning NULL. The size of the item being calloced is not large. Is there a way to configure more space on the heap? Perhaps one of the 1000's of possible parameters in the sdk.config?

I am using just SoftDevice for bluetooth and flash. I am using the latest possible version of both SoftDevice and the SDK for the nRF51x platform.

  • Hi,

    Please make sure this box is not checked in your target settings:

    Having microlib enabled will cause the HEAP section to be removed.

    Best regards,

    Vidar

  • That did not help but it did require more space. I am also getting a out of memory writing to flash - and its only pairing data that is getting written which is not much.

    I looked at the memory map using NRF Connect Programmer app and it looks like there is LOTs of flash free. About half just using visuals.

    The boot loader is 1984 bytes

    SoftDevice (which appears huge) is 134540 bytes

    the app has two small green bars just above SoftDevice called 'application'

    the first one is 1148 bytes

    the second one is 776 bytes.

    The remaining gray area is also called application and is 262144 bytes. I am a little confused to say the least. I thought gray was free but ....

    I switched to a Blood pressure device which has no issues and the bootloader and SoftDevice are the same. However, the application green bar now lies near the very top of the diagram at 148 bytes. It should be the same for the other device as well, as in both cases only pairing data is written to flash.

    Something is weird. Is there a way to tell how much heap size I have? Is there a way to tell where I can start writing to flash? There is in nrf52 but I dont know about here.

  • And the __HEAP_SIZE symbol is set to a non-zero value as well? You can check the *.map file to find the size of this section:

    brianreinhold said:
    I am also getting a out of memory writing to flash

    Can you clarify what you mean by this? Is it a linker error that indicates that you have run out of memory, or do you get an error you try to load the hex file?

    brianreinhold said:
    Is there a way to tell where I can start writing to flash?

    You can write to any flash page as long as it does not overlap with your FW code/data. If you do not have a bootloader present, you can probably use the pages at the end of flash assuming the application is not too big.

    The flash address at which the application ends can be calculated by adding the 'Total ROM Size' reported by the application build with size of the Softdevice. Or you can use the CODE_END macro from app_util.h available in more recent SDK versions.

  • Gees! I forgot all about using the map.

    I don't fully understand the colors of the memory layout in the nRF Connect Programmer app. Are the green colors the data I write to flash? It seems everything gray (not SoftDevice or the bootloader) is application, but there is no indication of what is free or unused.

    At the moment I am trying to place my data at the end of flash (top of the picture). If they are the green bars, they make sense for the working apps. But the one that is not working has the green bars (two of them not just one) just above SoftDevice.  But my interpretation of the green bars maybe wrong.

    I do use the macros in the nRF52 solutions. I am having no problem there.

  • I usually find it better to inspect the memory manually. The Programmer app is not always able to reliably parse the memory content, particularly if you have a custom data storage area.

    You can read the flash content to a text file with nrfjprog with the command below.

    $ nrfjprog --memrd 0x0 --n 0x40000 > flash.txt

    brianreinhold said:
    I do use the macros in the nRF52 solutions. I am having no problem there.

    Maybe you can import the same macros to your current project?

Related