7
31
Fork
You've already forked blackmagic
23

STM32G0 B/C regression: bank-2 flash programming fails due to not being erased #2270

Open
opened 2026年06月18日 16:06:41 +02:00 by sdw_jitter · 1 comment

It looks like commit 5cb2a94b simplified / removed support for erasing bank 2 on these specific parts.
I have noticed this by getting the error Error writing data to flash for firmwares that cross the 0x08040000
bank boundary. Images that fit entirely within bank 1 (< 256 KiB) flash fine.

Reproduction

  • Target: STM32G0B1RET6 (Cortex-M0+, 512 KiB Flash, dual bank).
  • Build any image whose .text/.rodata extends past 0x08040000.
$ arm-none-eabi-gdb -nx --batch \
 -ex 'target extended-remote /dev/ttyBmpGdb' \
 -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'load' firmware.elf
...
 1 STM32G0B/C M0+
Loading section .vector_table, size 0xbc lma 0x8000000
Loading section .metadata, size 0x10 lma 0x8000200
Loading section .text, size 0x42eac lma 0x8000210
Error writing data to flash

The same ELF flashes successfully with old 1.7 firmware, and with the latest 2.3 hardware running 2.0.0 firmware if the chip is mass-erased first (monitor erase_mass).

Workaround

Explicitly erase the device via 'monitor erase_mass' before loading

Affected devices

I've noticed this on the STM32G0B1RET6 (Cortex-M0+, 512 KiB Flash), there may be other device families/variants with the same issue

It looks like commit 5cb2a94b simplified / removed support for erasing bank 2 on these specific parts. I have noticed this by getting the error _Error writing data to flash_ for firmwares that cross the `0x08040000` bank boundary. Images that fit entirely within bank 1 (< 256 KiB) flash fine. ## Reproduction - Target: STM32G0B1RET6 (Cortex-M0+, 512 KiB Flash, dual bank). - Build any image whose `.text`/`.rodata` extends past `0x08040000`. ``` $ arm-none-eabi-gdb -nx --batch \ -ex 'target extended-remote /dev/ttyBmpGdb' \ -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'load' firmware.elf ... 1 STM32G0B/C M0+ Loading section .vector_table, size 0xbc lma 0x8000000 Loading section .metadata, size 0x10 lma 0x8000200 Loading section .text, size 0x42eac lma 0x8000210 Error writing data to flash ``` The same ELF flashes successfully with old 1.7 firmware, and with the latest 2.3 hardware running 2.0.0 firmware if the chip is mass-erased first (`monitor erase_mass`). ## Workaround Explicitly erase the device via 'monitor erase_mass' before loading ## Affected devices I've noticed this on the STM32G0B1RET6 (Cortex-M0+, 512 KiB Flash), there may be other device families/variants with the same issue

This looks like an oversight on our part - the logic is actually still there, it's just that the page calculation cannot say "this is bank 2" - STM32G0_FLASH_BANK2_START_PAGE should be converted from a page number to an address or part of the part_id based logic ported back and used to calculate the bank start for (page >= STM32G0_FLASH_BANK2_START_PAGE ? STM32G0_FPEC_CTRL_BKER : 0), replacing usage of the constant here.

Thank you for reporting this!

This looks like an oversight on our part - the logic is actually still there, it's just that the `page` calculation cannot say "this is bank 2" - STM32G0_FLASH_BANK2_START_PAGE should be converted from a page number to an address or part of the part_id based logic ported back and used to calculate the bank start for `(page >= STM32G0_FLASH_BANK2_START_PAGE ? STM32G0_FPEC_CTRL_BKER : 0)`, replacing usage of the constant here. Thank you for reporting this!
Sign in to join this conversation.
No Branch/Tag specified
main
fix/pre-bmp-v3-cross-file-cleanup
feature/bmda-remote-comms
ALTracer/feature/aarch64-ident
feature/better-meson-optimisation-handling
feature/am335x-support
feature/esp32-c3-support
feature/cortex-ar-software-breakpoints
feature/unit-testing
feature/windows-usb-serial-interface-naming
fix/bmp-external-spi
ALTracer/feature/bluepillplus-platform
ALTracer/feature/at32f43x-unrdp
feature/const-correctness
ALTracer/feature/fault_handlers
ALTracer/feature/hazard3-ice40-support
fix/ci-cleanup
ALTracer/fix/gdb-10-12-thread
ALTracer/feature/blackpill-f4-adc
ALTracer/fix/cortex-desc-allocfail-report
ALTracer/feature/spi-perf
ALTracer/feature/calibrate_swd
ALTracer/feature/blank-check
feature/avr
v2.0
v1.9
v1.10
v1.8
v2.1.0-rc1
v2.0.0
v2.0.0-rc2
v2.0.0-rc1
v1.9.3
v1.10.2
v1.10.1
v1.10.0
v1.10.0-rc1
v1.10.0-rc0
v1.9.2
v1.8.3
v1.9.1
v1.9.0
v1.9.0-rc1
v1.9.0-rc0
v1.8.2
v1.8.1
v1.8.0
v1.7.1
v1.7
v1.6.2-rc1
1.6.2-rc0
v1.6.1
v1.6
v1.6-rc1
v1.6-rc0
production_01
production_00
Labels
Clear labels
BMD App
Black Magic Debug App (aka. PC hosted) (not firmware)
BMP Firmware
Black Magic Probe Firmware (not PC hosted software)
Bug
Confirmed bug
Build system
Build system
Can't reproduce
Maintainers can't reproduce this problem
CI
Continuous Integration System
Contribution wanted
User contributions welcome
Documentation
Project documentation
Draft
Work in progress draft
Duplicate
This issue or pull request already exists
Enhancement
General project improvement
Feedback wanted
Requires additional submitter feedback
Foreign Host Board
Non Native hardware to runing Black Magic firmware on
GDB
Issue/PR related to GDB
Good first issue
Good for newcommers
HwIssue Mitigation
Solving or mitigating a Hardware issue in Software
Information Needed
Maintainers need more information
NativeHardware
Official Black Magic Debug Hardware
New Host Board
New hardware to run Black Magic firmware on
New Target
New debug target
Off Topic
Something that does not involve the project in any way
Potential Bug
A potential, unconfirmed or very special circumstance bug
Regression
Bug caused by a regression
User Interest Needed
More user interest required before consideration
User Testing Needed
Looking for user testing reports
Won't fix
Outside of the project scope or works as intended
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
blackmagic-debug/blackmagic#2270
Reference in a new issue
blackmagic-debug/blackmagic
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?