Idle hook from freeRtos


Hi all,

I need to have an idle hook to do some background jobs.
So I implemented the function ‘void vApplicationIdleHook( void )’ and now I want to set the configuration param ‘configUSE_IDLE_HOOK’ to 1.
I tryed the following two possibilities in the mos.yaml file without success:

configUSE_IDLE_HOOK: 1

configUSE_IDLE_HOOK: 1

What is the correct way?

Thanks for your help


Per the documentation,

  configUSE_IDLE_HOOK: 1

Should translate to:

  - "-DconfigUSE_IDLE_HOOK=1"
  - "-DconfigUSE_IDLE_HOOK=1"

Perhaps the indentation is required? What failure or error do you see?


I ran across something similar to this while looking for something else. Make sure the indent is there. Also, you might try:

   APP_CFLAGS: "-Dno-error=configUSE_IDLE_HOOK=1"


   APP_CXXFLAGS: "-Dno-error=configUSE_IDLE_HOOK=1"

Depending of course if its C or C++.


Hi Jim,
Thanks for your inputs! Unfortunately, I was not successul by applying them.
I tried the following four options:

configUSE_IDLE_HOOK: 1

configUSE_IDLE_HOOK: 1


  • “-DconfigUSE_IDLE_HOOK=1”

APP_CFLAGS: “-Dno-error=configUSE_IDLE_HOOK=1”

The first tree were compilable but unsuccessful, the fourth was not compilable.

Then, I tried all of the four with just ‘USE_IDLE_HOOK’ (without ‘config’), with the same result.

Could the problem be in the definition of the hook itself (void vApplicationIdleHook(void)) ?
I found it in the freertos documentation .

Thanks a lot for more information!



Oh, I was under the impression that you wrote code checking the macro. When I get a chance later I’ll see how the FreeRTOS idle hook is supposed to work. Remember that Mongoose uses a modified version of FreeRTOS, but I can’t say I know exactly what was changed.

I suggest that you test if the macro is getting defined by writing a little code in the init function, at least that way you’ll know if you’re defining it correctly.


Hi Jim,
I checked the macro itself and its ok. But the hook is still never called … :-/
Thanks for any help!


I’m updating my last post because it won’t work. The info here is tested on an ESP32.

The Espressif API modified the FreeRTOS hooks to be compatible with multicore CPUs, allowing you to specify a separate idle task for each core. Under this system, you have to register your idle task function. The original idle hook has been modified to call the hooks you register, and you can not write:

void vApplicationIdleHook(void)

If you do, when you compile you’ll get an error indication that this function has been redefined by your code. This example is written for the idle hook, but the tick hook has similar changes.

All this is (mostly) explained here:

I tested this, and here is what you need to do to make this work:

In your mos.yml file:


In your code, you’ll need these header files:

#include "FreeRTOS.h"
#include "esp_freertos_hooks.h"

Then you’ll need to write your idle hook callback:

static long int ctr;

bool myTestIdleHook(void)
  return true;

The callback should return true if it should be called by the idle hook once per interrupt (or FreeRTOS tick), and return false if it should be called repeatedly as fast as possible by the idle hook.

Finally, register the idle task callback. There are a bunch of functions available for this, see the link above for complete details. This function registers the callback for the core on which it is called:

  if(esp_register_freertos_idle_hook(myTestIdleHook) == ESP_OK)
    LOG(LL_INFO, ("Idle hook successfully registered."));
    LOG(LL_INFO, ("Idle hook registration failed."));

Check the link above for return information. It took a bit of research to figure this out, so I hope its useful to someone.



Hi Jim,
Thanks for this detailed explanation. I will check it out next week!
Kind regards


Hello Jim,

I checked this matter. It worked correctly for the ESP32. Thanks for your inputs.
For the ESP8266 I did not succeed, unfortunately. Is there a solution, too?

Kind regards


Hi Rolf… Sorry, I have no idea, I don’t have an ESP8266.