Skip to main content
Associate II
September 30, 2024
Solved

STM32H723 DFU mode sometimes not entering

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!

This topic has been closed for replies.
TDK
TDKBest answer
October 1, 2024

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.

"If you feel a post has answered your question, please click ""Accept as Solution""."

3 replies

TDK
September 30, 2024

> __disable_irq();

The USB DFU bootloader requires interrupts to be enabled. Your code disables them globally.

TDK_0-1727698461908.png

 

Put __enable_irq() somewhere prior to jumping to the bootloader.

"If you feel a post has answered your question, please click ""Accept as Solution""."
adakPalAuthor
Associate II
October 1, 2024

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.

TDK
TDKBest answer
October 1, 2024

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.

"If you feel a post has answered your question, please click ""Accept as Solution""."