modm-io / modm

modm: a C++23 library generator for AVR and ARM Cortex-M devices
https://modm.io
Mozilla Public License 2.0
746 stars 132 forks source link

[STM32G4] flash dual bank ignored during erase #1151

Closed hshose closed 3 months ago

hshose commented 6 months ago

Problem: When writing to flash pages beyond 128 on STM32G4 (in particular G474), Flash::erase fails silently und the Flash::program does not return an error (even though, right after programming the PROGERR Bit 3 in FLASH->SR register is set, as GDB tells me).

This is due to the DBANK bit not beeing set in the flash.cpp

According to the RM0440, pp. 135, in dual bank mode (DBANK=1), the BKER bit should be set to 1 for pages after 128. Dual bank mode is default.

What really threw me off was, that I could program addresses beyond page 128 once. I just now realized, that this this is likely because the factory values for flash would be 0x00 or 0xFF, in which case they are already erased the first time programmed.

At least the G474 Flash example and #1146 are effected by this problem.

hshose commented 6 months ago

Proposed fix in #1146

hshose commented 6 months ago

LOL might need a bit more logic to model the dual bank flash on the G4 family: image

salkinium commented 3 months ago

Fixed in https://github.com/modm-io/modm/pull/1146.