Skip to content

Bus_SPI: build the ESP32-C6 clock takeover with arduino-esp32 3.0 (ESP-IDF 5.1) - #326

Merged
lovyan03 merged 1 commit into
m5stack:developfrom
ainyan03:spi_clock_idf51
Oct 1, 2026
Merged

lovyan03 merged 1 commit into
m5stack:developfrom
ainyan03:spi_clock_idf51

Conversation

@ainyan03

@ainyan03 ainyan03 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

With arduino-esp32 3.0.x (ESP-IDF 5.1), an ESP32-C6 sketch fails to compile:

src/lgfx/v1/platforms/esp32/Bus_SPI.inl: error: 'PERIPH_RCC_ATOMIC' was not declared in this scope

The SPI clock takeover used on Arduino builds for C5 / C6 / C61 / P4 (temporarily selecting the 80 MHz GPSPI source when it gives a closer write clock) wraps its read-modify-write of the clock-source register in PERIPH_RCC_ATOMIC(), which ESP-IDF added in 5.2. C5 / C61 / P4 need arduino-esp32 3.1 or later and are not affected.

ESP-IDF 5.1 has no shared lock for that register (its own SPI driver writes the clock source without one). Where PERIPH_RCC_ATOMIC() is missing, the same block now runs inside a critical section of its own; with ESP-IDF 5.2 and later nothing changes.

Checks

  • arduino-esp32 3.0.7 / ESP32-C6: compile error before, builds after. 3.1.x C6, P4, C5 still build.
  • On two ESP32-C6 boards with an SPI display (arduino-esp32 3.0.7 and 3.1.3), with the write clock set to 27 MHz and the GPSPI source forced to XTAL beforehand: the source is XTAL before a transaction, PLL_F80M during it and XTAL again after (40 / 80 / 40 MHz), and a full-screen write reads back identical.

…P-IDF 5.1)

The SPI clock takeover (Arduino builds on C5 / C6 / C61 / P4) wraps its
read-modify-write of the clock-source register in PERIPH_RCC_ATOMIC(),
which ESP-IDF added in 5.2. arduino-esp32 3.0.x is built on ESP-IDF 5.1, so
an ESP32-C6 sketch failed to compile ("'PERIPH_RCC_ATOMIC' was not declared
in this scope"). C5 / C61 / P4 need arduino-esp32 3.1 or later and were not
affected.

ESP-IDF 5.1 has no shared lock for that register (its own SPI driver writes
the clock source without one), so where PERIPH_RCC_ATOMIC() is missing the
same block runs inside a critical section of its own.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants