cancel
Showing results for 
Search instead for 
Did you mean: 

How determine maximum CSTACK and HEAP which a microcontroller support ?

Davy Jones
Associate II
Posted on February 15, 2018 at 06:41

The microcontroller we are working on is STM32F303CC.  Lets say you have large project with multiple threads and peripherals attached to the system ? How can we determine the maximum CSTACK and HEAP value for microcontroller , So we can achieve system stability and avoid run time crashes and system instability.  

PS: I am new Embedded world, I am Sorry if this question has been asked before. Love the ST ecosystem. CubeMX makes life easier for beginners.   0690X00000609RRQAY.png

#stack-overflow #cstack #address #heap #out-of-range
1 ACCEPTED SOLUTION

Accepted Solutions
AvaTar
Lead
Posted on February 15, 2018 at 07:52

Some toolchains do a static analysis to guess the stack usage, but are far from perfect.

So it finally amounts to Trial-And-Error, and experience.

Heap is required if you use malloc() and the like, i.e. allocate memory dynamically.

A great number of MCU projects has a heap size of zero.

Both values can be safely be oversized, only you waste RAM then.

Lets say you have large project with multiple threads...

Threads imply an OS (probably RTOS), which usually assign a separate stack to each task.

These stacks are separate from the core stack.

View solution in original post

3 REPLIES 3
AvaTar
Lead
Posted on February 15, 2018 at 07:52

Some toolchains do a static analysis to guess the stack usage, but are far from perfect.

So it finally amounts to Trial-And-Error, and experience.

Heap is required if you use malloc() and the like, i.e. allocate memory dynamically.

A great number of MCU projects has a heap size of zero.

Both values can be safely be oversized, only you waste RAM then.

Lets say you have large project with multiple threads...

Threads imply an OS (probably RTOS), which usually assign a separate stack to each task.

These stacks are separate from the core stack.

Posted on February 15, 2018 at 15:56

How can we determine the maximum CSTACK and HEAP value for microcontroller

Easy: they must be less that the total availa RAM of that microcontroller!

Seriously, this has nothing specifically to do with the microcontroller - it's about managing your software.

As in any software development, you define your software's resource usage!

Posted on February 16, 2018 at 10:10

I knew I would be roasted for asking newbie/noobie/Inexperience question.

He who asks a 

question

 is a 

fool

 for five minutes; he who does not 

ask

 a 

question remains

 a 

fool

 forever.