Issues with Jumping to Application from Custom Bootloader on STM32F407
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?
