FreeRTOS stack size and printing

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FreeRTOS stack size and printing

2,217 Views
rudasi
Contributor I

I have a motor control project using freertos to do some debug printing. I would print some float variables in a debug task. I created a new project with the same code just in a different location for the same board and my printf in my freertos debug task would print a few characters then stop. I have looked over both project compile and linker settings and they are the same. After some debugging I found that increasing the stack size of my debug task from 100 to 200 fixed the print issue. 

 

I am not sure why the original project with a 100 stack size prints fine but the new one which in theory is exactly the same requires 200. I have float printing enabled. Any suggestions?

Labels (1)
0 Kudos
2 Replies

1,088 Views
BlackNight
NXP Employee
NXP Employee

I would have a look how much stack you have allocated, e.g. with the Eclipse FreeRTOS plugin (see FreeRTOS Kernel Awareness for Eclipse from NXP | MCU on Eclipse ). Depending on which library (newlib? newlib-nano?) the standard library and printf() requires dynamic memory in the non-FreeRTOS heap, and depending on the order of tasks and printf() usage the stack needed might be different. Additionally, depending on what you are using with printf(), it might not end up in a printf() call, see GNU gcc printf() and BuiltIn Optimizations | MCU on Eclipse .

Last but not least: using printf() usually is not a good idea anyway, see Why I don’t like printf() | MCU on Eclipse .

I hope this helps,

Erich

0 Kudos

1,088 Views
FreeRTOS_org
Contributor IV

Depending on how the memory is being allocated, or the order in which the allocations are done, there is a chance you just got lucky and the issue existed in both cases, but only caused a problem in one.

Do you have stack overflow checking turned on?

0 Kudos