stm32/boards/LEGO_HUB_NO6: Change SPI flash storage to use hardware SPI.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2021-08-26 12:02:54 +10:00
parent 6936f410ab
commit e3eed26d0b
2 changed files with 20 additions and 15 deletions

View File

@ -26,25 +26,26 @@
#include "py/obj.h"
#include "storage.h"
#include "spi.h"
#define CMD_EXIT_4_BYTE_ADDRESS_MODE (0xE9)
STATIC const mp_soft_spi_obj_t soft_spi_bus = {
.delay_half = MICROPY_HW_SOFTSPI_MIN_DELAY,
STATIC const spi_proto_cfg_t spi_bus = {
.spi = &spi_obj[1], // SPI2 hardware peripheral
.baudrate = 25000000,
.polarity = 0,
.phase = 0,
.sck = MICROPY_HW_SPIFLASH_SCK,
.mosi = MICROPY_HW_SPIFLASH_MOSI,
.miso = MICROPY_HW_SPIFLASH_MISO,
.bits = 8,
.firstbit = SPI_FIRSTBIT_MSB,
};
STATIC mp_spiflash_cache_t spi_bdev_cache;
const mp_spiflash_config_t spiflash_config = {
.bus_kind = MP_SPIFLASH_BUS_SPI,
.bus.u_spi.cs = MICROPY_HW_SPIFLASH_NSS,
.bus.u_spi.data = (void *)&soft_spi_bus,
.bus.u_spi.proto = &mp_soft_spi_proto,
.bus.u_spi.cs = MICROPY_HW_SPIFLASH_CS,
.bus.u_spi.data = (void *)&spi_bus,
.bus.u_spi.proto = &spi_proto,
.cache = &spi_bdev_cache,
};
@ -55,9 +56,9 @@ int32_t board_bdev_ioctl(void) {
// Exit 4-byte address mode
uint8_t cmd = CMD_EXIT_4_BYTE_ADDRESS_MODE;
mp_hal_pin_write(MICROPY_HW_SPIFLASH_NSS, 0);
mp_soft_spi_proto.transfer(MP_OBJ_FROM_PTR(&soft_spi_bus), 1, &cmd, NULL);
mp_hal_pin_write(MICROPY_HW_SPIFLASH_NSS, 1);
mp_hal_pin_write(MICROPY_HW_SPIFLASH_CS, 0);
spi_proto.transfer(MP_OBJ_FROM_PTR(&spi_bus), 1, &cmd, NULL);
mp_hal_pin_write(MICROPY_HW_SPIFLASH_CS, 1);
return ret;
}

View File

@ -61,6 +61,10 @@
#define MICROPY_HW_SPI1_SCK (pin_A5) // shared with DAC
#define MICROPY_HW_SPI1_MISO (pin_A6)
#define MICROPY_HW_SPI1_MOSI (pin_A7)
#define MICROPY_HW_SPI2_NSS (pin_B12)
#define MICROPY_HW_SPI2_SCK (pin_B13)
#define MICROPY_HW_SPI2_MISO (pin_C2)
#define MICROPY_HW_SPI2_MOSI (pin_C3)
// USB config
#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9)
@ -76,10 +80,10 @@
// SPI flash, for R/W storage
#define MICROPY_HW_SPIFLASH_ENABLE_CACHE (1)
#define MICROPY_HW_SPIFLASH_SIZE_BITS (256 * 1024 * 1024)
#define MICROPY_HW_SPIFLASH_NSS (pin_B12)
#define MICROPY_HW_SPIFLASH_SCK (pin_B13)
#define MICROPY_HW_SPIFLASH_MISO (pin_C2)
#define MICROPY_HW_SPIFLASH_MOSI (pin_C3)
#define MICROPY_HW_SPIFLASH_CS (MICROPY_HW_SPI2_NSS)
#define MICROPY_HW_SPIFLASH_SCK (MICROPY_HW_SPI2_SCK)
#define MICROPY_HW_SPIFLASH_MISO (MICROPY_HW_SPI2_MISO)
#define MICROPY_HW_SPIFLASH_MOSI (MICROPY_HW_SPI2_MOSI)
// SPI flash, block device config
extern int32_t board_bdev_ioctl(void);