Tasks created and are only executed once, seems like scheduler is configured incorrectly

I’m using an stm32 nucleo board, and generating the whole HAL layer from STM32 CubeMX.
I’ve added FreeRTOS manually to my project.

I’m having a bit of a problem, I’ve created two very simple tasks, task_one and task_two, but they seem to be executed only once.

I have some debug messages and it seems like the scheduler is stuck in
xPortSysTickHandler() or in xPortPendSVHandler(), since the last log message is inside xPortPendSVHandler().

I’ve looked at an stm32 with a cortex m4 demo and took the FreeRTOSConfig.h and modified it a bit.
Any idea why the scheduler might stop inside xPortPendSVHandler() ?

Does it work if you take the log messages out of the interrupt handlers. Insite an interrupt, a log message is likely to:

  1. Take way too long to execute, interrupt must be fast.
  2. Use too much stack.
  3. Likely cause thread safety/reentrancy issues.
  4. Mask the issue you are trying to debug by causing many other issues.

What modifications to the FreeRTOSConfig.h did you make?

Is the tick interrupt executing? If not, a task may only run until it blocks with a timeout, then never run again as without the tick interrupt it doesn’t see its block time ever reached. An easy way to know is to pause on the debugger when your issue occurs, then view the xTickCount variable in the debugger.

Another quick thing you can do is to add FreeRTOS using CubeMX only so that you have a working FreeRTOSConfig.h and everything else. You can then remove the CubeMX generated FreeRTOS copy and add the latest FreeRTOS version manually in case the auto-generated version is not latest. Please also ensure to move HAL Tick to some other timer - you’ll get a warning from CubeMX if you do not do so once you add FreeRTOS using CubeMX.

Hi, sorry for late response!

The problem was actually solved a few minutes after I posted my question.

The problem was indeed debug messages, once I removed all of them except one debug print in each task, it all worked!

First problem was that I used timer6 for HAL timebase, but missed adding the autogenerated timer file in CMake. So that caused the system to hang somewhere before taskCreate and startScheduler.
So when I tried to debug that issue, I added a lot of debug print, then realized that the timer file was missing in my build, added it and still didn’t work but the problem was elsewhere now. Sooo, then I removed all debug prints, and voila!

Thanks for your responses, it was all good suggestions!

Thank you for reporting back.