I have a product with the Atmel ARM7 AT9SAM7S256 running using freeRTOS 5.1.2 originally using IAR EWARM 4.42, and I am trying to move it to v5.30. The product sort of runs (!) but behaves erratically and some sprintf typ eoperations don’t work as expected, particularly printing the (dramatically) wrong values.
I have started a discussion with IAR, who say the the biggest cause of this sort of problem is stack missalignment. v5 comilers need/expect 8byte allignment on the stack when entering/leaving C functions.
It seems that the freeRTOS5 attempts to match this , but I have a problem in my understanding. When creating a new task, tasks.c gets an aligned stack which I have ensured is a multiple of 8bytes in size by making sure usStackDepth is even. Then the top of stack pointer is guaranteed to be 4 byte aligned as
pxTopOfStack = pxNewTCB->pxStack + ( usStackDepth - 1 );
Then pxPortInitialiseStack adds 17 4byte registers to the stack. It seems to me that this ought to be 18 registers, and the portRESTORE_CONTEXT and portSAVE_CONTEXT macros need adjusting similarly, or am I misunderstanding it all?
Any helpful hints comments and thoughts gratefully received.