Mismatch Between SPI2_HOST and REG_SPI_BASE Macro Causes Hardware SPI Crash on ESP32-C3 #10908
Closed
1 task done
Labels
Status: Awaiting triage
Issue is waiting for triage
Board
Custom board based on ESP32-C3
Device Description
A custom-designed board using the ESP32-C3 chip.
Hardware Configuration
Version
latest master (checkout manually)
IDE Name
VSCode + PlatformIO
Operating System
Windows 11
Flash frequency
80Mhz
PSRAM enabled
no
Upload speed
115200
Description
I encountered a crash when using the TFT_eSPI library with hardware SPI on my custom ESP32-C3 board. The issue stems from a mismatch between the
SPI2_HOST
enumeration value in the HAL headers and theREG_SPI_BASE
macro insoc.h
. Specifically:In
.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32c3\include\hal\include\hal\spi_types.h
:Here,
SPI2_HOST
is defined as1
.In
.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32c3\include\soc\esp32c3\include\soc\soc.h
, theREG_SPI_BASE
macro is defined as:The macro checks for
i == 2
, which does not align with the value ofSPI2_HOST
(1). As a result, the base address for SPI2 is incorrectly resolved to0x00000000
, causing invalid memory access.During initialization of the TFT_eSPI library, the
SPI_BUSY_CHECK
macro dereferences_spi_cmd
, which points toSPI_CMD_REG(SPI_PORT)
. SinceREG_SPI_BASE(SPI_PORT)
evaluates to0x00000000
,_spi_cmd
becomes a null pointer, leading to a crash.Expected Behavior
REG_SPI_BASE(SPI2_HOST)
should return the correct base address (0x60024000
) for SPI2 on ESP32-C3 devices.Observed Behavior
REG_SPI_BASE(SPI2_HOST)
returns0x00000000
, causing invalid memory access during SPI register interaction.Steps to Reproduce
tft.init();
in the setup code.Additional Notes
The relevant macro is in
TFT_eSPI\Processors\TFT_eSPI_ESP32_C3.h
, whereSPI_PORT
is defined as:This sets
SPI_PORT
toSPI2_HOST
, whose value is1
. However, theREG_SPI_BASE
macro insoc.h
evaluatesi == 2
forSPI2
base address resolution, creating the mismatch.Debugging confirmed that
REG_SPI_BASE(SPI_PORT)
resolves to0x00000000
instead of the expected0x60024000
.Workaround
Manually redefine the
REG_SPI_BASE
macro in the local environment to align with the enumeration values:This resolves the issue and allows the display to initialize and function correctly.
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: