STM32 BlinkLed fails to flash the .hex file

Hi, I'm following the Baremetal Setup guide Documentation, and found some things missing (which is OK). The board I got is exactly like the one in the document: STM32F746G-DISCO.

  1. The main problem though is that st-flash fails like this:
st-flash --connect-under-reset --format ihex write .build/release/STM32BlinkLED.hex 

st-flash 1.8.0
2025-07-05T16:21:49 INFO common.c: STM32F74x_F75x: 320 KiB SRAM, 1024 KiB flash in at least 2 KiB pages.
2025-07-05T16:21:49 INFO common_flash.c: Attempting to write 402686004 (0x18008034) bytes to stm32 address: 134217728 (0x8000000)
2025-07-05T16:21:49 ERROR common_flash.c: The size exceeds the size of the flash (0x00100000 bytes available)
stlink_fwrite_flash() == -1

Can you help me with the solution? I'm kinda totally new to this baremetal thingy, and just want some working project to tinker with. Maybe I need to somehow remove the firmware that is already there? I tried st-flash erase, it did not change anything

  1. Question. We build release version there. Why not use debug?

  2. As far as I can tell, the project compilation uses only slower CPU cores when building. How to make it use all CPU cores?

Thanks! Sorry for the dumb questions.

PS. Here are some things I found in the document itself. Where is the right place to tell about them?

  1. Step 3: Wrong repository name: https://github.com/swiftlang/swift-mmio/ (it does not exist at the moment) → GitHub - apple/swift-mmio: Define and operate on type safe MMIO
  2. Step 8 contains some TODOs :–)
  3. Step 8, for running elf2hex, you need uv installed (I just did brew install uv)

Hmm. I downloaded STM32CubeProgrammer and it flashed the file successfully (or I think it did). So the firmware was built correctly, I guess.

But I still would like to use st-flash.

Update:
I tried generating hex-file a little bit differently, and it seems to be working now:

./elf2hex.py --relocate-data-segment \
.build/release/STM32BlinkLED .build/release/STM32BlinkLED.hex

this --relocate-data-segment parameter did the trick. Have no idea, if this solution is correct though. ‾\(ツ)/‾

1 Like

Could this perhaps be added to the baremetal guide? Does it apply only to STM32?

Could this perhaps be added to the baremetal guide? Does it apply only to STM32?

Unfortunately, I have no idea. I would really like a comment from someone who knows, how this should work. I'm still trying to wrap my head around this task, but it will take some time :-)