Skip to content

Commit

Permalink
esp32/machine_hw_spi: Fix SPI default pins reordering on ESP32-S2/S3.
Browse files Browse the repository at this point in the history
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 <vanekt@fbl.cz>
  • Loading branch information
tom-van authored and dpgeorge committed Dec 15, 2021
1 parent f973370 commit 3305ec4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ports/esp32/machine_hw_spi.c
Expand Up @@ -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 {
Expand Down

0 comments on commit 3305ec4

Please sign in to comment.