From e761152d723ccbc472ec4f29ebb60a1ff6d34827 Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Mon, 29 Nov 2021 16:49:11 +0100 Subject: [PATCH] esp32/machine_hw_spi: Set proper default SPI(id=2) pins on S2 and S3. Use IO_MUX pins as defined by ESP IDF in soc/esp32/include/soc/spi_pins.h ESP32S2 and S3 don't have IO_MUX pins for SPI3, GPIO matrix is always used. Choose suitable defaults for S2 and S3. ESP32C3 does not have SPI3 at all. Don't define pin mappings for it. Signed-off-by: Tomas Vanek --- ports/esp32/machine_hw_spi.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ports/esp32/machine_hw_spi.c b/ports/esp32/machine_hw_spi.c index acdabcb2a0..1515b00744 100644 --- a/ports/esp32/machine_hw_spi.c +++ b/ports/esp32/machine_hw_spi.c @@ -63,11 +63,20 @@ #endif #endif -// Default pins for SPI(2), can be overridden by a board +// Default pins for SPI(id=2) aka IDF SPI3, can be overridden by a board #ifndef MICROPY_HW_SPI2_SCK -#define MICROPY_HW_SPI2_SCK (18) -#define MICROPY_HW_SPI2_MOSI (23) -#define MICROPY_HW_SPI2_MISO (19) +#if CONFIG_IDF_TARGET_ESP32 +// ESP32 has IO_MUX pins for VSPI/SPI3 lines, use them as defaults +#define MICROPY_HW_SPI2_SCK VSPI_IOMUX_PIN_NUM_CLK // pin 18 +#define MICROPY_HW_SPI2_MOSI VSPI_IOMUX_PIN_NUM_MOSI // pin 23 +#define MICROPY_HW_SPI2_MISO VSPI_IOMUX_PIN_NUM_MISO // pin 19 +#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +// ESP32S2 and S3 uses GPIO matrix for SPI3 pins, no IO_MUX possible +// Set defaults to the pins used by SPI2 in Octal mode +#define MICROPY_HW_SPI2_SCK (36) +#define MICROPY_HW_SPI2_MOSI (35) +#define MICROPY_HW_SPI2_MISO (37) +#endif #endif #define MP_HW_SPI_MAX_XFER_BYTES (4092) @@ -108,7 +117,9 @@ typedef struct _machine_hw_spi_obj_t { // Default pin mappings for the hardware SPI instances STATIC const machine_hw_spi_default_pins_t machine_hw_spi_default_pins[2] = { { .sck = MICROPY_HW_SPI1_SCK, .mosi = MICROPY_HW_SPI1_MOSI, .miso = MICROPY_HW_SPI1_MISO }, + #ifdef MICROPY_HW_SPI2_SCK { .sck = MICROPY_HW_SPI2_SCK, .mosi = MICROPY_HW_SPI2_MOSI, .miso = MICROPY_HW_SPI2_MISO }, + #endif }; // Static objects mapping to HSPI and VSPI hardware peripherals