ESP-32 GPIO Matrix and Bootloader Stuff.

Fishbone
Posts: 2
Joined: Thu Aug 03, 2023 10:45 pm

ESP-32 GPIO Matrix and Bootloader Stuff.

Postby Fishbone » Thu Aug 03, 2023 11:04 pm

Hi all:
I am new to microcontrollers, so please be patient.

I was looking at some of the esp32-C3 data sheets and have some questions. The data sheets for SPI 2 (which is the general purpose SPI has FSPICLK as GPIO6 which is what I assume the “default” for my SPI clock (SCK). FSPIHD (MOSI) is GPIO 4. However when running the following code:

Code: Select all

Serial.begin(115200);
  Serial.print("MOSI: ");
  Serial.println(MOSI);
  Serial.print("MISO: ");
  Serial.println(MISO);
  Serial.print("SCK: ");
  Serial.println(SCK);
  Serial.print("SS: ");
  Serial.println(SS);  
I get the following output:

— Terminal on COM4 | 115200 8-N-1
— Available filters and text transformations: colorize,
debug, default, direct, esp32_exception_decoder, hexlify,
log2file, nocontrol, printable, send_on_enter, time
— More details at Redirecting...
— Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0x3 (RTC_SW_SYS_RST),boot:0xd (SPI_FAST_FLASH_BOOT)
Saved PC:0x2000082c
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5810,len:0x438
load:0x403cc710,len:0x91c
load:0x403ce710,len:0x25b0
entry 0x403cc710
MOSI: 4
MISO: 3
SCK: 2
SS: 5

MOSI is where I would expect (GPIO 4 ) but SCK is GPIO 2.

I understand the gpio peripheral pins for general purpose SPI can be reconfigured but I always thought that the default values were considered the “hardware” SPI and if I reconfigure the GPIO matrix - that is considered software SPI and it is slower. I do recall at one point trying to change my SPI settings via commands in the SPI.h library but it really slowed down the frames per second (I am using an SPI oled display).

However, maybe remapping the pins via the GPIO matrix/IOMUX pins is o.k.? So the question is: How did my SCK pin get mapped to GPIO2? Is it “firmware” for my board i.e. this in my output:

ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0x3 (RTC_SW_SYS_RST),boot:0xd (SPI_FAST_FLASH_BOOT)
Saved PC:0x2000082c
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5810,len:0x438
load:0x403cc710,len:0x91c
load:0x403ce710,len:0x25b0
entry 0x403cc710

I am not familiar with bootloaders - but could it be that commands in my board's bootloader is changing the default GPIO mappings?
If so, how would I be able to look at my board's bootloader? (I am using a Lolin esp32-C3 pico). Also...how can I change the GPIO matrix mappings? That would REALLY be good to know.

Thank you if you stuck with me this far!
Fish

Fish

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP-32 GPIO Matrix and Bootloader Stuff.

Postby ESP_Sprite » Fri Aug 04, 2023 3:29 am

Fwiw, those pins are the defaults that Arduino sets; it's unrelated to the hardware. I can't tell you why those are the Arduino defaults, however.

MicroController
Posts: 1735
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP-32 GPIO Matrix and Bootloader Stuff.

Postby MicroController » Fri Aug 04, 2023 1:28 pm

I always thought that the default values were considered the “hardware” SPI and if I reconfigure the GPIO matrix - that is considered software SPI and it is slower
This is not true for the ESPs. The original Arduino microcontroller (ATmega AVR) has its periperals hardwired to its pins; if you want to use different pins, you can't use the hardware peripheral.
That's different for the ESPs: They have the GPIO matrix (hardware!) which allows you to have the hardware route peripheral signals to various pins. In most cases it makes absolutely no difference performance-wise which IO pin you route your signal to.
(AFAIK, the only exception is that the GPIO matrix hardware may not be fast enough for the highest speed signals (40MHz+ SPI).)

Who is online

Users browsing this forum: MicroController and 105 guests