FreeRTOS not running after bootloader jump (SAMC21, app @ 0x8000)

My FreeRTOS code works perfectly when flashed alone (starts from 0x00000000).
When bootloader is flashed first, then application (at 0x00008000), FreeRTOS doesn’t run — it doesn’t enter tasks.

FreeRTOS tasks not running after bootloader jump (SAMC21, app at 0x8000)

Microcontroller: SAMC21N18A
Compiler/IDE: Atmel Studio
FreeRTOS version (10)
Bootloader used (custom)

I’m using a custom bootloader on a SAMC21N18A microcontroller with FreeRTOS. The bootloader starts at 0x00000000 and jumps to the application at 0x00008000. When I flash only the application (starting at 0x00000000), FreeRTOS works fine.

But when I flash the bootloader at 0x00000000 and the application at 0x00008000, FreeRTOS doesn’t run — no tasks are executed, and it seems interrupts aren’t firing

:plus:

SAMC21 is a cortex-M device. Have you correctly updated the VTOR?

This is a good document from ARM describing all the steps needed to write a bootloader - Documentation – Arm Developer.

but our custom bootloader is working for non-RTOS code, but facing issue with RTOS code

Yes but your RTOS code works fine without the bootloader, right?

A very possible reason is that the vector table is not correctly setup because FreeRTOS requires some ISRs to be installed correctly. Did you try my above suggestions?

Yes, my RTOS code works fine (starts from 0x00000000)

Vector table is correctly setup,
I have configured FreeRTOS version 10 in Atmel Start. What other tools do I need to install for FreeRTOS to work properly?

int main(void)
{
atmel_start_init();
Initialization(); // This includes print statements
// Task creation for Task 1 to Task 6
vTaskStartScheduler();
}
In my FreeRTOS code, I added print statements inside the Initialization() function (which runs outside the RTOS). I can see those print statements through Data Visualizer, so I know it’s being called.

However, the tasks are not being created — they are not running.

Can you share the code in your bootloader where you do that?

Sorry, I couldn’t share the code on a public forum

In that case, have you done all the steps in the documents I liked above? Are you setting VTOR by doing something like the following:

SCB->VTOR = ( uint32_t )Address ;

If the answer to both the questions is yes, can you break the code in debugger and see what it is doing when it appears stuck?

We do exactly this on a SAMC21. You can find our code at Duet3Bootloader/src/Bootloader.cpp at dev · Duet3D/Duet3Bootloader · GitHub. See in particular the StartFirmware() function at the end.

2 Likes

Thank you for sharing @dc42!