Skip to main content
Graduate
September 30, 2024
Solved

STM32H723 DFU mode sometimes not entering

  • September 30, 2024
  • 2 replies
  • 1478 views

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.
    Best answer by TDK

    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.

    2 replies

    Super User
    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.

    adakPalAuthor
    Graduate
    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.

    TDKAnswer
    Super User
    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.