cancel
Showing results for 
Search instead for 
Did you mean: 

What relationship between Linker setting in CubeMX and System SRAM in MCU and the stack in FreeRTOS

AASD.1
Associate III

  Hi,

 <1> Recently I noticed the important of the Linker setting when I configured USB support(Someone say that need to increase the value in case of going wrong).

LinkerSettings.png

  So I am wondering how large I could set.How does it relate to System SRAM or somthing else?

Ram_EN.png

 

And how can I find it in codes? I took over a project with USB problem that was not created by CubeMX.

 

<2>I am also a FreeRTOS new user.I was told I should set a large stack when create a task in the first time.

xTaskCreate.png

 

CreateStatic.png

 

stack.png

 

But how maximum I could set?  All task stack add up can not be more than what?

 

  Does someone know or think about these questions?

 Thanks for your reply.

1 ACCEPTED SOLUTION

Accepted Solutions

In Keil MDK-ARM :

- in project options, Linker tab, if "Use memory layout from Target Dialog" is checked, then go to Target tab and look at "Read/only Memory areas" and "Read/Write memory areas".

- if "Use memory layout from Target Dialog" is not checked, look for the *.sct scatter file indicated in Linker tab. The file should be under MDK-ARM directory in Cube examples. You have to understand the syntax of this file. See MDK-ARM linker doc.

Also check Stack_Size and Heap_Size in startup_stm32xx.s file provided in the sources of the project. Example:

Stack_Size EQU 0x2000

Heap_Size EQU 0x2000

This is the configuration of stack and heap used by the C library provided by MDK-ARM (for malloc() and others).

 

 

View solution in original post

4 REPLIES 4
TDK
Guru

The board uses RAM for variables, the heap, and the stack. You can divide the available memory however you want among those three.

In general, the size allocated to the stack is a small portion of the overall memory, maybe 4 kB at most, but there is no explicit limit.

The static stack analyzer in STM32CubeIDE (Window -> Show View -> Static Stack Analyzer) can give you an idea of the amount of stack needed for each task. In the Call Graph tab, the Reset_Handler function will give you the max stack size of the main thread. In general, functions shouldn't be using more than maybe a couple hundred bytes of stack, and typically much much less, but again there is no explicit limit here.

 

If you feel a post has answered your question, please click "Accept as Solution".
AASD.1
Associate III

  Got it.I should set Minimum Heap and Stack Size together 4KB at most,create a task with a hundred bytes at first and resize it by static stack analyzer.

But I have a question where I could find the Linker settings in the Keil project? I get a project with USB problem and it was not created by CubeMX.

  Thanks for your reply.

Hello,

You can define the Heap Allocation failure Hook by activating the software flag: configUSE_MALLOC_FAILED_HOOK. This allows you to catch out heap errors through vApplicationMallocFailedHook( void )
Same thing for the Stack, you have to define configCHECK_FOR_STACK_OVERFLOW to catch stack overflows issues with vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName)

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

In Keil MDK-ARM :

- in project options, Linker tab, if "Use memory layout from Target Dialog" is checked, then go to Target tab and look at "Read/only Memory areas" and "Read/Write memory areas".

- if "Use memory layout from Target Dialog" is not checked, look for the *.sct scatter file indicated in Linker tab. The file should be under MDK-ARM directory in Cube examples. You have to understand the syntax of this file. See MDK-ARM linker doc.

Also check Stack_Size and Heap_Size in startup_stm32xx.s file provided in the sources of the project. Example:

Stack_Size EQU 0x2000

Heap_Size EQU 0x2000

This is the configuration of stack and heap used by the C library provided by MDK-ARM (for malloc() and others).