diff --git a/main.c b/main.c index ba6950e34c..4cdc39bf21 100644 --- a/main.c +++ b/main.c @@ -836,6 +836,12 @@ int __attribute__((used)) main(void) { // Start the debug serial serial_early_init(); + #if CIRCUITPY_EXTERNAL_FLASH_SETUP + // Set up anything that might need to get done before we try to use SPI flash + // This is needed for some boards where flash relies on GPIO setup to work + external_flash_setup(); + #endif + // Create a new filesystem only if we're not in a safe mode. // A power brownout here could make it appear as if there's // no SPI flash filesystem, and we might erase the existing one. diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 081048181e..80625a2cae 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -49,6 +49,9 @@ CFLAGS += -DMICROPY_PY_USELECT=$(MICROPY_PY_USELECT) MICROPY_PY_USELECT_SELECT ?= $(MICROPY_PY_USELECT) CFLAGS += -DMICROPY_PY_USELECT_SELECT=$(MICROPY_PY_USELECT_SELECT) +# enable pre-flash GPIO setup +CIRCUITPY_EXTERNAL_FLASH_SETUP ?= 0 +CFLAGS += -DCIRCUITPY_EXTERNAL_FLASH_SETUP=$(CIRCUITPY_EXTERNAL_FLASH_SETUP) CIRCUITPY_AESIO ?= $(CIRCUITPY_FULL_BUILD) CFLAGS += -DCIRCUITPY_AESIO=$(CIRCUITPY_AESIO) diff --git a/supervisor/board.h b/supervisor/board.h index 605c16f5dc..d9aee837f7 100644 --- a/supervisor/board.h +++ b/supervisor/board.h @@ -47,5 +47,9 @@ void reset_board(void); // disabling USB, BLE or flash) because CircuitPython may continue to run. void board_deinit(void); +// Configure anything that needs to get set up before the external flash +// is init'ed. For example, if GPIO needs to be configured to enable the +// flash chip, as is the case on some boards. +void external_flash_setup(void); #endif // MICROPY_INCLUDED_SUPERVISOR_BOARD_H