Native USB debugging on ESP32 in PlatformIO without ESP-IDF toolchain? #7879
-
I have a custom ESP32-S2-based circuit board with USB-C which does not have a USB-serial converter IC like a common dev board might. On this board, USB(-) is on GPIO19, and USB(+) is on GPIO20. USB works great for powering the board and for uploading firmware. The board works well and I have access to good old-fashioned serial console via a USB-to-logic level serial interface, but it would be nice to be able to get serial out to USB along with the firmware upload (like a dev board). I’m using PlatformIO in Visual Studio Code, and writing with arduino-esp32 rather than ESP-IDF. I understand by these instructions from Espressif that when using ESP-IDF I can configure log output to go to USB CDC rather than UART, and this has been done successfully on my custom board. But I would like to be able to do this without having to switch over to ESP-IDF. I’m presuming that one of the partitions that PlatformIO is building for me is this configuration with some nice common sense defaults, but I can’t see how I might alter those defaults to do what I’m looking for. Any thoughts or pointers? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 6 replies
-
This functionality is already available. @Jason2866 could you please help with PIO instructions? |
Beta Was this translation helpful? Give feedback.
-
Use a custom boards.json for your DIY board. Like this assuming no PSRAM. Name it for example
and create as usual an env in your platformio.ini and add as board your board
Looking in the predefined boards.json will help to understand the different settings https://github.com/platformio/platform-espressif32/tree/develop/boards If your board has PSRAM add in section The needed options can be set in platformio.ini too. But i like it more to define a custom boards.json which exactly meets the boards specs. So one time done no more thinking about which settings in platformio.ini are needed when a new env is done with this board... |
Beta Was this translation helpful? Give feedback.
-
Might using My new config is essentially identical to the esp32-s2-saola-1.json that I was using before, with only that flag added. However, with the old device config everything works as expected, and with the new device config I'm unable to connect to an MQTT broker as expected... just stops there... my logging is...
...and I get nothing more than that even with this in place:
Immediately after that last log I'm running...
I'm using Again, rolling back to a plain esp32-s2-saola-1 build works perfectly. Any thoughts would be appreciated! :) |
Beta Was this translation helpful? Give feedback.
-
@papakpmartin Mhh, the mqtt issue is strange and cant explain. https://github.com/arendst/Tasmota/tree/development/lib/default/pubsubclient-2.8.13 Have seen this too:
Maybe adding this helps
Finally you can try: Modified (forked) Platformio platform-espressif32 and changed to make this settings possible in boards.json
You can try if it works for you. If yes i will provide a PR currently we use this change only for project Tasmota
|
Beta Was this translation helpful? Give feedback.
-
Well, I was able to give this a go... it was weird. It mostly did not make a difference. Same symptom of starting nicely (as long as USB was plugged in and Monitor window was open) and running until approximately the same point, then pause for about 8-10 seconds, then crash/restart the ESP. No stacktrace. My device file is basically... {
"build": {
"arduino":{
"ldscript": "esp32s2_out.ld"
},
"core": "esp32",
"extra_flags": [
"-DARDUINO_ESP32S2_DEV",
"-DARDUINO_USB_CDC_ON_BOOT=1"
],
"f_cpu": "240000000L",
"f_flash": "80000000L",
"flash_mode": "qio",
"mcu": "esp32s2",
"variant": "esp32s2"
},
"connectivity": [
"wifi"
],
"debug": {
"openocd_target": "esp32s2.cfg"
},
"frameworks": [
"arduino",
"espidf"
],
"name": "My Custom ESP32-S2",
"upload": {
"flash_size": "4MB",
"maximum_ram_size": 327680,
"maximum_size": 4194304,
"speed": 460800,
"use_1200bps_touch": true,
"wait_for_upload_port": true,
"require_upload_port": true
},
"url": "...",
"vendor": "..."
} ...and my platformio.ini contains basically... [env:my-custom-esp32s2]
; platform = espressif32
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.02.00/platform-espressif32.zip
board = my-custom-esp32s2
framework = arduino
monitor_speed = 460800
monitor_filters =
esp32_exception_decoder
log2file
lib_deps =
knolleary/PubSubClient@^2.8
; others
; build_flags =
; -DCORE_DEBUG_LEVEL=5 Oddly, with that set up once in a while it worked perfectly for a few minutes, but would eventually revert back to the same behavior. At one point I thought it was maybe xTaskCreate(
task__handleReporting,
"task__handleReporting",
25000,
NULL, // parameters
10, // priority, higher number is higher priority
&taskHandle__handleReporting
// CONFIG_ARDUINO_RUNNING_CORE // Wi-Fi tasks must run on same core and Arduino
); ...it worked. But it did not reliably work. Not sure what to say, but I wanted to at least share what happened when I tried. |
Beta Was this translation helpful? Give feedback.
-
@papakpmartin Thinking that the issue you see is caused from your sketch. We had a "funny" bug in mqtt lib which caused weird issues. |
Beta Was this translation helpful? Give feedback.
-
Well, I'm not sure what to make of this, but commenting out all of the
So essentially, all Weird. But thought I'd share as it seemed interesting. :) |
Beta Was this translation helpful? Give feedback.
-
The issue was indeed my code. Having fixed that, this USB debug logging works wonderfully. The problem was this while (!m_mqttClient.connect(mac_address.c_str(), MQTT_USER, MQTT_PASS)) {
Serial.println("MQTT: Connecting...");
Serial.print("MQTT: State: ");
Serial.println(m_mqttClient.state());
} So in brief, @Jason2866's advice above worked perfectly. |
Beta Was this translation helpful? Give feedback.
Use a custom boards.json for your DIY board. Like this assuming no PSRAM. Name it for example
esp32s2-cdc.json
Make a new folderboards
in your root folder of the project. Place your created json file there