FreeRTOS - the stack is in words!!!! | Cypress Semiconductor
FreeRTOS - the stack is in words!!!!
No fibbing here... last night I woke up around 4am thinking "they're words"!!!!! As in 32-bit words, not 8-bit bytes. Yesterday I wrote about increasing the FreeRTOS stack size "for the OS to do anything interesting". It turns out that the 1kB stacks I was using were actually 4kB. And the original 16kB allocation of SRAM to FreeRTOS is actually quite generous. Oops.
Once I got to work, I needed to check. Maybe there would be no falling-on-the-sword admission of stupidity after all. I opened the project in ModusToolbox IDE and, with judicious use of 'F3' and the search dialog, found this code in the xTaskCreate() function of task.c:
pxStack = ( StackType_t * ) pvPortMalloc( ( ( ( size_t ) usStackDepth ) * sizeof( StackType_t ) ) );
I knew things were looking bad by this point, but I looked up StackType_t in portmacro.h to reveal the confirmation.
#define portSTACK_TYPE uint32_t typedef portSTACK_TYPE StackType_t;
Yup, they're words. It turns out I code better in my sleep than when I am awake! There is a moral here. You know when you think you know what you are doing, but there's a nagging doubt that you just ignore... DON'T. And especially don't write about it in public. Yesterday I did not really think about this and blithely assumed that our Apps team had under-resourced the RTOS configuration. I'm going to hear ALL about this from those guys...!