cancel
Showing results for 
Search instead for 
Did you mean: 

Switching to application from custom bootloader

pLanka
Visitor

Hi, 

Please help me sort this out.

I am trying to port a custom bootloader originally written for the SAMD21 Arm chip to the STM32U385VGT6. We are upgrading our current product with an STM32 Chip. I am having problems with switching from the bootloader to the application binary. My bootloader is loaded at address 0x08000000. The application binary is compiled to run from 0x08010000. I edited the linker script files to locate the binaries properly and tested opening the binary file with a hex editor. All seems situated correctly. Here is my function to jump to the application. APP_CODE_START is set to 0x08010000. I get "jumping to application" in my debug terminal. But the application code is not running. 

 

void jumpToApplication()
{    DEV_DEBUG_LOG("jumping to application");
     // Disable interrupts before changing MSP and VTOR
    __disable_irq();
    // Jump to the sketch
    __set_MSP(*((uint32_t *)APP_CODE_START));

    // Reset vector table address
    SCB->VTOR = ((uint32_t)(APP_CODE_START)&SCB_VTOR_TBLOFF_Msk);

    // Address of Reset_Handler is written by the linker at the beginning of the .text section.
    uint32_t resetHandlerAddress = *((uint32_t *)APP_CODE_START + 1);

    if (resetHandlerAddress < APP_CODE_START || resetHandlerAddress > (APP_CODE_START + APP_CODE_SIZE)) {
        //this will later cause watchdog reset
        while(1);
    }
 
    // Jump to application
    void (*app_reset_handler)(void) = (void (*)(void))resetHandlerAddress;
    app_reset_handler();
}
2 REPLIES 2
TDK
Super User

Do you ever re-enable interrupts?

You should disable interrupts individually so they do not immediately fire after the jump.

If you feel a post has answered your question, please click "Accept as Solution".
LCE
Principal II

What TDK said.

And:  __disable_irq(); does not actually disable any interrupts, it just prevents the MCU from entering any ISRs.

So better clear the Interrupt Enable and Pending registers. In H7 that's several NVIC->ICER[n] and NVIC->ICPR[n] .