2026-01-20 9:09 PM
Hi Community,
I am facing an issue with my custom bootloader not jumping to my main application after firmware upgrade. However, i am able to jump to application during a normal power cycle. The firmware transfer is done through USB CDC using a serial utility.exe and the data is stored in bank 2 of the flash. After this my application sets a value(flag) to a memory location for my bootloader to know firmware copy to be done. My application now jumps to bootloader to do the copy of firmware, clear the flag and jump to updated application. I am sending a response to serial utility before jump. I notice that sometimes the usb state is not ready and it doesn't send the response. But sometimes it is ready and send response, but bootloader sometimes fail to jump to application properly. Please help me out. Thanks
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
USBPoll();
if(upgradeStatusFlag == FLAG_SET)
{
if(copyFirmwareToAppAddress()!= SUCCESS)
{
Error_Handler();
}
if(clearUpgradeStatusFlag() != SUCCESS)
{
Error_Handler();
}
if (hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED)
{
if (!((SendResponse ((uint8_t *)SendUpgradeComplete, strlen(SendUpgradeComplete)))!=0)){
HAL_Delay(2000);
jumpToApplication();
}
}
else
{
Error_Handler();
}
}
else
{
//normal boot
}
}void jumpToApplication(void)
{
void (*BootJump)(void);
volatile uint32_t AppAddr = 0X08010000;
__disable_irq();
SysTick->CTRL = 0;
HAL_RCC_DeInit();
for (uint32_t i=0;i< 5; i++)
{
NVIC->ICER[i]= 0xFFFFFFFF;
NVIC->ICPR[i]= 0xFFFFFFFF;
}
__enable_irq();
BootJump = (void (*)(void)) (*((uint32_t *) ((AppAddr + 4))));
__set_MSP(*(uint32_t *)AppAddr);
BootJump();
while (1)
{
/* Code should never reach this loop */
}
}