From 0210383da5804976d9282247d7c308664dc2e6f6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 2 Mar 2018 23:49:00 +1100 Subject: [PATCH] stm32/spibdev: Add option to configure SPI block dev to use QSPI flash. To use QSPI (in software QSPI mode) the configuration needed is: #define MICROPY_HW_SPIFLASH_SIZE_BITS (n * 1024 * 1024) #define MICROPY_HW_SPIFLASH_CS (pin_x1) #define MICROPY_HW_SPIFLASH_SCK (pin_x2) #define MICROPY_HW_SPIFLASH_IO0 (pin_x3) #define MICROPY_HW_SPIFLASH_IO1 (pin_x4) #define MICROPY_HW_SPIFLASH_IO2 (pin_x5) #define MICROPY_HW_SPIFLASH_IO3 (pin_x6) --- ports/stm32/Makefile | 1 + ports/stm32/spibdev.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index 854820abe3..18e64899b5 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -185,6 +185,7 @@ EXTMOD_SRC_C = $(addprefix extmod/,\ ) DRIVERS_SRC_C = $(addprefix drivers/,\ + bus/softqspi.c \ memory/spiflash.c \ dht/dht.c \ ) diff --git a/ports/stm32/spibdev.c b/ports/stm32/spibdev.c index e70507b7ba..4481a7a709 100644 --- a/ports/stm32/spibdev.c +++ b/ports/stm32/spibdev.c @@ -36,6 +36,10 @@ static uint32_t flash_tick_counter_last_write; +#if defined(MICROPY_HW_SPIFLASH_MOSI) + +// External SPI flash uses standard SPI interface + STATIC const mp_machine_soft_spi_obj_t spiflash_spi_bus = { .base = {&mp_machine_soft_spi_type}, .delay_half = MICROPY_PY_MACHINE_SPI_MIN_DELAY, @@ -53,6 +57,29 @@ STATIC const mp_spiflash_config_t spiflash_config = { .bus.u_spi.proto = &mp_machine_soft_spi_p, }; +#elif defined(MICROPY_HW_SPIFLASH_IO0) + +// External SPI flash uses quad SPI interface + +#include "drivers/bus/qspi.h" + +STATIC const mp_soft_qspi_obj_t soft_qspi_bus = { + .cs = &MICROPY_HW_SPIFLASH_CS, + .clk = &MICROPY_HW_SPIFLASH_SCK, + .io0 = &MICROPY_HW_SPIFLASH_IO0, + .io1 = &MICROPY_HW_SPIFLASH_IO1, + .io2 = &MICROPY_HW_SPIFLASH_IO2, + .io3 = &MICROPY_HW_SPIFLASH_IO3, +}; + +STATIC const mp_spiflash_config_t spiflash_config = { + .bus_kind = MP_SPIFLASH_BUS_QSPI, + .bus.u_qspi.data = (void*)&soft_qspi_bus, + .bus.u_qspi.proto = &mp_soft_qspi_proto, +}; + +#endif + STATIC mp_spiflash_t spiflash; void spi_bdev_init(void) {