Stacks and heaps

Discussions and support about ChibiOS/RT, the free embedded RTOS.
Post Reply
Jeroen3
Posts: 35
Joined: Wed Apr 02, 2014 10:14 am

Stacks and heaps

Post by Jeroen3 »

Hi,

In the RVCT cstartup.s file the stacks and heap are created. I'm usually not paying much attention to startup files, but while the application grows I started to look deeper to get better understanding of what is happening to not get any surprises in the future.
The stacks and heaps should be mapped like this using my custom scattering file: (yes, its an STM32F407)
0 Statics
1 MSTACK
2 HEAP
3 CSTACK
All 0x1000 size.

Code: Select all

; RW data SRAM1 - 64 kB
RW_IRAM1 0x20000000 0x1C000 { 
    .ANY (+RW +ZI)
}
; RW data SRAM2 - S-bus only
RW_IRAM2 0x2001C000 0x4000 {
    .ANY (+RW +ZI)
}
; Core Coupled Memory - D-bus only
RW_IRAMCCM 0x10000000 EMPTY 0x10000 {    
   
}

They are mapped to ram like this:

Code: Select all

...statics...
0x2000cf30   0x00001000   Zero   RW         2124    CSTACK              cstartup.o
0x2000df30   0x00001000   Zero   RW         2125    HEAP                cstartup.o
0x2000ef30   0x00001000   Zero   RW         2123    MSTACK              cstartup.o
__heap_base__=Image$$RW_IRAM1$$ZI$$Limit
...remainder free mem sram1 used by memcore...
__heap_end__=Image$$RW_IRAM2$$Base

All I'm asking is an explanation how this stack/heap memory management is supposed to work with Chibios 2.6.5, since this is unclear to me.
Now it looks like I'm wasting MSTACK and HEAP since when I browse there in memoryview only 0's appear.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Stacks and heaps

Post by Giovanni »

MSTACK is the exception stack, where interrupts are served. CSTACK is the stack used by the main() function/thread. The heap is the reserved memory for the C-Runtime heap.

You can resize them depending on your needs.

Giovanni
Jeroen3
Posts: 35
Joined: Wed Apr 02, 2014 10:14 am

Re: Stacks and heaps

Post by Jeroen3 »

So ChibiOS is only depending on the MSTACK for it's systick and hal interrupts, and a bit of CSTACK to run main in?
Since all threads have static linked working area's, the CSTACK is different for each thread.

It makes a bit more sense now, thanks.
Post Reply