philpem wrote on Wednesday, September 17, 2014:
I’ve spent the past two days chasing down an issue with FreeRTOS failing to run correctly when I build my application in “release” mode. Aside from turning off debug messages, this also enables some optimisations in the IAR C compiler.
Long story short, if I build port.c, queue.c or tasks.c with IAR 7.20.5 and set optimisation any higher than Low, the code hard-faults shortly after the first task (a temporary, ephemeral Initialisation task named “INIT”) starts up.
On further investigation, enabling Medium optimisation with Common Subexpression Elimination disabled allows a working version of port.c to be built. Sadly the same does not apply to tasks.c and queue.c; if either is built with optimisation set higher than Low, the hardfaults return.
The optimisation level of my own code is irrelevant to the problem. I can build my application with optimisation on or off and the hardfaults remain.
I’ve also found that disabling my idle hook (a low-power hook similar to the one in the examples) will also resolve the problem, irrespective of the optimisation level:
void vApplicationIdleHook( void )
{
PWR_EnterSleepMode(PWR_Regulator_ON, PWR_SLEEPEntry_WFI);
}
What is going on here? Is this a compiler bug, a bug in my code or a bug in FreeRTOS?
The target is an ST STM32L151RC (ARM Cortex M3), FreeRTOS 8.1.2, compiler is IAR 7.20.5.
Thanks,
Phil.