Broken ESP32-C3 config/build after moving to arduino-esp32 v2.0.0-rc1

I had a working PIO config for my new ESP32-C3 module:

[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
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
build_unflags =
	-DARDUINO_ESP32_DEV
	-DARDUINO_VARIANT="esp32"
build_flags =
	-DARDUINO_ESP32C3_DEV
	-DARDUINO_VARIANT="esp32c3"
lib_deps =
	adafruit/Adafruit BusIO@^1.7.5
	adafruit/Adafruit SSD1306@^2.4.2
	adafruit/Adafruit GFX Library@^1.10.4
	paulstoffregen/Time@^1.6.0

I then updated this to try and use the new espressif/arduino-esp32 v2.0.0-rc1 release:

[env:esp32c3]
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream
platform_packages =
	framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#2.0.0-rc1

The build seemed to work, but the uploaded image didn’t. So I tried to revert back to the old version again which I knew was working. But now I get lots of these linker errors for a lot of object files:

/Users/bob/.platformio/packages/toolchain-riscv-esp/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld:
    error: /Users/bob/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32c3/lib/libpthread.a(pthread.c.obj): conflicting priv spec version (major/minor/revision).
/Users/bob/.platformio/packages/toolchain-riscv-esp/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld:
    error: /Users/bob/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32c3/lib/libpthread.a(pthread.c.obj): conflicting priv spec version (major/minor/revision).
/Users/bob/.platformio/packages/toolchain-riscv-esp/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld:
    failed to merge target specific data of file /Users/bob/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32c3/lib/libpthread.a(pthread.c.obj)

I’ve tried wiping everything (including stuff in the .platformio directory) but nothing seems to work.
I’m using CLion on a Mac. Any suggestions? I’ve probably made some stupid mistake reverting back to the original version…

Thanks!

Well you cloned master at some point and used it some time in the past, now since you’ve reinstalled it it will have pulled master again, which has now gotten much further. You can try and estimate at which date you’ve initially pulled master and then use a commit hash from Commits · espressif/arduino-esp32 · GitHub accordingly instead of master in the platformio.ini

The other possibility is to try and make it now work with latest master. My hunch is that the errors have something to do with a now new toolchain being used and all that is needed is the same update. In the manifest https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json, the toolchains are listed. In the "version": "2.0.0-rc1", section it references gcc8_4_0-esp-2021r1 as its toolchain, differing to gcc8_4_0-crosstool-ng-1.24.0-123-g64eb9ff in the 2.0.0-alpha1 version.

The MacOS download link is listed further down in the manifest as

You would need to download that, extract it somewhere on the harddrive, then in the main folder where the bin, include folder etc. is, copy the old package.json from /Users/bob/.platformio/packages/toolchain-riscv-esp/package.json in it. Then, reference the new toolchain by adapting the platform_packages expression with the path to the folder where the package.json is with the file:// protocol.

platform_packages =
	toolchain-riscv-esp@file:///User/bob/Downloads/extracted_riscv32_toolchain
	framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#master
	platformio/tool-esptoolpy @ ~1.30100

Thanks Max. Of course master has moved forward - d’oh :flushed:
As suggested, I moved the commit version to one roughly 25 days ago (f4f1c8956beeda99c376b86c7ba3eff1ba431581) and this now compiles and links ok. There have been 20 commits to master since that one, one of them is this one:

  • IDF master d93887f9f
  • PlatformIO updates for CI (#5387)
  • Update PlatformIO CI build script:
    - Switch to the latest toolchains 8.4.0 for ESP32, ESP32S2, ESP32C3
    - Use PlatformIO from master branch for better robustness
  • Update package.json for PlatformIO

I’ll take a look at your other suggestion regarding updating the toolchains

This is 100% the culprit of your compiler error messages.

So, I did as you suggested Max, and I can now do builds using either 2.0.0-rc1 or the earlier version that I used previously (and worked). Upload seems successful for both, but neither image runs properly :worried:

Here is my ini file for the original toolchain and the pinned version of arduino-esp32:

[env:esp32c3]
platform = espressif32
platform_packages =
	toolchain-riscv-esp
	framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#cbcba53
	platformio/tool-esptoolpy @ ~1.30100
framework = arduino
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
build_unflags =
	-DARDUINO_ESP32_DEV
	-DARDUINO_VARIANT="esp32"
build_flags =
	-DARDUINO_ESP32C3_DEV
	-DARDUINO_VARIANT="esp32c3"

Here are the upload logs using the old toolchain for some very basic test code:

/usr/local/bin/platformio -c clion run --target upload -e esp32c3
Processing esp32c3 (platform: espressif32; framework: arduino; board: esp32dev)

Tool Manager: Installing git+https://github.com/espressif/arduino-esp32.git#cbcba53
git version 2.26.0
Cloning into '/Users/bob/.platformio/.cache/tmp/pkg-installing-buxepb7o'...
remote: Enumerating objects: 26402, done.        
remote: Counting objects: 100% (594/594), done.        
remote: Compressing objects: 100% (324/324), done.        
remote: Total 26402 (delta 221), reused 594 (delta 221), pack-reused 25808        
Receiving objects: 100% (26402/26402), 746.70 MiB | 5.68 MiB/s, done.
Resolving deltas: 100% (16083/16083), done.
Updating files: 100% (6497/6497), done.
Updating files: 100% (1272/1272), done.
HEAD is now at cbcba53d Improve error message when ADC2 can not be used because WiFi is On
Tool Manager: framework-arduinoespressif32 @ 0.0.0+sha.cbcba53d has been installed!
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (3.3.1) > Espressif ESP32 Dev Module
HARDWARE: ESP32C3 160MHz, 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.cbcba53d 
 - tool-esptoolpy 1.30100.210531 (3.1.0) 
 - tool-mkspiffs 2.230.0 (2.30) 
 - 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 33 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio/build/esp32c3/src/main.cpp.o
Generating partitions .pio/build/esp32c3/partitions.bin
Archiving .pio/build/esp32c3/libFrameworkArduinoVariant.a
Indexing .pio/build/esp32c3/libFrameworkArduinoVariant.a
Compiling .pio/build/esp32c3/FrameworkArduino/Esp.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/FunctionalInterrupt.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/HardwareSerial.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/IPAddress.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/IPv6Address.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/MD5Builder.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/Print.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/Stream.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/StreamString.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/USB.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/USBCDC.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/WMath.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/WString.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/base64.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/cbuf.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-adc.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-bt.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-cpu.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-dac.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-gpio.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-i2c.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-ledc.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-matrix.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-misc.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-psram.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-rmt.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-sigmadelta.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-spi.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-time.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-timer.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-tinyusb.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-touch.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/esp32-hal-uart.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/libb64/cdecode.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/libb64/cencode.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/main.cpp.o
Compiling .pio/build/esp32c3/FrameworkArduino/stdlib_noniso.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/wiring_pulse.c.o
Compiling .pio/build/esp32c3/FrameworkArduino/wiring_shift.c.o
Archiving .pio/build/esp32c3/libFrameworkArduino.a
Indexing .pio/build/esp32c3/libFrameworkArduino.a
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 9392 bytes from 327680 bytes)
Flash: [=         ]   6.6% (used 206692 bytes from 3145728 bytes)
Building .pio/build/esp32c3/firmware.bin
esptool.py v3.1
Merged 1 ELF section
Configuring upload protocol...
AVAILABLE: esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Auto-detected: /dev/cu.usbserial-A50285BI
Uploading .pio/build/esp32c3/firmware.bin
esptool.py v3.1
Serial port /dev/cu.usbserial-A50285BI
Connecting....
Chip is unknown ESP32-C3 (revision 3)
Features: Wi-Fi
Crystal is 40MHz
MAC: 7c:df:a1:a4:49:7c
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Flash will be erased from 0x00000000 to 0x00004fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x00042fff...
Flash params set to 0x002f
Compressed 18864 bytes to 11763...
Writing at 0x00000000... (100 %)
Wrote 18864 bytes (11763 compressed) at 0x00000000 in 0.6 seconds (effective 255.3 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 119...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (119 compressed) at 0x00008000 in 0.1 seconds (effective 384.8 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.1 seconds (effective 588.7 kbit/s)...
Hash of data verified.
Compressed 207072 bytes to 99511...
Writing at 0x00010000... (14 %)
Writing at 0x0001a546... (28 %)
Writing at 0x000211ec... (42 %)
Writing at 0x000279b3... (57 %)
Writing at 0x0002f416... (71 %)
Writing at 0x0003a8b6... (85 %)
Writing at 0x00041fb6... (100 %)
Wrote 207072 bytes (99511 compressed) at 0x00010000 in 3.5 seconds (effective 474.1 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
 [SUCCESS] Took 176.74 seconds 

Process finished with exit code 0

When I try to run this, I get this looping output in serial:

ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x1 (POWERON),boot:0xf (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:QIO, clock div:1
load:0x3fcd6100,len:0x14b0
ets_loader.c 78 

I’m using hardware that previously worked.
I realise I may be straying in ESP32 support rather than PlatformIO support, but I know the environment worked previously so I think what I have is still a PlatformIO configuration problem. Maybe.

At https://gitter.im/espressif/arduino-esp32?at=5ed0fe022c49c45f5aad3f0a I read things about that being wrong and it must be dio.

1 Like

Interesting.
It was working previously using qio. I changed it to dio, and it prints more but the program still doesn’t run:

ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x1 (POWERON),boot:0xf (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd6100,len:0x137c
load:0x403ce000,len:0x8c0
load:0x403d0000,len:0x2924
SHA-256 comparison failed:
Calculated: 7e3ee51ec984c760a1ab62bc896f8cccf04acc25ab883634a46a416d68336a07
Expected: 501813b8f071d39ab9aaa8fc873a619c8d797cc47c19b0f957c790f96003ad55
Attempting to boot anyway...
entry 0x403ce000
I (48) boot: ESP-IDF v4.4-dev-1594-g1d7068e4b 2nd stage bootloader
I (49) boot: compile time 15:52:58
I (49) boot: chip revision: 3
I (49) boot_comm: chip revision: 3, min. bootloader chip revision: 0
I (55) boot.esp32c3: SPI Speed      : 80MHz
I (59) boot.esp32c3: SPI Mode       : DIO
I (63) boot.esp32c3: SPI Flash Size : 4MB
I (66) boot: Enabling RNG early entropy source...
I (71) boot: Partition Table:
I (73) boot: ## Label            Usage          Type ST Offset   Length
I (80) boot:  0 nvs              WiFi data        01 02 00009000 00005000
I (86) boot:  1 otadata          OTA data         01 00 0000e000 00002000
I (93) boot:  2 app0             OTA app          00 10 00010000 00300000
I (99) boot:  3 spiffs           Unknown data     01 82 00310000 000f0000
I (106) boot: End of partition table
I (109) boot_comm: chip revision: 3, min. application chip revision: 0
I (115) esp_image: segment 0: paddr=00010020 vaddr=3c020020 size=08780h ( 34688) map
I (128) esp_image: segment 1: paddr=000187a8 vaddr=3fc8a200 size=014d0h (  5328) load
I (131) esp_image: segment 2: paddr=00019c80 vaddr=40380000 size=06398h ( 25496) load
I (143) esp_image: segment 3: paddr=00020020 vaddr=42000020 size=1ea20h (125472) map
I (165) esp_image: segment 4: paddr=0003ea48 vaddr=40386398 size=03e5ch ( 15964) load
I (168) esp_image: segment 5: paddr=000428ac vaddr=50000000 size=00010h (    16) load
I (172) boot: Loaded app from partition at offset 0x10000
I (174) boot: Disabling RNG early entropy source...

It looks like the upload is uploading to 4 different partitions. I don’t remember it doing that previously…

The main application of ~200kB is flashed at 0x10000, and the bootloader also boots that partition.

so that looks okay.

I remember there being some flags for serial output switches (between USB and UART), have you tried adding those? Using the PlatformIO and the Arduino framework with the ESP32-S2-DevKitM-1 - #2 by maxgerhardt

Did you try a LED blinky code that does not need UART? Maybe the firmware does run in general, there’s just no UART output for some reason.

And when that doesn’t help, I just found that the Arduino core has a setting “CDC on boot” (CDC is USB-Serial), and it is per-default at 0.

The developers neglected to implement this macro in the PlatformIO builder scripts.

Try adding

   -DARDUINO_USB_CDC_ON_BOOT=0

in the list of build_flags…

(Or with 1 if that doesn’t work)

Do you know what also helps?

    Serial.begin(115200);

I’m so sorry Max! :flushed:

1 Like

Project code now uploaded successfully using dio mode.
I’ll give it a go using v2 RC1…

v2 RC1 also works :slight_smile:
Thanks again for all your help Max! Looking forward to when v2 is finally released so we can get it in PIO.

@basirk Hi,
would you mind providing your final (maybe, updated by now) configuration, which works correctly with a Esp32C3-DevKit board?

@iamhere2 - I’m actually using the ESP32C3-13U module from AiThinker, but I guess it shouldn’t be any different to the DevKit board.

[env]
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream
platform_packages =
	framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#2.0.0-rc2
	toolchain-riscv-esp@file:///Users/cbassett/Desktop/Projects/boost_gauge/code/riscv32-esp-elf
	platformio/tool-esptoolpy @ ~1.30100
framework = arduino
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 = dio
board_build.arduino.ldscript = esp32c3_out.ld
build_unflags =
	-DARDUINO_ESP32_DEV
	-DARDUINO_VARIANT="esp32"
build_flags =
	-DARDUINO_ESP32C3_DEV
	-DARDUINO_VARIANT="esp32c3"
build_type = debug

Hope this works for you. Hopefully arduino-esp32 v2 should be released soon and these workarounds won’t be needed.

1 Like