summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriabdalkader <i.abdalkader@gmail.com>2022-04-17 15:17:57 +0200
committerDamien George <damien@micropython.org>2022-04-20 15:37:14 +1000
commit03c61916bc4c8ccaa28210ed4b848effc2036b4e (patch)
tree91ceadddc307e9d37ec476609bf024dee831389e
parent71afed1a70d1b783d104d29878be3c44fae7cbcf (diff)
stm32/boards/ADAFRUIT_F405_EXPRESS: Use external SPI flash for storage.
Fixes issue #8553.
-rw-r--r--ports/stm32/boards/ADAFRUIT_F405_EXPRESS/bdev.c28
-rw-r--r--ports/stm32/boards/ADAFRUIT_F405_EXPRESS/mpconfigboard.h31
2 files changed, 56 insertions, 3 deletions
diff --git a/ports/stm32/boards/ADAFRUIT_F405_EXPRESS/bdev.c b/ports/stm32/boards/ADAFRUIT_F405_EXPRESS/bdev.c
new file mode 100644
index 000000000..402d5b83a
--- /dev/null
+++ b/ports/stm32/boards/ADAFRUIT_F405_EXPRESS/bdev.c
@@ -0,0 +1,28 @@
+#include "py/obj.h"
+#include "storage.h"
+#include "spi.h"
+
+#if !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
+
+STATIC const spi_proto_cfg_t spi_bus = {
+ .spi = &spi_obj[0], // SPI1
+ .baudrate = 25000000,
+ .polarity = 0,
+ .phase = 0,
+ .bits = 8,
+ .firstbit = SPI_FIRSTBIT_MSB,
+};
+
+STATIC mp_spiflash_cache_t spi_bdev_cache;
+
+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 *)&spi_bus,
+ .bus.u_spi.proto = &spi_proto,
+ .cache = &spi_bdev_cache,
+};
+
+spi_bdev_t spi_bdev;
+
+#endif
diff --git a/ports/stm32/boards/ADAFRUIT_F405_EXPRESS/mpconfigboard.h b/ports/stm32/boards/ADAFRUIT_F405_EXPRESS/mpconfigboard.h
index afa81a5ba..edf1e6c23 100644
--- a/ports/stm32/boards/ADAFRUIT_F405_EXPRESS/mpconfigboard.h
+++ b/ports/stm32/boards/ADAFRUIT_F405_EXPRESS/mpconfigboard.h
@@ -11,6 +11,7 @@
#define MICROPY_HW_ENABLE_DAC (1)
#define MICROPY_HW_ENABLE_USB (1)
#define MICROPY_HW_ENABLE_SDCARD (1)
+#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0)
// HSE is 12MHz
#define MICROPY_HW_CLK_PLLM (12)
@@ -24,6 +25,30 @@
#define MICROPY_HW_RTC_USE_US (0)
#define MICROPY_HW_RTC_USE_CALOUT (1)
+// External SPI Flash config
+#if !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
+
+#define MICROPY_HW_SPIFLASH_SIZE_BITS (16 * 1024 * 1024) // 16 Mbit (2 MByte)
+
+#define MICROPY_HW_SPIFLASH_CS (MICROPY_HW_SPI1_NSS)
+#define MICROPY_HW_SPIFLASH_SCK (MICROPY_HW_SPI1_SCK)
+#define MICROPY_HW_SPIFLASH_MISO (MICROPY_HW_SPI1_MISO)
+#define MICROPY_HW_SPIFLASH_MOSI (MICROPY_HW_SPI1_MOSI)
+
+extern const struct _mp_spiflash_config_t spiflash_config;
+extern struct _spi_bdev_t spi_bdev;
+#define MICROPY_HW_SPIFLASH_ENABLE_CACHE (1)
+#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))
+#define MICROPY_HW_BDEV_SPIFLASH_EXTENDED (&spi_bdev) // for extended block protocol
+
+#endif // !MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
+
// UART config
#define MICROPY_HW_UART3_NAME "UART3" // on RX / TX
#define MICROPY_HW_UART3_TX (pin_B10) // TX
@@ -50,9 +75,9 @@
// SPI buses
#define MICROPY_HW_SPI1_NAME "SPIFLASH"
#define MICROPY_HW_SPI1_NSS (pin_A15) // FLASH CS
-#define MICROPY_HW_SPI1_SCK (pin_B3) // FLASH CLK
-#define MICROPY_HW_SPI1_MISO (pin_B4) // FLASH MISO
-#define MICROPY_HW_SPI1_MOSI (pin_B5) // FLASH MOSI
+#define MICROPY_HW_SPI1_SCK (pin_B3) // FLASH CLK
+#define MICROPY_HW_SPI1_MISO (pin_B4) // FLASH MISO
+#define MICROPY_HW_SPI1_MOSI (pin_B5) // FLASH MOSI
#define MICROPY_HW_SPI2_NAME "SPI1"
#define MICROPY_HW_SPI2_NSS (pin_B12) // SD DETECT
#define MICROPY_HW_SPI2_SCK (pin_B13) // SCK