Skip to content

Commit e3eed26

Browse files
committed
stm32/boards/LEGO_HUB_NO6: Change SPI flash storage to use hardware SPI.
Signed-off-by: Damien George <[email protected]>
1 parent 6936f41 commit e3eed26

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

ports/stm32/boards/LEGO_HUB_NO6/bdev.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,26 @@
2626

2727
#include "py/obj.h"
2828
#include "storage.h"
29+
#include "spi.h"
2930

3031
#define CMD_EXIT_4_BYTE_ADDRESS_MODE (0xE9)
3132

32-
STATIC const mp_soft_spi_obj_t soft_spi_bus = {
33-
.delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY,
33+
STATIC const spi_proto_cfg_t spi_bus = {
34+
.spi = &spi_obj[1], // SPI2 hardware peripheral
35+
.baudrate = 25000000,
3436
.polarity = 0,
3537
.phase = 0,
36-
.sck = MICROPY_HW_SPIFLASH_SCK,
37-
.mosi = MICROPY_HW_SPIFLASH_MOSI,
38-
.miso = MICROPY_HW_SPIFLASH_MISO,
38+
.bits = 8,
39+
.firstbit = SPI_FIRSTBIT_MSB,
3940
};
4041

4142
STATIC mp_spiflash_cache_t spi_bdev_cache;
4243

4344
const mp_spiflash_config_t spiflash_config = {
4445
.bus_kind = MP_SPIFLASH_BUS_SPI,
45-
.bus.u_spi.cs = MICROPY_HW_SPIFLASH_NSS,
46-
.bus.u_spi.data = (void *)&soft_spi_bus,
47-
.bus.u_spi.proto = &mp_soft_spi_proto,
46+
.bus.u_spi.cs = MICROPY_HW_SPIFLASH_CS,
47+
.bus.u_spi.data = (void *)&spi_bus,
48+
.bus.u_spi.proto = &spi_proto,
4849
.cache = &spi_bdev_cache,
4950
};
5051

@@ -55,9 +56,9 @@ int32_t board_bdev_ioctl(void) {
5556

5657
// Exit 4-byte address mode
5758
uint8_t cmd = CMD_EXIT_4_BYTE_ADDRESS_MODE;
58-
mp_hal_pin_write(MICROPY_HW_SPIFLASH_NSS, 0);
59-
mp_soft_spi_proto.transfer(MP_OBJ_FROM_PTR(&soft_spi_bus), 1, &cmd, NULL);
60-
mp_hal_pin_write(MICROPY_HW_SPIFLASH_NSS, 1);
59+
mp_hal_pin_write(MICROPY_HW_SPIFLASH_CS, 0);
60+
spi_proto.transfer(MP_OBJ_FROM_PTR(&spi_bus), 1, &cmd, NULL);
61+
mp_hal_pin_write(MICROPY_HW_SPIFLASH_CS, 1);
6162

6263
return ret;
6364
}

ports/stm32/boards/LEGO_HUB_NO6/mpconfigboard.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
#define MICROPY_HW_SPI1_SCK (pin_A5) // shared with DAC
6262
#define MICROPY_HW_SPI1_MISO (pin_A6)
6363
#define MICROPY_HW_SPI1_MOSI (pin_A7)
64+
#define MICROPY_HW_SPI2_NSS (pin_B12)
65+
#define MICROPY_HW_SPI2_SCK (pin_B13)
66+
#define MICROPY_HW_SPI2_MISO (pin_C2)
67+
#define MICROPY_HW_SPI2_MOSI (pin_C3)
6468

6569
// USB config
6670
#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9)
@@ -76,10 +80,10 @@
7680
// SPI flash, for R/W storage
7781
#define MICROPY_HW_SPIFLASH_ENABLE_CACHE (1)
7882
#define MICROPY_HW_SPIFLASH_SIZE_BITS (256 * 1024 * 1024)
79-
#define MICROPY_HW_SPIFLASH_NSS (pin_B12)
80-
#define MICROPY_HW_SPIFLASH_SCK (pin_B13)
81-
#define MICROPY_HW_SPIFLASH_MISO (pin_C2)
82-
#define MICROPY_HW_SPIFLASH_MOSI (pin_C3)
83+
#define MICROPY_HW_SPIFLASH_CS (MICROPY_HW_SPI2_NSS)
84+
#define MICROPY_HW_SPIFLASH_SCK (MICROPY_HW_SPI2_SCK)
85+
#define MICROPY_HW_SPIFLASH_MISO (MICROPY_HW_SPI2_MISO)
86+
#define MICROPY_HW_SPIFLASH_MOSI (MICROPY_HW_SPI2_MOSI)
8387

8488
// SPI flash, block device config
8589
extern int32_t board_bdev_ioctl(void);

0 commit comments

Comments
 (0)