diff options
| author | Damien George <damien.p.george@gmail.com> | 2018-03-02 23:49:00 +1100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2018-03-02 23:55:45 +1100 |
| commit | 0210383da5804976d9282247d7c308664dc2e6f6 (patch) | |
| tree | 44242fe00587d2b74206b04c9d6ad13fae29c8bf | |
| parent | a0dfc386410b3a397e8643b269e352a8930b5f53 (diff) | |
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)
| -rw-r--r-- | ports/stm32/Makefile | 1 | ||||
| -rw-r--r-- | ports/stm32/spibdev.c | 27 |
2 files changed, 28 insertions, 0 deletions
diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index 854820abe..18e64899b 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 e70507b7b..4481a7a70 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) { |
