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.

Parents
  • 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?

  • As it turns out I am not using CODE_END. I am doing the following in the nRF52 SDK

        uint32_t pg_size = NRF_FICR->CODEPAGESIZE;
        uint32_t pg_num  = NRF_FICR->CODESIZE - (NRF_FICR->CODESIZE * pg_size - 0xE0000) / pg_size;
        
        // Okay, what are we doing here. On the dongle, the bootloader occupies flash above 0xE0000. So I have to find how big flash is,
        // subtract 0xE0000 from it, find the number of pages there, and then subtract that number of pages from the total. THAT gives the
        // page where the boot record starts (0xE0000). Now I have to drop a few pages to where I can start. I drop two pages here
        // I still don't know how to dynamically find the page at the top of MY app which gives the
        // area of free flash between my app and the bootloader at the top. The DK, by the way, has no bootloader so I don't need all this.
    
        NRF_LOG_INFO("Total pages is %u, pg_num is %u pg_size is %u", NRF_FICR->CODESIZE, pg_num, NRF_FICR->CODEPAGESIZE);
        pg_num = pg_num - 2;

    Still not good as there is probably a lot more flash available to me.

    For the CODE_END I see lots of options but using segger emb stud I see

    #elif defined(__SES_ARM)
    extern uint32_t * _vectors;
    extern uint32_t __FLASH_segment_used_end__;
    #define CODE_START ((uint32_t)&_vectors)
    #define CODE_END   ((uint32_t)&__FLASH_segment_used_end__)
    #define CODE_SIZE  (CODE_END - CODE_START)

    Should that be the location of where I start writing to flash? Would that always be a page boundary or do I need to calculate that?

    How would the macro differ if I were using nRF51 (where I am having the problem)?

    I increased the HEAP size and all my problems went away.

  • I did increase the HEAP size but I did it directly in the assembly code. I also needed to increase the STACK size for another version of the model but again, I did it directly in the code. When I looked at the preprocessor defines for my settings, their was neither a HEAP or STACK size option present. If I use the preprocessor above will that override the values in code?

    What is the preprocessor for STACK size?

Reply
  • I did increase the HEAP size but I did it directly in the assembly code. I also needed to increase the STACK size for another version of the model but again, I did it directly in the code. When I looked at the preprocessor defines for my settings, their was neither a HEAP or STACK size option present. If I use the preprocessor above will that override the values in code?

    What is the preprocessor for STACK size?

Children
No Data
Related