Skip to content

stm32/boards/ARDUINO_GIGA: Clear the BCM4 option bit at early init. - #20060

Open
kwagyeman wants to merge 1 commit into
micropython:masterfrom
kwagyeman:kwabena/stm32_giga_cm4_boot
Open

kwagyeman wants to merge 1 commit into
micropython:masterfrom
kwagyeman:kwabena/stm32_giga_cm4_boot

Conversation

@kwagyeman

@kwagyeman kwagyeman commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A Giga can leave the factory with the STM32H747's BCM4 option bit set. Ours reads OPTSR 0x0bc6aaf0; a Portenta and a Nicla Vision read 0x0b86aaf0. With the bit set, the Cortex-M4 boots at every reset from its boot address, 0x08100000. That address is inside this firmware's text (FLASH_TEXT is 0x08040000 + 1280K), so the M4 runs whatever M7 code is there.

Two consequences:

  • mp_openamp_remoteproc_start() refuses to start the M4 while the bit is set ("auto-boot is enabled via the option bytes"), so remoteproc can't be used on such a board.
  • Anything that rewrites flash bank 2 while the M4 runs from it is at risk.

This clears the bit in GIGA_board_early_init(), then resets once it reads clear, so that boot also runs without the M4. It only resets if the write took, so a failed write can't loop. It happens once per board.

Testing

Built ARDUINO_GIGA. On the Giga above, clearing BCM4 with the same sequence (unlock the option bytes, clear the bit in OPTSR_PRG, OPTSTART) left it at 0x0b86aaf0 across resets. With the M4 no longer booting, a boot stub's firmware install that had failed on every boot succeeded.

Trade-offs and Alternatives

Anyone who relies on the M4 auto-booting its own firmware from 0x08100000 loses that. MicroPython's text covers that address, so with MicroPython on the M7 nothing useful can live there anyway. The M4 is still started explicitly through remoteproc, which this makes possible.

A Giga can leave the factory with the STM32H747's BCM4 option bit set
(OPTSR 0x0bc6aaf0 on the board here; a Portenta and a Nicla Vision read
0x0b86aaf0, bit clear).  The Cortex-M4 then boots at every reset from its
boot address, 0x08100000, which is inside this firmware's text (FLASH_TEXT
runs from 0x08040000 for 1280K), and runs whatever M7 code is there.

That has visible effects:
- mp_openamp_remoteproc_start refuses to start the M4 while the bit is
  set, so remoteproc can't be used on such a board.
- Anything that rewrites bank 2 while the M4 runs from it is at risk: an
  OTA boot stub installing new firmware there failed on every update
  until the bit was cleared.

Clear the bit in the board's early init, and reset once it reads clear so
that this boot runs without the M4 as well.  This happens once per board.

Signed-off-by: Kwabena W. Agyeman <kwagyeman@live.com>
@kwagyeman kwagyeman moved this to In progress in OpenMV Features Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Code size report:

Reference:  alif: Update to Alif Ensemble DFP v2.2.1. [826d98e]
Comparison: stm32/boards/ARDUINO_GIGA: Clear the BCM4 option bit at early init. [merge of 96a59cb]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants