AI-Thinker ESP32-C3 support for Arduino frameworks

I would like to change one of my Arduino projects from an Espressif8266 ESP12-E module to an AI-Thinker Espressif32 ESP32-C3F (which is meant to be pin compatible) - but I think this is not yet supported by PIO.

I have found esp32-c3-devkitm-1, but this gives the build error “This board doesn’t support arduino framework!”. Is there anything I can do to use the ESP32-C3F with the Arduino framework, or will I need to wait for support?

Thanks!

See topics

The Arduino-ESP32 core supports ESP32C3 boards in its latest beta (and bleeding-edge master) version, as indicated by the variant folder and board definition. But PlatformIO will not officially update to beta versions. However, by using a bit of platform_packages and other platformio.ini instructions, one can up an environment where it takes that latest core and uses the correct toolchain and settings for compilation.

Try and create a standard ESP32Dev project, then overwrite it with the platformio.ini below.

[env:esp32c3]
platform = espressif32
platform_packages =
	toolchain-riscv-esp
	framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#master
	platformio/tool-esptoolpy @ ~1.30100
framework = arduino
; take usual esp32dev board and modify meta-info
; to make it a ESP32C3 board.
board = esp32dev
board_build.mcu = esp32c3
board_build.partitions = huge_app.csv
board_build.variant = esp32c3
board_build.f_cpu = 160000000L
board_build.f_flash = 80000000L
board_build.flash_mode = qio
board_build.arduino.ldscript = esp32c3_out.ld
; remove old build flags
build_unflags =
  -DARDUINO_ESP32_DEV
  -DARDUINO_VARIANT="esp32"
; inject new ones 
; uncommont Serial macro below if serial is not working..
build_flags =
  -DARDUINO_ESP32C3_DEV
  -DARDUINO_VARIANT="esp32c3"
;  -DARDUINO_SERIAL_PORT=1
;  -DBOARD_HAS_PSRAM
; -DCORE_DEBUG_LEVEL=5

Using an empty sketch as test, I get a successfull compilation.

Processing esp32c3 (platform: espressif32; framework: arduino; board: esp32dev)
-----------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (3.3.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32C3 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 0.0.0+sha.a618fc1
 - tool-esptoolpy 1.30100.210531 (3.1.0)
 - toolchain-riscv-esp 1.80400.0 (8.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 30 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\esp32c3\src\main.cpp.o
Linking .pio\build\esp32c3\firmware.elf
Retrieving maximum program size .pio\build\esp32c3\firmware.elf
Checking size .pio\build\esp32c3\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   2.9% (used 9432 bytes from 327680 bytes)
Flash: [=         ]   6.8% (used 213474 bytes from 3145728 bytes)
Building .pio\build\esp32c3\firmware.bin
esptool.py v3.1
Merged 1 ELF section
==================== [SUCCESS] Took 4.99 seconds =========================

Note that you will need to have git installed for this to pull the latest version. If you’ve previously used a project where it pulls some git version of the core, delete <user home folder>/.platformio/packages/framework-arduinoespressif32* to trigger the download of a fresh version.

Many thanks Max! I’ll give that a go :+1:
I probably should have checked for build support before ordering the modules from China…
Hopefully we’ll see a full release of the Arduino-ESP32 core soon.

@maxgerhardt That’s got me further, thanks!

Unfortunately I’m now getting these compilation errors. Looks like there’s some missing definitions in ESP32 that the SSD1306/BusIO libraries require.

Compiling .pio/build/esp32c3/lib3c1/Adafruit SSD1306/Adafruit_SSD1306.cpp.o
In file included from .pio/libdeps/esp32c3/Adafruit BusIO/Adafruit_SPIDevice.cpp:2:
.pio/libdeps/esp32c3/Adafruit BusIO/Adafruit_SPIDevice.cpp: In constructor 'Adafruit_SPIDevice::Adafruit_SPIDevice(int8_t, int8_t, int8_t, int8_t, uint32_t, BitOrder, uint8_t)':

/Users/cbassett/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:106:66: error: 'GPIO_OUT1_REG' was not declared in this scope
 #define portOutputRegister(port)    ((volatile uint32_t*)((port)?GPIO_OUT1_REG:GPIO_OUT_REG))

/Users/cbassett/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h:107:66: error: 'GPIO_IN1_REG' was not declared in this scope
 #define portInputRegister(port)     ((volatile uint32_t*)((port)?GPIO_IN1_REG:GPIO_IN_REG))

I’ll try to have a dig in the ESP8266 stuff to see how it’s defined there. Any advice welcome though :slight_smile:

The core code is weird. When I do a search on GPIO_OUT1_REG I get only two results – in Arduino.h using it, and in tools/sdk/esp32s2/include/soc/esp32s2/include/soc/gpio_reg.h defining it. So it seems like this register is only defined for ESP32S2 chips, and not for anything else – how it is still being used unconditionally then in the portOutputRegister (and analog in portInputRegister) seems very weird to me. In any case, you can stop the Adafruit library from using the faster output/input registers by commenting this line

within .pio/libdeps/esp32c3/Adafruit BusIO/Adafruit_SPIDevice.h.

I’ll see if I can open a core issue about that.

What a star Max! Thank you very much! :+1:

Issue is open in Core attempts to use GPIO_OUT1_REG and GPIO_IN1_REG on chips that don't have it · Issue #5378 · espressif/arduino-esp32 · GitHub.