summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-03-10 00:55:06 +1100
committerDamien George <damien.p.george@gmail.com>2018-03-10 00:59:43 +1100
commitbb3359f357b7e73bb5cd76c4a267ea6f2fd90c7a (patch)
tree079142cba378478e73492ed8004e3aa682ea1186
parent626d6c9756df3f089b9f62d15f343cdf080c7f80 (diff)
stm32/boards/STM32L476DISC: Provide SPI-flash bdev config.
This board shows how to configure external SPI flash as the main storage medium. It uses software SPI.
-rw-r--r--ports/stm32/boards/STM32L476DISC/bdev.c22
-rw-r--r--ports/stm32/boards/STM32L476DISC/mpconfigboard.h12
2 files changed, 34 insertions, 0 deletions
diff --git a/ports/stm32/boards/STM32L476DISC/bdev.c b/ports/stm32/boards/STM32L476DISC/bdev.c
new file mode 100644
index 000000000..50a02498a
--- /dev/null
+++ b/ports/stm32/boards/STM32L476DISC/bdev.c
@@ -0,0 +1,22 @@
+#include "storage.h"
+#include "genhdr/pins.h"
+
+// External SPI flash uses standard SPI interface
+
+const mp_soft_spi_obj_t soft_spi_bus = {
+ .delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY,
+ .polarity = 0,
+ .phase = 0,
+ .sck = &MICROPY_HW_SPIFLASH_SCK,
+ .mosi = &MICROPY_HW_SPIFLASH_MOSI,
+ .miso = &MICROPY_HW_SPIFLASH_MISO,
+};
+
+const mp_spiflash_config_t spiflash_config = {
+ .bus_kind = MP_SPIFLASH_BUS_SPI,
+ .bus.u_spi.cs = &MICROPY_HW_SPIFLASH_CS,
+ .bus.u_spi.data = (void*)&soft_spi_bus,
+ .bus.u_spi.proto = &mp_soft_spi_proto,
+};
+
+spi_bdev_t spi_bdev;
diff --git a/ports/stm32/boards/STM32L476DISC/mpconfigboard.h b/ports/stm32/boards/STM32L476DISC/mpconfigboard.h
index 463ec9ccf..47d25f574 100644
--- a/ports/stm32/boards/STM32L476DISC/mpconfigboard.h
+++ b/ports/stm32/boards/STM32L476DISC/mpconfigboard.h
@@ -4,6 +4,7 @@ void STM32L476DISC_board_early_init(void);
#define MICROPY_HW_BOARD_NAME "L476-DISCO"
#define MICROPY_HW_MCU_NAME "STM32L476"
+#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0)
#define MICROPY_HW_HAS_SWITCH (1)
#define MICROPY_HW_HAS_FLASH (1)
#define MICROPY_HW_ENABLE_RNG (1)
@@ -17,6 +18,17 @@ void STM32L476DISC_board_early_init(void);
#define MICROPY_HW_SPIFLASH_MOSI (pin_E12)
#define MICROPY_HW_SPIFLASH_MISO (pin_E13)
+// block device config for SPI flash
+extern const struct _mp_spiflash_config_t spiflash_config;
+extern struct _spi_bdev_t spi_bdev;
+#define MICROPY_HW_BDEV_IOCTL(op, arg) ( \
+ (op) == BDEV_IOCTL_NUM_BLOCKS ? (MICROPY_HW_SPIFLASH_SIZE_BITS / 8 / FLASH_BLOCK_SIZE) : \
+ (op) == BDEV_IOCTL_INIT ? spi_bdev_ioctl(&spi_bdev, (op), (uint32_t)&spiflash_config) : \
+ spi_bdev_ioctl(&spi_bdev, (op), (arg)) \
+)
+#define MICROPY_HW_BDEV_READBLOCKS(dest, bl, n) spi_bdev_readblocks(&spi_bdev, (dest), (bl), (n))
+#define MICROPY_HW_BDEV_WRITEBLOCKS(src, bl, n) spi_bdev_writeblocks(&spi_bdev, (src), (bl), (n))
+
// MSI is used and is 4MHz
#define MICROPY_HW_CLK_PLLM (1)
#define MICROPY_HW_CLK_PLLN (40)