FreeRTOS on Xilinx Microblaze: no tasks start, loop over main

I am trying to use FreeRTOS on a Xilinx FPGA with a Microblaze soft core.

I instantiated a very basic hardware (Microblaze, 128K memory for Data and 128K Memory for Instructions, Timer, Interrupt Controller) and I created a FreeRTOS project with the wizard inside Vitis IDE.

The project it creates is a simple hello world one (two tasks, one receiver and one transmitter and the receiver prints on the UART) the problem is that no tasks starts but only the main is executed multiple times! Even if I create a simple project with a single task, after the scheduler is started it starts to loop on the main over and over.

By debugging strange things inside the OS I noticed that at a certain point after the scheduler starts, it try to run the task I think and loads in the R14 a value that is used to branch on it. The problem is that the value is outside the range covered by the program (i.e. there are no useful address there, the ram is initialized to 0x0 in fact it executes instructions like add R0, R0, R0) and I think that the program counter continue to be incremented till it reaches the end of the ram and starts over again from 0x0 that is the boot address thus the main starts again.

I don’t know where the problem can be actually. Can you help me? Thanks!

Did you create the FreeRTOS projects yourself, or was it created by Vitis?

Try setting portPRE_LOAD_STACK_FOR_DEBUGGING to 1, so the registers of a newly created task are set to known values. Then, put a break point on vPortStartFirstTask, which pops the register values off the task’s stack into the CPU registers. Do the registers have their expected values, other than R14 which you already noted didn’t?

I managed to solve it, fortunately. I had to enable a flag inside the microblaze block configuration in order to enable the CLZ (count leading zeros) instruction, used by the optimized version of a macro used by the vTaskSwitchContext function in tasks.c.