cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U575 - Jump to Application from Custom Bootloader & USB not ready issue

Tarun_05
Associate

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

 

1 REPLY 1
gbm
Principal

Please read the dozens of threads on bootloaders on this forum - you will find a lot of information there; the topic is coming back every week on the forum. Basically, you should not jump to application from another application and especially not from the interrupt context. You should start the application from the bootloader, going through software-generated reset and jumping to it at the very start of the bootloader code, before initializing anything, even the clocks. For USB, the application should wait about 20..50 ms before activating the USB interface, so that the host has a chance to notice device's disconnection and connection.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice