AI-Thinker ESP32-C3 support for Arduino frameworks

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.