Skip to content

Commit bb3359f

Browse files
committed
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.
1 parent 626d6c9 commit bb3359f

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "storage.h"
2+
#include "genhdr/pins.h"
3+
4+
// External SPI flash uses standard SPI interface
5+
6+
const mp_soft_spi_obj_t soft_spi_bus = {
7+
.delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY,
8+
.polarity = 0,
9+
.phase = 0,
10+
.sck = &MICROPY_HW_SPIFLASH_SCK,
11+
.mosi = &MICROPY_HW_SPIFLASH_MOSI,
12+
.miso = &MICROPY_HW_SPIFLASH_MISO,
13+
};
14+
15+
const mp_spiflash_config_t spiflash_config = {
16+
.bus_kind = MP_SPIFLASH_BUS_SPI,
17+
.bus.u_spi.cs = &MICROPY_HW_SPIFLASH_CS,
18+
.bus.u_spi.data = (void*)&soft_spi_bus,
19+
.bus.u_spi.proto = &mp_soft_spi_proto,
20+
};
21+
22+
spi_bdev_t spi_bdev;

ports/stm32/boards/STM32L476DISC/mpconfigboard.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ void STM32L476DISC_board_early_init(void);
44
#define MICROPY_HW_BOARD_NAME "L476-DISCO"
55
#define MICROPY_HW_MCU_NAME "STM32L476"
66

7+
#define MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE (0)
78
#define MICROPY_HW_HAS_SWITCH (1)
89
#define MICROPY_HW_HAS_FLASH (1)
910
#define MICROPY_HW_ENABLE_RNG (1)
@@ -17,6 +18,17 @@ void STM32L476DISC_board_early_init(void);
1718
#define MICROPY_HW_SPIFLASH_MOSI (pin_E12)
1819
#define MICROPY_HW_SPIFLASH_MISO (pin_E13)
1920

21+
// block device config for SPI flash
22+
extern const struct _mp_spiflash_config_t spiflash_config;
23+
extern struct _spi_bdev_t spi_bdev;
24+
#define MICROPY_HW_BDEV_IOCTL(op, arg) ( \
25+
(op) == BDEV_IOCTL_NUM_BLOCKS ? (MICROPY_HW_SPIFLASH_SIZE_BITS / 8 / FLASH_BLOCK_SIZE) : \
26+
(op) == BDEV_IOCTL_INIT ? spi_bdev_ioctl(&spi_bdev, (op), (uint32_t)&spiflash_config) : \
27+
spi_bdev_ioctl(&spi_bdev, (op), (arg)) \
28+
)
29+
#define MICROPY_HW_BDEV_READBLOCKS(dest, bl, n) spi_bdev_readblocks(&spi_bdev, (dest), (bl), (n))
30+
#define MICROPY_HW_BDEV_WRITEBLOCKS(src, bl, n) spi_bdev_writeblocks(&spi_bdev, (src), (bl), (n))
31+
2032
// MSI is used and is 4MHz
2133
#define MICROPY_HW_CLK_PLLM (1)
2234
#define MICROPY_HW_CLK_PLLN (40)

0 commit comments

Comments
 (0)