Skip to content

Conversation

@sensei-hacker
Copy link
Member

@sensei-hacker sensei-hacker commented Jan 26, 2026

User description

Summary

Fixes the CLI dfu command on STM32H743/H750 targets. Previously, the command would reboot the board but it would return as a VCP device instead of entering DFU mode for firmware flashing.

Root cause: The bootloader request check was happening too late in the boot sequence (after clock and peripheral initialization). The H7 ROM bootloader requires the RTC backup register check to occur before any system configuration happens.

Solution: moved checkForBootLoaderRequest from src/main/drivers/system_stm32h7xx.c to src/main/target/system_stm32h7xx.c (CMSIS startup, before any hardware initialization). Also enable SYSCFG clock before jumping to bootloader.

Changes

  • src/main/target/system_stm32h7xx.c: Added early bootloader check in SystemInit() before any clock configuration
  • src/main/drivers/system_stm32h7xx.c: Removed late bootloader check from systemInit()
  • src/main/drivers/system.c: Added H7-specific bootloader jump code with SYSCFG clock enablement (properly gated with #if defined(STM32H7))

Platform Impact

H7-specific only. All changes are either in H7-specific files or properly gated with #if defined(STM32H7) in shared files. F4/F7/AT32 platforms are completely unaffected.

Testing

  • Target: DAKEFPVH743PRO
  • Test: CLI dfu command
  • Result: ✅ Successfully enters DFU mode (tested with dfu-util)
  • Versions affected: This issue existed in 7.1.2, 8.0.0, and 9.0.0 (not a regression, never worked on H7)

Test Plan

  • Tested on H743 hardware - DFU entry works
  • Verified F4/F7/AT32 code paths unchanged
  • Confirmed all changes are H7-specific or properly gated
  • Built and tested firmware successfully

PR Type

Bug fix


Description

  • Move bootloader check to early SystemInit() before clock configuration

  • Enable SYSCFG clock before jumping to H7 bootloader

  • Add H7-specific bootloader jump code with proper gating

  • Remove late bootloader check from systemInit() driver function


Diagram Walkthrough

flowchart LR
  A["Boot sequence"] --> B["SystemInit CMSIS startup"]
  B --> C["checkForBootLoaderRequest early"]
  C --> D{"Bootloader request?"}
  D -->|Yes H7| E["Enable SYSCFG clock"]
  E --> F["Jump to bootloader"]
  D -->|No| G["Continue normal boot"]
  D -->|Yes F4/F7| H["Jump to bootloader"]
Loading

File Walkthrough

Relevant files
Bug fix
system.c
Add H7-specific bootloader jump with SYSCFG clock               

src/main/drivers/system.c

  • Added H7-specific bootloader jump code with
    __HAL_RCC_SYSCFG_CLK_ENABLE() call
  • Wrapped H7 bootloader logic with #if defined(STM32H7) preprocessor
    guard
  • Maintained F4/F7 bootloader jump code in else branch
  • Added comments clarifying reset reason clearing and bootloader jump
    steps
+16/-0   
system_stm32h7xx.c
Remove late bootloader check from systemInit                         

src/main/drivers/system_stm32h7xx.c

  • Removed checkForBootLoaderRequest() call from systemInit() function
  • This call is now performed earlier in SystemInit() before clock
    configuration
+0/-2     
system_stm32h7xx.c
Add early bootloader check in SystemInit                                 

src/main/target/system_stm32h7xx.c

  • Added early checkForBootLoaderRequest() call in SystemInit() CMSIS
    startup function
  • Positioned before FPU configuration and any clock/peripheral
    initialization
  • Added comment explaining the early check requirement for H7 ROM
    bootloader
+3/-0     

The CLI 'dfu' command on STM32H743/H750 targets was failing to enter
DFU bootloader mode. The board would reboot but return as a VCP device
instead of entering DFU mode for firmware flashing.

Root cause: Bootloader request check was happening too late in the boot
sequence, after clock and peripheral initialization. The H7 bootloader
requires the RTC backup register check to occur before any system
configuration.

Solution: Move checkForBootLoaderRequest() from systemInit() to
SystemInit(), which is called by CMSIS startup code before any hardware
initialization. Also enable SYSCFG clock before jumping to bootloader,
matching the working Betaflight implementation for H7.

Changes:
- src/main/target/system_stm32h7xx.c: Call checkForBootLoaderRequest()
  early in SystemInit() before clock configuration
- src/main/drivers/system_stm32h7xx.c: Remove late call from systemInit()
- src/main/drivers/system.c: Add H7-specific bootloader jump code that
  enables SYSCFG clock before jumping

Tested on DAKEFPVH743PRO - CLI 'dfu' command now successfully enters
DFU mode for firmware flashing.

Fixes issue present in 7.1.2, 8.0.0, and 9.0.0 releases.
@qodo-code-review
Copy link
Contributor

ⓘ Your approaching your monthly quota for Qodo. Upgrade your plan

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

@sensei-hacker
Copy link
Member Author

Tested by Daijubou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant