stm32g0: Add flash bank swap support - #20060
Merged
xiaoxiang781216 merged 1 commit intoSep 5, 2026
Merged
Conversation
Add APIs to toggle the dual-bank flash mapping and reload the option bytes. Reject bank swapping when BOOT_LOCK is enabled and leave the swap operation as a no-op on single-bank devices. Assisted-by: OpenAI Codex <codex@openai.com> Signed-off-by: jsanchez-2g <jsanchez@2g-eng.com>
jsanchez-2g
requested review from
masayuki2009,
raiden00pl and
simbit18
as code owners
September 4, 2026 16:58
acassis
approved these changes
Sep 4, 2026
xiaoxiang781216
approved these changes
Sep 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add STM32G0 flash APIs required to switch dual-bank memory mapping and reload
flash option bytes:
stm32_flash_swapbanks()togglesFLASH_OPTR_NSWAP_BANKstm32_flash_optload()launches an option-byte reload-EPERMwhenFLASH_SECR_BOOT_LOCKis activeReloading option bytes after changing the bank mapping normally causes an
immediate system reset.
Validation
git diff --check: passedtools/checkpatch.sh -g HEAD^..HEAD: passedCONFIG_STM32_PROGMEM=y:CONFIG_STM32_PROGMEM=y:Hardware validation
Tested the equivalent existing implementation on a 2G BMS Golgi STM32G0B1
target using two consecutive RS-485 firmware updates.
Observed option-byte states:
FLASH_OPTR=fef9feaanSWAP_BANK=1FLASH_OPTR=fee9feaanSWAP_BANK=0FLASH_OPTR=fef9feaanSWAP_BANK=1Both updates completed successfully. After each update, the target rebooted,
mounted its filesystem, initialized its communication interfaces and BMS
hardware, and resumed normal operation.
The hardware image used the product-tree implementation from which these APIs
were ported. The submitted code was rebased and compile-validated against
current Apache NuttX master.