Jump to application from bootloader not working
I have reviewed the many posts from others that have not been able to jump from a bootloader the application code and nothing that I tried worked.
My MCU has its 128kB of flash in two banks, one at 0x08000000 and the other at 0x08040000. When the MCU is reset, it starts with the code in the first bank, so this is where my bootloader is located.
I have 6kB of flash reserved for storing calibration and configuration information immediately following the bootloader. I have the application code in the second bank (0x08040000).
The sole purpose of my bootloader is to allow an application software package to update the application firmware over a Modbus connection (via USB or RS485). I am able to send the new firmware and successfully program the new application code. I have verified this by using the STM32CubeProgrammer to compare the file to the updated flash contents.
Without the bootloader, the application code works fine from STM23CubeIDE when debugging.
When the bootloader resets, it verifies the application code CRC, then it will jump to the application code in the second bank. I have the following code that is a compilation from a few posts, but it is not working. Please Help...
#define APP_ADDR 0x08040000 // my MCU app code base address
#define MCU_IRQS 102u // no. of NVIC IRQ inputs
struct app_vectable_ {
uint32_t Initial_SP;
void (*Reset_Handler)(void);
};
#define APPVTAB ((struct app_vectable_ *)APP_ADDR)
void JumpToApploader(void)
{
/* Disable all interrupts */
__disable_irq();
/* Disable Systick timer */
SysTick->CTRL = 0;
/* Set the clock to the default state */
HAL_RCC_DeInit();
/* Clear Interrupt Enable Register & Interrupt Pending Register */
for (uint8_t i = 0; i < (MCU_IRQS + 31u) / 32; i++)
{
NVIC->ICER[i]=0xFFFFFFFF;
NVIC->ICPR[i]=0xFFFFFFFF;
}
/* Re-enable all interrupts */
__enable_irq();
// Set the MSP
__set_MSP(APPVTAB->Initial_SP);
// Jump to app firmware
APPVTAB->Reset_Handler();
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
void dbaseGoToApp(void)
{
// start executing the application code if it appears to be valid
if (dbaseIsAppOk())
{
JumpToApploader();
}
}
