Support for ESP32 Quad and Octal SPI on SPI2 and SPI3
I have an ESP32S3 project that requires a high bandwidth between the MCU and an external device. The only feature blocking the use of micropython is its lack of support for ESP32's multi-line SPI (Quad and Octal). I looked over the SPI code in ports/esp32 and it looks pretty doable. I'm considering adding it and sending a PR. Before I do so, though, I'm wondering how I should expose it in a module. I think the most sensible thing would be to create a separate esp32.QSPI class (and perhaps an esp32.OctalSPI class).
I'd be interested in hearing what people think.
Thanks!
Esp32s2 changes
HW SPI did not work on esp32-s2:
MicroPython v1.15-74-gfb631644e on 2021-05-04; ESP32S2 module with ESP32S2
Type "help()" for more information.
>>> esp.osdebug(0,esp.LOG_DEBUG)
>>> from machine import SPI
>>> spi1=SPI(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: SPI(1) doesn't exist
>>> spi2=SPI(2)
E (128705) spi: spi_bus_initialize(632): invalid dma channel
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: invalid configuration
The problem is caused by different SPI_HOST aliases for CONFIG_IDF_TARGET_ESP32S2
in esp-idf/components/hal/include/hal/spi_types.h:
#define FSPI_HOST SPI2_HOST
#define HSPI_HOST SPI3_HOST
There is no VSPI_HOST so SPI(1) does not exist.
HSPI_HOST moved from SPI2 to SPI3. That's why SPI(2) tried wrong DMA channel.
MicroPython v1.15 is no longer compatible with IDF 3.x so we can avoid [HVF]SPI_HOST
aliases and use SPI[123]_HOST directly. Also from IDF 4.3 we can use SPI_DMA_CH_AUTO
instead of selecting proper channel number.
The commit "esp32-s2: set default SPI pins for GENERIC_S2 board" sets proper default pins
for SPI(1) and SPI(2). The question is if we should not change the default pin definitions
MICROPY_HW_SPI1_SCK... based on CONFIG_IDF_TARGET_ESP32S2
The last commit "esp32-s2: make GPIO 26 usable if SPIRAM is not configured"
is not related to SPI - just adds GPIO 26 if not used as SPIRAM CS