This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to configure minimum heap size on ARM

My project uses ARM Cortex M0+, with C++ and ArmClang 6.10.1. My ultimate goal is to set "Heap_Size EQU 0x0" in the startup.s file. My code builds fine, but when I run it in Keil simulator it crashes. Stepping through assembly instructions, it appears that the "_init_alloc" function exits with SIGRTMEM signal after comparing the 0x0 heap size to a "#0x10" immediate. To confirm, I set "Heap_Size EQU 0x10" and my program builds/runs as expected.

I've ensured that malloc+new are not used in my code (UNUSED according to the generated static call graph); I left free+delete alone since they are used in more places, but I don't think this matters since I'm not using malloc+new. After digging through the ARM info center, I used "IMPORT __ARM_use_no_argv" and an overridden "__aeabi_atexit" function to achieve this.

As a possibly related side-note, I can't use "IMPORT __use_no_heap_region" because the linker still finds references to malloc+free, resulting in "Error: L6915E: Library reports error: __use_no_heap was requested, but malloc was referenced". I'm not sure why entirely, but maybe because the linker can't remove them explicitly from the library (they still appear in the map file).

Conclusion:
Is there some typical minimum heap size, and/or how is the aforementioned "#0x10" immediate determined? Is it specific to C++ or ArmClang? In another project that uses ArmCC with RTX and C only, the "Heap_Size EQU 0x0" works as expected. Thanks for any help!

Parents
  • The first time I saw an issue with having a heap size of 0 was when I started using C++. I got to the same 16 byte minimum heap size you have found (this was more than 10 year ago). I just went with that. Eventually I found that overriding the __aeabi_atexit() allowed me to set the heap size to 0 again. I can also set #pragma import(__use_no_heap) and #pragma. The #pragma import (__use_no_heap) is very helpful as if you add any library function that uses malloc, the linker will give you an error (rather than having your code fail at run time because malloc failed and you scratch your head because you think you are not ever calling malloc in your code)

    I also found this reference on the forum -

    www.keil.com/.../

Reply
  • The first time I saw an issue with having a heap size of 0 was when I started using C++. I got to the same 16 byte minimum heap size you have found (this was more than 10 year ago). I just went with that. Eventually I found that overriding the __aeabi_atexit() allowed me to set the heap size to 0 again. I can also set #pragma import(__use_no_heap) and #pragma. The #pragma import (__use_no_heap) is very helpful as if you add any library function that uses malloc, the linker will give you an error (rather than having your code fail at run time because malloc failed and you scratch your head because you think you are not ever calling malloc in your code)

    I also found this reference on the forum -

    www.keil.com/.../

Children
No data