From SEGGER Wiki
Revision as of 10:27, 5 November 2019 by Fabian (talk | contribs)
Jump to: navigation, search

STM32G4 option byte programming

For STM32G4 devices, the option byte page(s) can be programmed via J-Flash. When programming the option bytes, the following conditions must be met:

  • Per bank: All option bytes must be written in one go. It is not possible to only write - for example - one word.
  • Reserved bits must be written with "1" otherwise writing the option bytes will not work as expected and the verify of the written area will fail.

STM32G47xx Flash Dual Bank Mode

The ST STM32G47xx series devices come with a dual-bank flash memory. The layout of the dual-bank flash memory can be configured by the user through the option byte nDBANK. By default, the value of this option byte is DBANK == 1, which means that the flash is configured as dual bank memory while DBANK == 0 means that the flash is configured as single bank memory flash. The total flash size is exactly the same for both modes.

Problem description

  • The sector layout is different depending on the DBANK bit
  • The flash algorithm has to behave different (pass different sector indices to erase sector)

By default, the J-Link flash loader assumes that the flash controller is configured for the dual bank flash layout (DBANK == 1) because it is the default configuration. In case of the flash controller is configured for the single bank flash layout (DBANK == 0), the default flash algorithm / sector layout won't work.


When operating the flash in single bank flash mode (DBANK == 0), the flash algorithm as well as the sector layout used by the J-Link DLL needs to be overwritten. This can be done using the SEGGER Open Flashloader. Please find below three precompiled flash algorithms, one for the 128KB, one for the 256KB and one for the 512KB variant of the STM32G47xx device series. The algorithms assume that the flash is configured in single bank mode. Detailed information how to use the precompiled flashloaders can be found here: