diff --git a/ports/stm32/main.c b/ports/stm32/main.c index 5c75355422..d24200ba0f 100644 --- a/ports/stm32/main.c +++ b/ports/stm32/main.c @@ -130,6 +130,7 @@ STATIC mp_obj_t pyb_main(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a } MP_DEFINE_CONST_FUN_OBJ_KW(pyb_main_obj, 1, pyb_main); +#if MICROPY_HW_ENABLE_STORAGE static const char fresh_boot_py[] = "# boot.py -- run on boot-up\r\n" "# can run arbitrary Python, but best to keep it minimal\r\n" @@ -264,6 +265,7 @@ MP_NOINLINE STATIC bool init_flash_fs(uint reset_mode) { return true; } +#endif #if MICROPY_HW_HAS_SDCARD STATIC bool init_sdcard_fs(void) { @@ -512,7 +514,9 @@ void stm32_main(uint32_t reset_mode) { #if MICROPY_HW_HAS_SDCARD sdcard_init(); #endif + #if MICROPY_HW_ENABLE_STORAGE storage_init(); + #endif #if MICROPY_PY_LWIP // lwIP doesn't allow to reinitialise itself by subsequent calls to this function // because the system timeout list (next_timeout) is only ever reset by BSS clearing. @@ -599,7 +603,10 @@ soft_reset: // Initialise the local flash filesystem. // Create it if needed, mount in on /flash, and set it as current dir. - bool mounted_flash = init_flash_fs(reset_mode); + bool mounted_flash = false; + #if MICROPY_HW_ENABLE_STORAGE + mounted_flash = init_flash_fs(reset_mode); + #endif bool mounted_sdcard = false; #if MICROPY_HW_HAS_SDCARD @@ -727,8 +734,10 @@ soft_reset_exit: // soft reset + #if MICROPY_HW_ENABLE_STORAGE printf("PYB: sync filesystems\n"); storage_flush(); + #endif printf("PYB: soft reboot\n"); #if MICROPY_PY_NETWORK diff --git a/ports/stm32/modmachine.c b/ports/stm32/modmachine.c index 73442719b5..ff1eaec95f 100644 --- a/ports/stm32/modmachine.c +++ b/ports/stm32/modmachine.c @@ -231,7 +231,9 @@ STATIC NORETURN mp_obj_t machine_bootloader(void) { #if MICROPY_HW_ENABLE_USB pyb_usb_dev_deinit(); #endif + #if MICROPY_HW_ENABLE_STORAGE storage_flush(); + #endif HAL_RCC_DeInit(); HAL_DeInit(); diff --git a/ports/stm32/mpconfigboard_common.h b/ports/stm32/mpconfigboard_common.h index 7449a68956..919598de44 100644 --- a/ports/stm32/mpconfigboard_common.h +++ b/ports/stm32/mpconfigboard_common.h @@ -169,6 +169,13 @@ #define MICROPY_HW_BDEV_WRITEBLOCK flash_bdev_writeblock #endif +// Enable the storage sub-system if a block device is defined +#if defined(MICROPY_HW_BDEV_IOCTL) +#define MICROPY_HW_ENABLE_STORAGE (1) +#else +#define MICROPY_HW_ENABLE_STORAGE (0) +#endif + // Enable hardware I2C if there are any peripherals defined #if defined(MICROPY_HW_I2C1_SCL) || defined(MICROPY_HW_I2C2_SCL) \ || defined(MICROPY_HW_I2C3_SCL) || defined(MICROPY_HW_I2C4_SCL) diff --git a/ports/stm32/spibdev.c b/ports/stm32/spibdev.c index 91ec4df5e9..b73058c6ab 100644 --- a/ports/stm32/spibdev.c +++ b/ports/stm32/spibdev.c @@ -30,6 +30,8 @@ #include "led.h" #include "storage.h" +#if MICROPY_HW_ENABLE_STORAGE + int32_t spi_bdev_ioctl(spi_bdev_t *bdev, uint32_t op, uint32_t arg) { switch (op) { case BDEV_IOCTL_INIT: @@ -79,3 +81,5 @@ int spi_bdev_writeblocks(spi_bdev_t *bdev, const uint8_t *src, uint32_t block_nu return ret; } + +#endif diff --git a/ports/stm32/stm32_it.c b/ports/stm32/stm32_it.c index b7124de894..b051382875 100644 --- a/ports/stm32/stm32_it.c +++ b/ports/stm32/stm32_it.c @@ -310,9 +310,11 @@ void SysTick_Handler(void) { // be generalised in the future then a dispatch table can be used as // follows: ((void(*)(void))(systick_dispatch[uwTick & 0xf]))(); + #if MICROPY_HW_ENABLE_STORAGE if (STORAGE_IDLE_TICK(uwTick)) { NVIC->STIR = FLASH_IRQn; } + #endif if (DMA_IDLE_ENABLED() && DMA_IDLE_TICK(uwTick)) { dma_idle_handler(uwTick); @@ -459,8 +461,10 @@ void FLASH_IRQHandler(void) { HAL_FLASH_IRQHandler(); } */ + #if MICROPY_HW_ENABLE_STORAGE // This call the storage IRQ handler, to check if the flash cache needs flushing storage_irq_handler(); + #endif IRQ_EXIT(FLASH_IRQn); } diff --git a/ports/stm32/storage.c b/ports/stm32/storage.c index 2ac54a4010..761db0b525 100644 --- a/ports/stm32/storage.c +++ b/ports/stm32/storage.c @@ -34,6 +34,8 @@ #include "storage.h" #include "irq.h" +#if MICROPY_HW_ENABLE_STORAGE + #define FLASH_PART1_START_BLOCK (0x100) #if defined(MICROPY_HW_BDEV2_IOCTL) @@ -284,3 +286,5 @@ void pyb_flash_init_vfs(fs_user_mount_t *vfs) { vfs->u.ioctl[0] = (mp_obj_t)&pyb_flash_ioctl_obj; vfs->u.ioctl[1] = (mp_obj_t)&pyb_flash_obj; } + +#endif