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

Stack / Heap Sizing Startup File Syntax

I went through and after some work, got FreeRTOS compiling on a STM32 CM0 with 4kb of RAM.

I couldn't get FreeRTOS to fit due to allocation too much heap space in the default config.This is the first time I've ever had working with software with dynamic memory allocation on a micrcontroller.

This is the first time I've ever had working with software with dynamic memory allocation on a micrcontroller.

So after pulling out my hair for a bit, I figured out in Keil where you set the IROM/IRAM and got into all of that and made sure those settings were correct. Eventually I saw that you also can allocate the stack and heap in the system startup file.

(In my case, the FreeRTOS port was allocating too much memory to its heap (the port looked like it was expecting 8kb of RAM, so there was enough memory for the rest of the system.)

The error at first was that there was not enough space for .bss objects, which I had never heard of. But it turns out there are a few other memory areas than the heap and stack where other stuff lives. Lesson learned.

But what is actually going on in the startup file to allocate memory?

I have a stock startup file from ST, with 4kb of RAM.

Am I correct that you just take the hex value, and convert it to decimal for the byte amount?

So in the stock startup file, I have 1024 byte of my RAM for the stack, and 512 bytes of my RAM for heap?

Are these start-up instructions used differently? Are they not an allocation, but a minimum amount for the compiler to allocate?

I understand the issue with the dynamic allocation and over-running the heap.

But say I think I will not dynamically allocate more than 512 bytes of RAM, is there a reason I would not change the stack value to 3500 bytes, and fully allocate the ram at startup?

And what about this those .bss objects?! Is that why you leave some unallocated ram from the stack and heap, for the miscellaneous.

PS: I am not thrilled at the thought of dynamic memory allocation on a microcontroller in a commercial product. Particularly because if the system overflows/locks, that's a warranty issue... I know FreeRTOS can now use static allocation at compile time. Ideally probably get that version running, but baby steps for now.

; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; <h> Stack Configuration
;   <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Stack_Size              EQU     0x400

                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp


; <h> Heap Configuration
;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>

Heap_Size      EQU     0x200

                AREA    HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem        SPACE   Heap_Size
__heap_limit