Skip to main content
Davy Jones
Associate II
February 15, 2018
Solved

How determine maximum CSTACK and HEAP which a microcontroller support ?

  • February 15, 2018
  • 3 replies
  • 2248 views
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
    This topic has been closed for replies.
    Best answer by AvaTar
    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.

    3 replies

    AvaTar
    AvaTarBest answer
    Senior III
    February 15, 2018
    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.

    Andrew Neil
    Super User
    February 15, 2018
    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!

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Davy Jones
    Associate II
    February 16, 2018
    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.