CubeOrange+ Secure Bootloader breaks USB in release build (-Os), works only with --debug (-Og)

Description:
I am implementing secure boot on CubeOrange+ (STM32H757) using ArduPilot.

Issue:
The secure bootloader built in normal (non-debug) mode causes complete USB enumeration failure after reboot, while the same bootloader built with --debug works correctly.

Hardware:

  • Board: CubeOrange+
  • MCU: STM32H757
  • Connection: USB (OTG FS)
  • Debug: ST-Link V2 (SWD)

Software Setup:
ArduPilot versions tested:

  • 4.5.7 (default)
  • 4.6.3 (modified to fit flash)

Build commands:
Non-debug:
Tools/scripts/build_bootloaders.py CubeOrangePlus --signing-key=KEY.dat

Debug:
Tools/scripts/build_bootloaders.py CubeOrangePlus --signing-key=KEY.dat --debug

Observed Behavior:

Non-debug bootloader (-Os):

  • Firmware upload succeeds
  • After reboot:
    • No USB enumeration
    • No /dev/ttyACM*
    • Not visible in lsusb
  • Board appears dead over USB
  • Recoverable via ST-Link

Debug bootloader (-Og):

  • Works correctly
  • USB enumerates as:
    CubeOrange±Secure-BL-v10
  • Firmware loads and runs normally

Key Finding:
Issue reproducible on:

  • Stock ArduPilot 4.5.7 (no modifications)
  • Reduced 4.6.3 build (no modifications)

Conclusion: Not caused by user modifications.

GDB_logs.txt (10.0 KB)