This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

FreeRTOS and app_scheduler combined

Hi all,

For a project I need to use a private library which uses the app_scheduler to queue events triggered from a second MCU. I am using FreeRTOS on the nRF and I am unsure how to make the app_scheduler work together with FreeRTOS. The supplier of the library compiled it with the FreeRTOS version of app_timer. So it should be compatible.

After reading the app_scheduler documentation I figured I need to initialise it first. I do this before calling the vTaskStartScheduler() function. But I read I also need to call app_sched_execute() in my main loop to check for items in the event queue and process them. 

Now vTaskStartScheduler() does not return, so I don't have such a literal main loop. I am wondering how to make sure tasks in the app_scheduler queue still get executed.

What is the best way to achieve this? I'm currently thinking about creating a task/thread which wil just call app_sched_execute() whenever it gets CPU time but it seems a bit ugly. Is there a cleaner way to use both FreeRTOS and the app_scheduler at the same time?

P.S I also found a post asking the same question but it was never answered: devzone.nordicsemi.com/.../freertos-and-app_scheduler

  • Jur said:
    This works great but it is not the cleanest solution. So do I understand correctly that I can use tickless idle and idle hook together when not making the chip sleep in the idle hook?

     Firstly sorry for the late reply. I was sick and just returned to work today.

    Yes your understanding is correct. The idea of enabling tickless idle is to give the RTOS control on sleep states of the chip. So when enabling tickless idle, the sleep state should only be at one place for the RTOS to properly have control on the ticks and later adjusting the missing ticks.

    Using idle hook and tickless idle is completely ok as long as you do not use any sleep states in the idle hook.

     

    Jur said:
    So do I understand correctly that I can use tickless idle and idle hook together when not making the chip sleep in the idle hook? In that case I can use tickless idle for sleeping and the idle hook for just calling app_sched_execute().

     correct.

  • No worries, I hope you're okay! Thanks a lot for helping me, appreciated! It is all clear now :)

  • I would just like to add something for developers that may come across this thread who need to do the same thing:

    When using the idle hook to call app_sched_execute() whatever is queued for the Scheduler will (obviously) be executed within the idle task. I got stack overflows and undefined behavior as a result of the stack size of the idle task being too small for the scheduled events. When you run into the same problem you can increase configMINIMAL_STACK_SIZE within FreeRTOSConfig.h. This will also increase the stack size of the idle task Slight smile

  • Hi  , ,

    Could you share an example using app_scheduler.h library and freeRTOS please .
    
    I have a problem and I'm stuck on this part.

    Thank you for your help .

Related