Need help with SPI pin assignment on ESP32xx devices in Cir

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mikew67
 
Posts: 27
Joined: Tue Mar 17, 2020 2:56 am

Need help with SPI pin assignment on ESP32xx devices in Cir

Post by mikew67 »

Gentle folks,
The SPI peripherals on ESP32 devices are more complicated than those on some other CircuitPython devices. Specifically, let's consider the ESP32-S2 Saola w/WROVER board, for which there is a CP port https://circuitpython.org/board/espress ... _1_wrover/ (Thank you very much :-). This MCU has four SPI peripherals, in three classes, the first of which is normally used for external RAM access, leaving two devices, sometimes called SPI2 and SPI3, sometimes HSPI and VSPI in the Espressif tech reference manual (849 pages; go knock yourself out :-). The situation is further complicated by the pin assignments for the two usable SPI devices, directly to some "natural" pins or to any available GPIO pin through the IOMUX, if desired. Given all of this, it's easy to see that the simple SPI device model contemplated in CP might have some unexpected wrinkles on this platform. It's not simply a matter of importing the "board" file, and using the predesignated pins, e.g., "board.MISO". In fact, the "board" object for this CP port has no pre-defined SPI pins; they're all of the form IOnn (for a numbered collection of GPIO pins and only three specially designated pins: NEOPIXEL, TX and RX.

So I've been digging through the extensive CircuitPython libraries and examples, examining code, especially anything with an "ESP32" in part of its name and been more confused than enlightened. Not sure what library goes with what, or is compatible with what else. Haven't found a succinct document that starts with the issues mentioned above and gives guidance on the easy way to setup to use the HSPI peripheral, for example, what are the "natural" direct GPIO pin numbers to use to avoid the need for the IOMUX, and what special libraries need to be loaded to accomplish this. Is there such a document?

In desperation, I've resorted to the Espressif ESP-IDF and programming in C to write a test app to test my hardware and learn the messy details of using SPI on this chip. Works fine; talks to my target device just as expected. But it took a lot of wasted time with logic probe, data scope and C hacking to work out the details, all of which I hoped to avoid.

Any guidance from the CircuitPython perspective? Can we put together a guide for ESP32xx platforms that at least lists the options and where to look for further info?

TIA

Mike

User avatar
tannewt
 
Posts: 3315
Joined: Thu Oct 06, 2016 8:48 pm

Re: Need help with SPI pin assignment on ESP32xx devices in

Post by tannewt »

Hi Mike,
CircuitPython abstracts away these differences. CircuitPython will use the IOMUX automatically if it can. Otherwise it uses the GPIO mux which allows for maximum pin flexibility at up to 40mhz (IIRC). For the vast majority of cases this is more than enough. The faster 80mhz (IIRC) capped SPI through the IOMUX is rarely needed. If you need it, then I expect one to be able to read the datasheet to find the pins and then use them directly with "microcontroller.pin" or map them to board names through the schematic or the pins.c file in CP's board folder.

The logic that does the peripheral abstraction is here: https://github.com/adafruit/circuitpyth ... #L141-L149

Generally, it's the common-hal folder in each port that does the automatic peripheral allocation based on the selected pins.

The `board` object uses pin designations on the physical board. Therefore, there are no SPI specific names because they aren't labeled on the saola.

Feel free to drop in the Adafruit Discord to ask implementation questions. https://adafru.it/discord We're happy to answer them there.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”