I too had this problem in my program. I added vApplicationIdleHook in my Stm32 NucleoF446RE with Atollic TrueSTUDIO, only to test it, with no particular need. I remember that vApplicationIdleHook was called and could print something, but going ahead with my app, now vApplicationIdleHook is no more called and behaves badly. I don't write here much code as things would be too long, but hints easy to understand also for an hobbyist like me.
Present working arrangement:
1) in FreeRTOSConfig.h I add two rows
#define configIDLE_SHOULD_YIELD 0
#define configUSE_IDLE_HOOK 1
2) in main.c I add only my definition of void vApplicationIdleHook(void): no need to declare it forward. I put inside this function a point of test: not at all osDelay or worse an infinite cycle.
3) in main.c I create a task. Its priority doesn't matter.
Partial code:
int uuu = 0;
int main(void)
{
//create StartTaskDef with osPriorityLow
//boilerplate code...
}
void vApplicationIdleHook(void)
{
uuu++; // CCC
}
void StartTaskDef(void *argument)
{
const TickType_t xDelayms = pdMS_TO_TICKS(2); // cimsis_os2.h version
while (1) // AAA
{
osDelay(xDelayms); // BBB cimsis_os2.h version
}
}
Test 1.
In the code above: comment out the row AAA; put a breakpoint at the rows BBB and
CCC; compile and debug. Debug in order will stop at: BBB (higher priority anyway); CCC; CCC; CCC; ... BBB will be hit only once because its task executes once and then exits. For each CCC hit, uuu increments by 1.
Test 2.
Leave the code above as it is with row AAA active; put a breakpoint at the rows BBB and CCC; compile and debug. Debug in order will stop at: BBB (higher priority anyway); CCC; CCC; CCC; ... For each CCC hit, uuu increments by 1. That seems strange as now row AAA is an infinite cycle and debug doesn't hit BBB anymore. So remove the breakpoint at row CCC and resume debug. Now debug will stop at: BBB;
BBB; BBB; ... Examination of uuu at each stop of debug shows now that uuu has increased not by a unit, but by the thousands. That means that while row BBB was executing (StartTaskDef was sleeping), vApplicationIdleHook could act thousands of times.
Considerations.
Debugging vApplicationIdleHook is harder than other objects of this operative system, but can be interpreted, should be trusted and perhaps improved. There is
some confusion between online description of osDelay by cimsis_os2.h that says its argument be ticks and the description given by
FreeRTOS: osDelay vs HAL_delay
which says argument of osDelay is milliseconds.
Here I've used the first version (cimsis_os2.h version), but I prefere the second one that has solved another similar problem.