0

I wrote a custom bootloader for the STM32F4 microcontroller and I’m able to write an application to the flash memory at the address of 0x08008000. The issue I have is when I use the jump function the application doesn’t seem to execute. I have attached the jump function below. I have disabled all the peripherals, timers and interrupts. Also, relocated the vector table to 0x08008000 to run the new app.

void bootloader_jump_to_user_app(void)
{

   //just a function pointer to hold the address of the reset handler of the user app.
    void (*app_reset_handler)(void);

    //shut down any tasks running
    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10);
    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_11);
    HAL_TIM_Base_Stop_IT(&htim4);
    HAL_TIM_Base_DeInit(&htim4);
    HAL_RCC_DeInit();
    HAL_DeInit();


    SysTick->CTRL = 0;
    SysTick->LOAD = 0;
    SysTick->VAL = 0;

    //disbale interuppts
    __set_PRIMASK(1);
    __disable_irq();

     SCB->VTOR = FLASH_SECTOR2_BASE_ADDRESS; //0x080080000

    // 1. configure the MSP by reading the value from the base address of the sector 2
    uint32_t msp_value = *(__IO uint32_t *)FLASH_SECTOR2_BASE_ADDRESS;

    __set_MSP(msp_value);

    uint32_t resethandler_address = *(__IO uint32_t *) (FLASH_SECTOR2_BASE_ADDRESS + 4);

    app_reset_handler = (void*) resethandler_address;

    //3. jump to reset handler of the user application
    app_reset_handler();

}

In the linker file for the bootloader I have broken the flash into two parts, one for the app and the other for the bootloader. For the application linker file I have the flash starting at 0x08008000.

/* Memories definition */
MEMORY
{
    CCMRAM  (xrw)   : ORIGIN = 0x10000000,  LENGTH = 64K
    RAM (xrw)   : ORIGIN = 0x20000000,  LENGTH = 128K
    FLASH   (rx)    : ORIGIN = 0x8000000,   LENGTH = 128K
    APPLICATION (rx) : ORIGIN = 0x08008000, LENGTH = 896K
}