cancel
Showing results for 
Search instead for 
Did you mean: 

Issues with Jumping to Application from Custom Bootloader on STM32F407

Vignesh_M
Associate II

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?

 

 

13 REPLIES 13
MM..1
Chief III

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;

 

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.

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. */

Hi,

    I changed as per your suggestion, so below given details, but it's not working again same problem. If should any changes in the project please let me know

 MEMORY
{
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
FLASH1 (rx) : ORIGIN = 0x8080000, LENGTH = 512K
} 

#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x80000 /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#else
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x80000 /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#endif /* VECT_TAB_SRAM */

Give some more detail explanation, or please arrange a one section for discussion on this, I need more clarification on this.

 

Where you see in my line FLASH1, or you change all occurence in ld file from FLASH to FLASH1 ???

@Vignesh_M ,

Please use </> button to paste you code. See these tips on how to post a thread.

Thank you for your understanding.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

if ((appStackPointer & 0xFFF00003) == 0x20000000 && (appResetHandler & 0xFFC00001) == 0x08000001)

Might be a more effective sanity check, ie SP in RAM and 32-bit aligned, and PC in FLASH and ODD, rather than 0xFFFFFFFF of erased FLASH

Make sure to enable interrupts when you get to the other side.

Perhaps us a SYMBOL to define SCB->VTOR, that way the LINKER can do it's job and not require you to curate a bunch of source files continuously.

ie

extern uint32_t g_pfnVectors[];

SCB->VTOR = (uint32_t)&g_pfnVectors[0]; // Use the Symbol to determine the address.. FFS

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi, 

     I tried what you suggested. I debugged the program and then ran it, but it still doesn't run properly. It seems to go somewhere unexpected.

MEMORY
{
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
FLASH (rx) : ORIGIN = 0x8080000, LENGTH = 512K
}

First step your code must work alone. Try on normal 08000000 or jump from stmcubeprogrammer or CLI 08080000.