stm32: Allow to have no storage support if there are no block devices.

If no block devices are defined by a board then storage support will be
disabled.  This means there is no filesystem provided by either the
internal flash or external SPI flash.  But the VFS system can still be
enabled and filesystems provided on external devices like an SD card.
This commit is contained in:
Damien George 2018-05-28 10:57:27 +10:00
parent aa4a7a8732
commit f497723802
6 changed files with 31 additions and 1 deletions

View File

@ -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

View File

@ -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();

View File

@ -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)

View File

@ -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

View File

@ -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);
}

View File

@ -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