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.
This commit is contained in:
Damien George 2018-03-10 00:55:06 +11:00
parent 626d6c9756
commit bb3359f357
2 changed files with 34 additions and 0 deletions

View File

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

View File

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