2022-11-01 01:32 AM
Hello,
I am working on a project with an STM32H753 Microcontroller and I have an external SDRAM 32 mbyte connected to the MCU via FMC. I want to use the SDRAM as default heap space. This because I want cJSON library use this memory space for dynamic allocation. The problem is that I don't know if this is possible and also I don't know how to Initialize pins and clocks and how to activate the FMC interphase before the project entrers the main file. Any suggestions?
Thanks In advance,
2022-11-01 02:46 AM
Not sure what runtime you're using, this is for STM32CubeIDE/gcc/newlib-nano and answers only the software part:
The heap is not used before calling the first malloc or other heap function. So you don't have to setup a heap early before main.
malloc and friends rely on the void *_sbrk(ptrdiff_t incr) function. This function is called when more heap memory is needed and the returned pointer is used. In contrast to malloc, there is no "free" like counterpart to _sbrk._sbrk is implemented in sysmem.c and you are totally free to change the implementation to return FMC RAM as long as there is more of it available.
hth
KnarfB
2022-11-01 06:51 AM
The prescribed purpose of SystemInit() is to bring up external memory interfaces, etc, before the C Runtime goes to work and fills or moves the statics into RAM.
For GNU/GCC look at _sbrk() and disassociate the heap and stack so the heap can use SDRAM, and the stack the fastest TCM RAM.
2022-12-02 01:46 AM
Hello and thank you for your answers,
I am looking that fuction _sbrk to change it but I can find where is placed in project. The IDE that I use for my project is Keil Uvision 5.
2022-12-02 10:24 AM
Check linker file details of your compiler, and crawl back to higher level to reconfigure it if needed.