diff options
author | Damien George <damien@micropython.org> | 2025-03-19 22:01:56 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-04-03 16:15:35 +1100 |
commit | 1660faacf6c8a5837a76dfa2b12f90e87347863c (patch) | |
tree | 9c9400da37655681fb2d1b324bd02374072c6658 | |
parent | ac1cbef36661625dabc47bc4aa0aa7a0d076dec1 (diff) |
stm32/boards/PYBD_SF2: Restart qspi memory-mapped mode during startup.
The PYBD boards use an F7xx which has an errata 2.4.3:
Memory-mapped read operations may fail when timeout counter is enabled
This is unfortunate because it means that once QSPI memory-mapped flash is
accessed the QSPI peripheral will leave the CS pin active (low) forever,
which increases power consumption of the SPI flash chip (because it's
active and waiting for commands). The exact amount of power increase
depends on the flash, but the PYBD_SFx increase by about 2.5mA.
Previously this increase in power only happened when QSPI flash was needed,
eg on PYBD_SF2 when mbedtls or nimble libraries were used. On PYBD_SF6
it's actually never used.
But with the introduction of ROMFS which lives in the QSPI flash, the
memory is always access on start up to see if the ROMFS contains a valid
image (it must read the memory to find out). That means these boards
always consume about 2.5mA more after starting up (compared to when ROMFS
is disabled).
The fix in this commit is to explicitly restart the QSPI memory mapped mode
during the start up process. More precisely, the restart is done after
querying the ROMFS and just before trying to execute `boot.py`. That's the
right location to keep power consumption permanently down if the QSPI is
never used (eg ROMFS image doesn't exist).
Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r-- | ports/stm32/boards/PYBD_SF2/board_init.c | 10 | ||||
-rw-r--r-- | ports/stm32/boards/PYBD_SF2/mpconfigboard.h | 3 |
2 files changed, 13 insertions, 0 deletions
diff --git a/ports/stm32/boards/PYBD_SF2/board_init.c b/ports/stm32/boards/PYBD_SF2/board_init.c index b39da97c4..2f277d1cc 100644 --- a/ports/stm32/boards/PYBD_SF2/board_init.c +++ b/ports/stm32/boards/PYBD_SF2/board_init.c @@ -61,6 +61,16 @@ void board_early_init(void) { #if !BUILDING_MBOOT +#include "boardctrl.h" +#include "qspi.h" + +int board_run_boot_py(boardctrl_state_t *state) { + // Due to errata 2.4.3, restart memory-mapped mode to deactivate the CS line and save power. + qspi_memory_map_restart(); + + return boardctrl_run_boot_py(state); +} + void board_sleep(int value) { mp_spiflash_deepsleep(&spi_bdev.spiflash, value); mp_spiflash_deepsleep(&spi_bdev2.spiflash, value); diff --git a/ports/stm32/boards/PYBD_SF2/mpconfigboard.h b/ports/stm32/boards/PYBD_SF2/mpconfigboard.h index 3ae11125d..da5ab9e7f 100644 --- a/ports/stm32/boards/PYBD_SF2/mpconfigboard.h +++ b/ports/stm32/boards/PYBD_SF2/mpconfigboard.h @@ -43,11 +43,14 @@ #define MICROPY_HW_ENABLE_RF_SWITCH (1) #define MICROPY_BOARD_EARLY_INIT board_early_init +#define MICROPY_BOARD_RUN_BOOT_PY board_run_boot_py #define MICROPY_BOARD_ENTER_STOP board_sleep(1); #define MICROPY_BOARD_LEAVE_STOP board_sleep(0); #define MICROPY_BOARD_ENTER_STANDBY board_sleep(1); #define MICROPY_BOARD_SDCARD_POWER mp_hal_pin_high(pyb_pin_EN_3V3); +struct _boardctrl_state_t; void board_early_init(void); +int board_run_boot_py(struct _boardctrl_state_t *state); void board_sleep(int value); // HSE is 25MHz, run SYS at 120MHz |