Skip to main content
Explorer
October 15, 2024
Question

Issues with Jumping to Application from Custom Bootloader on STM32F407

  • October 15, 2024
  • 1 reply
  • 2807 views

I am currently working on a custom bootloader for an STM32F407 microcontroller and facing issues when attempting to jump to the application. The application is located at the address 0x08080000.

Here are the details:

Problem Description

When the bootloader tries to jump to the application, the stack pointer and reset handler are not set correctly, and the application does not start. The values read for the stack pointer and reset handler seem incorrect, which prevents the jump from happening successfully.

 

#define APPLICATION_ADDRESS 0x08080000

void JumpToApp(void)

{

// Read the initial stack pointer and reset handler from the application address

appStackPointer = *(__IO uint32_t*)APPLICATION_ADDRESS;

appResetHandler = *(__IO uint32_t*)(APPLICATION_ADDRESS + 4);

// Print debug information

UART_Printf("appStackPointer: 0x%08X\n", appStackPointer);

UART_Printf("appResetHandler: 0x%08X\n", appResetHandler);

// Validate the stack pointer and reset handler

if ((appStackPointer & 0x2FFE0000) == 0x20000000 && (appResetHandler & 0xFF000000) == 0x08000000)

{

// Disable interrupts

__disable_irq();

// Set Vector Table base address

SCB->VTOR = APPLICATION_ADDRESS;

// Set stack pointer

__set_MSP(appStackPointer);

// Function pointer to the reset handler

JumpToApplication = (pFunction)appResetHandler;

// Jump to application reset handler

JumpToApplication();

}

else

{

// Print error message if values are not valid

UART_Printf("Invalid stack pointer or reset handler\n");

}

}

 

1.What could be the reason for the stack pointer and reset handler values being incorrect?

2.Are there any additional steps needed to ensure the correct values are read from the application address?

3.Could there be an issue with how the application is compiled or linked?

 

 

    This topic has been closed for replies.

    1 reply

    Graduate II
    October 15, 2024

    Why you dont show print result here?

    Your Q 1. why you mean is incorrect

    2. yes code must be flashed here and F407 must be 1M flash is app starts on 512k why bootpart so big?

    3. yes for example this must be in app not in jump

    SCB->VTOR = APPLICATION_ADDRESS;

     

    Vignesh_MAuthor
    Explorer
    October 16, 2024

    Hi,

          Specifically for firmware updates. I receive a hex file via UART, store it in a buffer, and before writing to flash, I erase the last 512KB (starting at address 0x08080000). The firmware is then written to this 512KB section of flash memory successfully.

    However, when the bootloader tries to jump to the application, the stack pointer and reset handler are not set correctly, and the application does not start. The values read for the stack pointer and reset handler seem incorrect, which prevents the jump from happening successfully. Below are the runtime values of the stack pointer and reset handler.

    Printing statement

    appStackPointer: 0x20020000
    appResetHandler: 0x08000835
    Invalid stack pointer or reset handler

    Should we have any changes made in linker script(flash.id) and any others?

    The boot partition size is larger; there is a specific requirement for that. Is there a specific requirement for that?

    Can you guide me on how to resolve this issue? If you have any example code, that would be greatly appreciated.

    Graduate II
    October 16, 2024

    This isnt OK appResetHandler: 0x08000835

    Your application build linker config require arange memory. You dont write how IDE used then i asume CubeIDE.

    minimum change is edit LD file an rebuild.

     FLASH (rx) : ORIGIN = 0x8080000, LENGTH = 512K 

    next change VTOR offset in system_...c init file. 

    #define VECT_TAB_OFFSET 0x80000 /*!< Vector Table base offset field. 
     This value must be a multiple of 0x200. */