FreeRTOS in Bootloader

joehinkle wrote on Friday, September 16, 2016:

Several of my cpu’s peripherals (SPI, I2C, ENET) utilize FreeRTOS tasks so When I designed my Bootloader I need FreeRTOS running to utilize those components.

When the time comes to jump from the Bootloader (FreeRTOS tasks running) into the Main Application (which also uses FreeRTOS) – What do I need to do from the FreeRTOS perspective to perform the leap?

  1. Disable all HW peripheral interrupts that were enabled in the Bootloader.

  2. Disable HW interrupts (I’m using an ARM so (“cpsid i”));

  3. Best way to disable Tic Timer?

  4. Any thing else from FreeRtos’s point of view?

Thanks.

Joe

rtel wrote on Friday, September 16, 2016:

I’ve been doing this quite a bit myself, and haven’t found any issues
that you would not find in a bare metal (non RTOS) application - so
really FreeRTOS doesn’t add any complexity. As per a non RTOS
application you need to jump to the start up code of the application
being booted, so it initialises its variables etc, (not jump to main()
of the application being booted), set up the vector table base address
(so the vector table of the application is used, not the vector table of
the bootloader), etc, etc.

In addition to disabling interrupts of any peripherals that were enabled
by the bootloader you will also need to somehow disable the systick
interrupt - but for a belt and braces approach I tend to globally
disable interrupts too before jumping to the application (“cpsid i”).

Regards.

amcolex wrote on Sunday, October 09, 2016:

I recently wrote a bootloader for my project, and like you, I also use FreeRTOS in the bootloader and the application.

Here is my jump function:

#define START_ADDRESS               0x08018200 // change accordingly
typedef void (*p_function)(void);


void jump_to_application(void)
{
    uint8_t i;
    uint32_t jump_address = *(__IO uint32_t*)(START_ADDRESS + 4);
    p_function p_jump_function = (p_function)jump_address;

    // stop all interrupts
    __disable_irq();

    // Disable IRQs
    for(i = 0;i < 8;i++)
    {
        NVIC->ICER[i] = 0xFFFFFFFF;
    }
    // Clear pending IRQs
    for(i = 0;i < 8;i++)
    {
        NVIC->ICPR[i] = 0xFFFFFFFF;
    }

    // enable all interrupts
    __enable_irq();

    __set_CONTROL(0);

    // re-init stack pointer (first entry of the vector table)
    __set_MSP(*(__IO uint32_t*)START_ADDRESS);

    //jump!
    p_jump_function();

}