Determining RAM available at compile or run time
Posted: Fri May 31, 2019 11:59 am
I want to be able to allocate a large static circular buffer, where I will use as much RAM as I can up to a certain amount, e.g. I might want 64KB, but if there is not sufficient RAM I'd allocate maybe 16KB. The buffer is accessed in 2KB chunks, using an array of pointers. I want to make the code portable between STM32F4, F7 and H7 ranges, but I can't see an obvious way to determine RAM size at compile time. At the moment I use a different makefile for the boards I'm using, so I set the buffer size there.
The RAM is described in the relevant processor files, but with start address, and then the size in a comment, but the definitions are not consistent (e.g. SRAM1_BASE in stm32f767xx.h and D1_AXISRAM_BASE in stm32h743xx.h, and the definitions do not give an end address or size. The information is available at link time (coded into the linker script file).
It may make more sense to determine the free space at run time (chCoreGetStatusX()), and allocate at initialisation time (chCoreAlloc()), but that adds a bit more complexity with managing pointers (as I would need a dynamic list rather than static array).
Any suggestions welcome. Is it better to allocate dynamically or statically?
Mike
The RAM is described in the relevant processor files, but with start address, and then the size in a comment, but the definitions are not consistent (e.g. SRAM1_BASE in stm32f767xx.h and D1_AXISRAM_BASE in stm32h743xx.h, and the definitions do not give an end address or size. The information is available at link time (coded into the linker script file).
It may make more sense to determine the free space at run time (chCoreGetStatusX()), and allocate at initialisation time (chCoreAlloc()), but that adds a bit more complexity with managing pointers (as I would need a dynamic list rather than static array).
Any suggestions welcome. Is it better to allocate dynamically or statically?
Mike