2024-09-30
02:16 AM
- last edited on
2024-09-30
04:12 AM
by
Laurids_PETERSE
I am using STM32H723VG and I want to implement bootloader for firmware update. I want to enter STM32 bootloader to flash data through USB DFU inside firmware:
#define BOOTLOADER_ADDRESS_START 0x1FF09800
void Bootloader_JumpToBootloader()
{
__disable_irq();
USBD_DeInit(&hUsbDeviceFS);
HAL_RCC_DeInit();
HAL_DeInit();
HAL_Delay(100);
SysTick->CTRL = 0;
uint8_t cnt = (sizeof(NVIC->ICER) / sizeof(*NVIC->ICER));
for (int i = 0; i < cnt; i++)
{
NVIC->ICER[i] = 0xFFFFFFFF;
NVIC->ICPR[i] = 0xFFFFFFFF;
}
SCB_InvalidateICache();
SCB_DisableICache();
SCB_CleanDCache();
SCB_DisableDCache();
__set_MSP(*((uint32_t *)BOOTLOADER_ADDRESS_START));
SCB->VTOR = BOOTLOADER_ADDRESS_START;
void (*SysMemBootJump)(void);
SysMemBootJump = (void (*)(void))(*((uint32_t *)(BOOTLOADER_ADDRESS_START + 4U)));
SysMemBootJump();
}
The issue I'm encountering is that the USB DFU interface only initializes sporadically after executing this function. Sometimes the DFU mode starts correctly, and I'm able to flash new firmware without any problems. Other times, the DFU mode doesn't initialize at all, and the device isn't recognized over USB.
I've tried disabling all peripherals before jumping to the bootloader, but this hasn't resolved the issue. It seems to be random whether the DFU mode starts correctly or not.
Any insights, suggestions, or guidance would be greatly appreciated!
Thank you!
Solved! Go to Solution.
2024-10-01 06:24 AM
If you use USB in your application, which it looks like you do, insert a 1s pause after de-initializing USB but before jumping to the bootloader. USB requires some downtime for the PC to notice that the device is not there.
2024-09-30 05:15 AM
> __disable_irq();
The USB DFU bootloader requires interrupts to be enabled. Your code disables them globally.
Put __enable_irq() somewhere prior to jumping to the bootloader.
2024-09-30 10:38 PM
It helped, but still one out of three jumps to bootloader ends without entering DFU. Sometimes powering off and on resovle my problem but not always.
2024-10-01 06:24 AM
If you use USB in your application, which it looks like you do, insert a 1s pause after de-initializing USB but before jumping to the bootloader. USB requires some downtime for the PC to notice that the device is not there.