Espidf-arduino-blink example fails for ESP32S2 but not for other Chips

So I would like to compile with
platform = espressif32, framework = arduino, espidf
for the board adafruit_qtpy_esp32s2.
and I started with the often cited Espidf-arduino-blink.

Fact: Just running the example as it is on github works well for the given predefined boards (esp32dev, espea32, esp320).
But when I add the following board lines (testing various boards, I always get the same errors for the esp32s2, see below).

[env]
platform = espressif32
framework = arduino, espidf
build_flags = 
	-D CONFIG_BLINK_GPIO=2
monitor_speed = 115200

; [env:esp32dev]
; board = esp32dev

; [env:espea32]
; board = espea32

; [env:esp320]
; board = esp320


[env:adafruit_qtpy_esp32s2]
board = adafruit_qtpy_esp32s2

[env:seeed_xiao_esp32c3]
board = seeed_xiao_esp32c3

[env:adafruit_qtpy_esp32]
board = adafruit_qtpy_esp32

[env:adafruit_feather_esp32s2_tft]
board = adafruit_feather_esp32s2_tft

Result of pio run:


Environment                   Status    Duration
----------------------------  --------  ------------
adafruit_qtpy_esp32s2         FAILED    00:00:38.389
seeed_xiao_esp32c3            SUCCESS   00:03:46.079
adafruit_qtpy_esp32           SUCCESS   00:03:59.153
adafruit_feather_esp32s2_tft  FAILED    00:00:44.090

The error I get is:

src/Blink.cpp: In function 'void setup()':
src/Blink.cpp:64:5: error: 'Serial' was not declared in this scope
     Serial.begin(115200);
     ^~~~~~
src/Blink.cpp:64:5: note: suggested alternative: 'Serial1'
     Serial.begin(115200);
     ^~~~~~
     Serial1
src/Blink.cpp: In function 'void loop()':
src/Blink.cpp:70:5: error: 'Serial' was not declared in this scope
     Serial.println("Hello!");
     ^~~~~~
src/Blink.cpp:70:5: note: suggested alternative: 'Serial1'
     Serial.println("Hello!");
     ^~~~~~
     Serial1

My trials of using Serial1 (reluctantly) did not work out. Also Serial0 did not work out. It seams, the framework compiles main() instead of setup and loop.

I found no esp32s2 board which I could compile the example with. All esp32s2 end up in the same error message. All the other boards I tried compile without any error.

Any idea how to fix this is highly appreciated. best regards
Phil

Still happens for me. Sorry for bumping the thread, but it seems the example remains broken for esp32s2 for two years at least.

For ESP32S2 and ESP32S3 builds, you need to have the arduino_tinyusb component if you want to have access to the USB CDC serial port. (This is not a problem if your S2 or S3 board uses hardware UART to communicate to the PC).

https://github.com/espressif/esp32-arduino-lib-builder/tree/master/components/arduino_tinyusb

Otherwise, the Serial object of type USBCDC will simply not be created. (source, source).

Jason2866’s repo already demonstrated that two years ago how to do it in PlatformIO:

https://github.com/Jason2866/Arduino_IDF_TinyUSB

Just to prove my point: The repo

https://github.com/maxgerhardt/pio-arduinoespidf-usbserial

Takes the platformio.ini from above (+ TinyUSB activation flags for S2 environments) and the arduino_tinyusb component from Jason2866, and it compiles just fine.

========================= [SUCCESS] Took 59.50 seconds =========================
Environment                   Status    Duration
----------------------------  --------  ------------
adafruit_qtpy_esp32s2         SUCCESS   00:02:17.866
seeed_xiao_esp32c3            SUCCESS   00:00:53.469
adafruit_qtpy_esp32           SUCCESS   00:01:06.246
adafruit_feather_esp32s2_tft  SUCCESS   00:00:59.504
========================= 4 succeeded in 00:05:17.085 =========================

So… according to the source of the example, I need to place that component inside my source tree? I thought everything was included in Arduino and ESP-IDF frameworks and all that is needed are proper build flags.