Using the PlatformIO and the Arduino framework with the ESP32-S2-DevKitM-1

EDIT: Cross-posted GitHub issue is live here.

I purchased one of the official ESP32-S2-DevKitM-1 boards from Espressif on Amazon and am trying to figure out how to get an example project built and uploaded to my board.

As far as I know, there is no exact match for my board in the PlatformIO board library, but I think that the ESP32-S2-Saola-1 is probably the closest target available. I started trying things on my own (trying to adapt this known-good project that I’ve used with my ESP-8266 NodeMCU 1.0), only to realize I had no idea what I was doing :grin: and try to find an example project to start from. However, I haven’t found a combination of targets and projects that have built or uploaded successfully.

I was trying for a while to get the repo’s platform-espressif32/examples/espidf-arduino-wifiscan example project to work, but I kept running into issues. The Build All task seems to indicate that env:esp-wrover-kit and env:esp32dev both build correctly: But neither uploads because my part is the ESP32-S2 variant and not the regular ESP32.

`esp32dev`
> Executing task: C:\Users\neilb\.platformio\penv\Scripts\platformio.exe run --target upload --environment esp32dev <

Processing esp32dev (board: esp32dev; platform: espressif32; framework: arduino, espidf)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (3.2.1) > Espressif ESP32 Dev Module
HARDWARE: ESP32 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.d011dd7
 - framework-espidf 3.40001.200521 (4.0.1)
 - tool-cmake 3.16.4
 - tool-esptoolpy 1.30000.201119 (3.0.0)
 - tool-idf 1.0.1
 - tool-mconf 1.4060000.20190628 (406.0.0)
 - tool-mkspiffs 2.230.0 (2.30)
 - tool-ninja 1.9.0
 - toolchain-esp32ulp 1.22851.191205 (2.28.51)
 - toolchain-xtensa32 2.80400.210211 (8.4.0)
Warning! Arduino framework as an ESP-IDF component doesn't handle the `variant` field! The default `esp32` variant will be used.
Reading CMake configuration...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Retrieving maximum program size .pio\build\esp32dev\firmware.elf
Checking size .pio\build\esp32dev\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  12.1% (used 39660 bytes from 327680 bytes)
Flash: [======    ]  64.0% (used 671254 bytes from 1048576 bytes)
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: COM5
Uploading .pio\build\esp32dev\firmware.bin
esptool.py v3.0
Serial port COM5
Connecting....

A fatal error occurred: This chip is ESP32-S2 not ESP32. Wrong --chip argument?
*** [upload] Error 2
================================================================================================================ [FAILED] Took 16.34 seconds ================================================================================================================

Environment    Status    Duration
-------------  --------  ------------
esp32dev       FAILED    00:00:16.339
=========================================================================================================== 1 failed, 0 succeeded in 00:00:16.339 ===========================================================================================================
The terminal process "C:\Users\neilb\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload', '--environment', 'esp32dev'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.
`esp32dev`
> Executing task: C:\Users\neilb\.platformio\penv\Scripts\platformio.exe run --target upload --environment esp-wrover-kit <

Processing esp-wrover-kit (board: esp-wrover-kit; platform: espressif32; framework: arduino, espidf)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp-wrover-kit.html
PLATFORM: Espressif 32 (3.2.1) > Espressif ESP-WROVER-KIT
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (ftdi) On-board (ftdi) 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.d011dd7
 - framework-espidf 3.40001.200521 (4.0.1)
 - tool-cmake 3.16.4
 - tool-esptoolpy 1.30000.201119 (3.0.0)
 - tool-idf 1.0.1
 - tool-mconf 1.4060000.20190628 (406.0.0)
 - tool-mkspiffs 2.230.0 (2.30)
 - tool-ninja 1.9.0
 - toolchain-esp32ulp 1.22851.191205 (2.28.51)
 - toolchain-xtensa32 2.80400.210211 (8.4.0)
Warning! Arduino framework as an ESP-IDF component doesn't handle the `variant` field! The default `esp32` variant will be used.
Reading CMake configuration...
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Retrieving maximum program size .pio\build\esp-wrover-kit\firmware.elf
Checking size .pio\build\esp-wrover-kit\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  12.1% (used 39660 bytes from 327680 bytes)
Flash: [======    ]  64.0% (used 671254 bytes from 1048576 bytes)
Configuring upload protocol...
AVAILABLE: esp-prog, espota, esptool, ftdi, 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: COM5
Uploading .pio\build\esp-wrover-kit\firmware.bin
esptool.py v3.0
Serial port COM5
Connecting....

A fatal error occurred: This chip is ESP32-S2 not ESP32. Wrong --chip argument?
*** [upload] Error 2
================================================================================================================ [FAILED] Took 15.12 seconds ================================================================================================================

Environment     Status    Duration
--------------  --------  ------------
esp-wrover-kit  FAILED    00:00:15.118
=========================================================================================================== 1 failed, 0 succeeded in 00:00:15.118 ===========================================================================================================
The terminal process "C:\Users\neilb\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload', '--environment', 'esp-wrover-kit'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

But the ESP32-S2-Saola-1 target that I suspect is closest to what I actuall have doesn’t build either because it doesn’t support the arduino framework. Can someone please help me figure out how to use my dev board with the Arduino framework?

Have you seen Board Definition for Adafruit MagTag - #6 by denschub? The bleeding edge version has ESP32S2 support and you can configure PlatformIO to build for this variant.

Oh, cool! Yeah, I hadn’t seen that before. I’ll try that out in a minute.

Hrm. This is interesting: (I Ctrl+C’d at the end because nothing else was happening)

> Executing task: C:\Users\neilb\.platformio\penv\Scripts\platformio.exe run --target upload --target monitor <

Processing MagTag (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.2.1) > Espressif ESP32 Dev Module
HARDWARE: ESP32S2 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.5d9b98c
 - tool-esptoolpy 1.30000.201119 (3.0.0)
 - tool-mkspiffs 2.230.0 (2.30)
 - toolchain-esp32s2ulp 1.22851.191205 (2.28.51)
 - toolchain-xtensa32s2 1.80400.210211 (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...
Dependency Graph
|-- <WiFi> 1.0
Building in release mode
Retrieving maximum program size .pio\build\MagTag\firmware.elf
Checking size .pio\build\MagTag\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  11.1% (used 36280 bytes from 327680 bytes)
Flash: [==        ]  22.8% (used 717286 bytes from 3145728 bytes)
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: COM5
Uploading .pio\build\MagTag\firmware.bin
esptool.py v3.0
Serial port COM5
Connecting....
Chip is ESP32-S2FH32
Features: WiFi, Embedded 4MB Flash, 105C temp rating, ADC and temperature sensor calibration in BLK2 of efuse
Crystal is 40MHz
MAC: 7c:df:a1:30:38:20
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 12576 bytes to 8732...
Writing at 0x00001000... (100 %)
Wrote 12576 bytes (8732 compressed) at 0x00001000 in 0.2 seconds (effective 500.9 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 119...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (119 compressed) at 0x00008000 in 0.0 seconds (effective 2730.5 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 9363.9 kbit/s)...
Hash of data verified.
Compressed 717424 bytes to 478836...
Writing at 0x00010000... (3 %)
Writing at 0x00014000... (6 %)
Writing at 0x00018000... (10 %)
Writing at 0x0001c000... (13 %)
Writing at 0x00020000... (16 %)
Writing at 0x00024000... (20 %)
Writing at 0x00028000... (23 %)
Writing at 0x0002c000... (26 %)
Writing at 0x00030000... (30 %)
Writing at 0x00034000... (33 %)
Writing at 0x00038000... (36 %)
Writing at 0x0003c000... (40 %)
Writing at 0x00040000... (43 %)
Writing at 0x00044000... (46 %)
Writing at 0x00048000... (50 %)
Writing at 0x0004c000... (53 %)
Writing at 0x00050000... (56 %)
Writing at 0x00054000... (60 %)
Writing at 0x00058000... (63 %)
Writing at 0x0005c000... (66 %)
Writing at 0x00060000... (70 %)
Writing at 0x00064000... (73 %)
Writing at 0x00068000... (76 %)
Writing at 0x0006c000... (80 %)
Writing at 0x00070000... (83 %)
Writing at 0x00074000... (86 %)
Writing at 0x00078000... (90 %)
Writing at 0x0007c000... (93 %)
Writing at 0x00080000... (96 %)
Writing at 0x00084000... (100 %)
Wrote 717424 bytes (478836 compressed) at 0x00010000 in 11.7 seconds (effective 488.6 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
============================================================================================================ [SUCCESS] Took 18.98 seconds ============================================================================================================
--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at http://bit.ly/pio-monitor-filters
--- Miniterm on COM5  115200,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:2
load:0x3ffe6100,len:0x424
load:0x4004c000,len:0x844
load:0x40050000,len:0x2460
entry 0x4004c180
E (248) psram: PSRAM ID read error: 0x00ffffff

Try and remove -DBOARD_HAS_PSRAM from the platformio.ini if your board doesn’t have PSRAM, doesn’t seem to be working with your config or the core is broken.

Okay, commented that line out and uploaded. I’m not sure I understand what’s supposed to be happening now? :slight_smile: I’m fairly confused about what’s going on, lol…

> Executing task: C:\Users\neilb\.platformio\penv\Scripts\platformio.exe device monitor --environment MagTag <

--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at http://bit.ly/pio-monitor-filters
--- Miniterm on COM5  115200,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:2
load:0x3ffe6100,len:0x424
load:0x4004c000,len:0x844
load:0x40050000,len:0x2460
entry 0x4004c180

Well it definitely the first-state bootloader… Maybe it has to do with that missing TinyUF2.bin bootloader. Try and add -DCORE_DEBUG_LEVEL=5 to the build_flags toget some more verbose output.

If still nothing happens then maybe the serial output is wrongly configured (try removing DARDUINO_SERIAL_PORT=1 to get UART instead of USB-CDC?) or it really is missing the bootloader.

What sketch are you testing this with?

Will try that now. The same wifi-scanner one I mentioned in my first post.

And just for the record: what I did was I used the official Arduino IDE, enabled the “show verbose output during [] compilation [] upload” checkboxes, and compared those build commands (the calls to xtensa-esp32s2-elf-g++/xtensa-esp32-elf-g++) to the ones visible in PlatformIO’s verbose output.

You have to ignore all the include flags (-I /some/path), but other than that, they should pretty much match each other, and if they don’t, you can use the custom configs to make them match.

1 Like

Adding the debug-level flag: (a new pair of lines is printed every ~5s)

> Executing task: C:\Users\neilb\.platformio\penv\Scripts\platformio.exe device monitor <

--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at http://bit.ly/pio-monitor-filters
--- Miniterm on COM5  115200,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:2     
load:0x3ffe6100,len:0x424 
load:0x4004c000,len:0x844 
load:0x40050000,len:0x2460
entry 0x4004c180
[     0][D][esp32-hal-tinyusb.c:569] tinyusb_enable_interface(): Interface 0 enabled
[   699][D][esp32-hal-tinyusb.c:456] tinyusb_load_enabled_interfaces(): Load Done: if_num: 2, descr_len: 75, if_mask: 0x1
[   704][I][esp32-hal-tinyusb.c:75] tinyusb_driver_install(): Driver installation...
[   712][I][esp32-hal-tinyusb.c:88] tinyusb_driver_install(): Driver installed
[   881][V][WiFiGeneric.cpp:273] _arduino_event_cb(): STA Started
[   883][D][WiFiGeneric.cpp:795] _eventCallback(): Arduino Event: 2 - STA_START
[  2508][V][WiFiGeneric.cpp:307] _arduino_event_cb(): SCAN Done: ID: 128, Status: 0, Results: 7
[  2509][D][WiFiGeneric.cpp:795] _eventCallback(): Arduino Event: 1 - SCAN_DONE
[  9572][V][WiFiGeneric.cpp:307] _arduino_event_cb(): SCAN Done: ID: 129, Status: 0, Results: 10
[  9572][D][WiFiGeneric.cpp:795] _eventCallback(): Arduino Event: 1 - SCAN_DONE
[ 16665][V][WiFiGeneric.cpp:307] _arduino_event_cb(): SCAN Done: ID: 130, Status: 0, Results: 12
[ 16666][D][WiFiGeneric.cpp:795] _eventCallback(): Arduino Event: 1 - SCAN_DONE

Do you still want me to try the other thing?

I don’t quite follow what you mean, but I presume Max does :slight_smile:

Well that definitely looks like the sketch is running and it has found 12 surrounding WiFi networks, but funnily enough you don’t see the sketch output. For some strange reason the core’s debug output goes to the right serial bot not Serial.

The board you have does not have a USB-Serial converter chip right? It connects USB straight to the ESP32-S2?

Neither adding nor removing -DARDUINO_SERIAL_PORT=1 makes a difference?

OH lol! Removing -DARDUINO_SERIAL_PORT=1 from the config did actually work. (I thought I was waiting for your response on whether or not trying this was useful after the first test you suggested)

--- Available filters and text transformations: colorize, debug, default, direct, esp32_exception_decoder, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at http://bit.ly/pio-monitor-filters
--- Miniterm on COM5  115200,8,N,1 ---
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:2
load:0x3ffe6100,len:0x424
load:0x4004c000,len:0x844
load:0x40050000,len:0x2460
entry 0x4004c180
[   857][V][WiFiGeneric.cpp:273] _arduino_event_cb(): STA Started
[   859][D][WiFiGeneric.cpp:795] _eventCallback(): Arduino Event: 2 - STA_START
�[  3814][V][WiFiGeneric.cpp:307] _arduino_event_cb(): SCAN Done: ID: 128, Status: 0, Results: 11
[  3815][D][WiFiGeneric.cpp:795] _eventCallback(): Arduino Event: 1 - SCAN_DONE
scan done
11 networks found
1: [REDACTED] (-47)*
2: [REDACTED] (-55)*
3: [REDACTED] (-55)*
4: [REDACTED] (-62)*
5: [REDACTED] (-88)*
6: [REDACTED] (-88)*
7: [REDACTED] (-88)*
8: [REDACTED] (-88)*
9: [REDACTED] (-90)*
10: [REDACTED] (-91)*
11: [REDACTED] (-92)*

I’m going to try another sketch now to make sure this isn’t a fluke :slight_smile:

Yo! Thanks @maxgerhardt for you troubleshooting help and @denschub for working on this alternative target definition. As far as I can tell right now, what we have currently works for my board: :heart_eyes:

[env:MagTag]
platform = espressif32
platform_packages =
	toolchain-xtensa32s2
	framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#2.0.0-alpha1
framework = arduino

board = esp32dev
board_build.mcu = esp32s2
board_build.partitions = huge_app.csv

build_unflags =
  -DARDUINO_ESP32_DEV
  -DARDUINO_VARIANT="esp32"
build_flags =
  -DARDUINO_MAGTAG29_ESP32S2
  ; -DARDUINO_SERIAL_PORT=1
  -DARDUINO_VARIANT="adafruit_magtag29_esp32s2"
  ; -DBOARD_HAS_PSRAM
  -DCORE_DEBUG_LEVEL=5

monitor_speed = 115200
2 Likes

Although I would still be very interested in seeing a more official way to get support for this board. Is there any way we could get this merged soon?

The above is relying on 2.0.0-alpha1, and PlatformIO only supports proper release versions. Once 2.0.0 gets actually released the PlatformIO people will add the proper board definitions, framework files and other missing bits and pieces (like here or here) for proper support and it’ll work out of the box. Until then it’s all beta-stuff and custom. See my thoughts in Board Definition for Adafruit MagTag - #5 by maxgerhardt.

1 Like

Understood, thank you for the clarification. (and help!)

As far as I can tell, the espressif / arduino-esp32 repo has been changed, so that this workaround no longer works.
Does anyone know how to set it up correctly now?

The config should still work for 2.0.0-alpha1, but since master has advanced and they changed the toolchain, you need to replicate it too. This was discussed recently in Broken ESP32-C3 config/build after moving to arduino-esp32 v2.0.0-rc1 - #2 by maxgerhardt (equivalently for toolchain-xtensa32s2 for a ESP32-S2 that is, not the riscv toolchain for a ESPC3).

1 Like

Is there any documentation about what ‘missing bits’ need to get added in? Previously I was able to use release/v3.3 of the esp32-arduino-lib-builder and just do this to copy in recompiled IDF things:

cp -r out/tools/* ~/.platformio/packages/framework-arduinoespressif32/tools
cp -r out/platform.txt ~/.platformio/packages/framework-arduinoespressif32/platform.txt

But it looks like the directory structure has changed and all my attempts to copy in files in different spots don’t seem to work.