From 3305ec44a2f45f9afbae029d157d49d1270cf21d Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Wed, 1 Dec 2021 18:34:39 +0100 Subject: [PATCH] esp32/machine_hw_spi: Fix SPI default pins reordering on ESP32-S2/S3. The index of machine_hw_spi_obj and machine_hw_spi_default_pins arrays is assigned to 0 for ARG_id==HSPI_HOST and 1 for another SPI. On ESP32S2 and S3 HSPI_HOST=2 so the first set (idx=0) of default pins is used for SPI(id=2) aka HSPI/SPI3 and the second set (idx=1) for SPI(id=1) aka FSPI/SPI2. This makes a misleading mess in MICROPY_HW_SPIxxxx definitions and it is also in contradiction to the comments around the definitions. Change the test of ARG_id to fix the order of machine_hw_spi_default_pins. This change might require adjusting MICROPY_HW_SPIxxxx definitions in mpconfigboard.h of S2/S3 based boards. Signed-off-by: Tomas Vanek --- ports/esp32/machine_hw_spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/esp32/machine_hw_spi.c b/ports/esp32/machine_hw_spi.c index 467bff7ccb86..27afa60afdac 100644 --- a/ports/esp32/machine_hw_spi.c +++ b/ports/esp32/machine_hw_spi.c @@ -458,7 +458,7 @@ mp_obj_t machine_hw_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_ machine_hw_spi_obj_t *self; const machine_hw_spi_default_pins_t *default_pins; - if (args[ARG_id].u_int == HSPI_HOST) { + if (args[ARG_id].u_int == 1) { // SPI2_HOST which is FSPI_HOST on ESP32Sx, HSPI_HOST on others self = &machine_hw_spi_obj[0]; default_pins = &machine_hw_spi_default_pins[0]; } else {