On ESP32-S3, native USB inteface, is it possible to debug (USB-JTAG) core0 and core1 or at least only core1?

Hi, I am trying to debug an ESP32-S3-DevKitC-1-N8R2 on the native USB connector and have failed miserably. Spent 3 full working days with GEMINI with no success. Half a day with ChatGPT today and no results too.

I do not want to resort to printf debugging.:woozy_face:

Not sure if the issue is related to PIOarduino which I am using now or that it would happen under PlatformIO too?

I had endless problems with PIOarduino, I would suggest uninstalling the extension, ensuring the PIO extension is updated, restart the PC then download and open one of my ESP32-S3 projects from here, which will build and debug for a Seeed Xiao but should be easily adaptable to any ESP32-S3.

Hi Steven,

Thanks for your recommendation and code.

To be 100% sure I understood well, you suggest getting rid of PIOarduino and go back to the latest PlatformIO plugin?

Regards,

Thomas

Hi Thomas,

I was tempted to try PIOarduino as it included an MCU I wanted to use i.e. ESP32-C6 which is not currently supported by PlatformIO. I don’t remember the details but my recollection is that I had many problems, not necessarily with the C6 environment but general bugginess and unreliability e.g. debugging would work but not every time. I formed to opinion that it is more experimental than mature. I stress this is only my opinion and I am fully supporting the project, which I’m sure is a moving target and will only get better in the future. I can’t rule out that part of the problem is the ESP32-C6 itself as being a RISC V CPU the debugging system is not as mature as the Dual-core 32-bit Tensilica Xtensa LX7 based ESP32-S3.

Another problem I had is that PIOarduino seems to take over an existing PlatformIO extension, even to the extent of changing the extension icon! So it does not seem possible to have both extensions in VSCode and switch between them as e.g. I often do between PlatformIO and Microchip’s MPLAB. The choice seems to be between a pure PlatformIO extension, or a merged PIO/PIOarduino system - messy.

But as someone who can not cope with anything less than total reliability I went back to PlatformIO. Also as an ESP32-S3 does not cost much more than an ESP32-C6 and is a much better MCU what’s the point fighting an unnecessary battle?

If you want to try PIOarduino it is possible to install VSCode as a single, or multiple, portable version, as well as a normal fully installed version; in this way you could try PIOarduino in a portable version of VSCode without messing up your normal installation.

Ask Google Gemini how to install VSCode in a portable way.

Good luck.

Steve

Hi Steven,

Thanks for the input. I will try it and will come back with the results, but it will take one or two days as I am dealing with another issue right now.

Regards

Thomas

Hi Steven,

I uninstalled VSC and then removed the “.vscode” and “.platformio” folders.

Installed VSC from scratch and installed the PlatformIO plugin.

I went to the project you linked and this is my platformio.ini file using your file as template.

[env:DEBUG]
platform = espressif32
board = esp32-s3-devkitc1-n8r2-dts
framework = arduino

; Debug build settings
build_type = debug
build_unflags = -Os
build_flags =
    -Og                              ; Optimize for debugging
    -g3                              ; Maximum debug info
    -DARDUINO_USB_CDC_ON_BOOT=1      ; Enable USB CDC
    -DDEBUG_SETUP                    ; Enable setup() breakpoint spin loop

; Debug tool configuration
debug_tool = esp-builtin
debug_speed = 5000

; Initialize debugger at setup
debug_init_break = tbreak setup

; Extra debug commands
debug_extra_cmds =
    set complaints 0
    set print pretty on
    mon reset halt

; Upload settings
upload_speed = 921600

It did not work (Spent two days trying to get some help from Gemini AI which sucks). Easily more than 100 runs with the most bizarre commands and flags changes running in circles.

The problem is that the debugger starts dumping its endless lines and halts at PC=0x40000400

But the GUI is completely lost:

  1. The CALL STACK has the message “Paused on exception” and nothing else, not even plain adresses of different stack levels (probably because it is stuck at the start of the code). At least it is consistent with the DEBUG LOG.

  2. The DEBUG toolbox is “lost in space” with the PAUSE button enabled (despite the processor being halted) having no clue the processor is stopped.

  3. The DEBUG console at the bottom is as lost as the DEBUG toolbox and will not accept any command other than an “interrupt” and only then both DEBUG toolbox and DEBUG console will be consistent with the debugger state, and the DEBUG console will accept other commands. But because we are still at the entrypoint, no source code can be highlighted.

This is the tail of the DEBUG LOG with my “interrupt” command and a final “continue” that never reaches my Setup() function.

Info : [esp32s3.cpu0] Target halted, PC=0x40000400, debug_reason=00000000
Info : [esp32s3.cpu1] Debug controller was reset.
Info : [esp32s3.cpu1] Core was reset.
[esp32s3.cpu0] Target halted, PC=0x40000400, debug_reason=00000000
[esp32s3.cpu1] Debug controller was reset.
[esp32s3.cpu1] Core was reset.
Info : [esp32s3.cpu1] Target halted, PC=0x40000400, debug_reason=00000000
[esp32s3.cpu1] Target halted, PC=0x40000400, debug_reason=00000000
PlatformIO: Initialization completed
PlatformIO: Resume the execution to debug_init_break = tbreak setup
PlatformIO: More configuration options → 

Note: automatically using hardware breakpoints for read-only addresses.
interrupt
{“token”:12,“outOfBandRecord”:
,“resultRecords”:{“resultClass”:“done”,“results”:
}}
Info : [esp32s3.cpu0] Target halted, PC=0x40041A76, debug_reason=00000000
Info : Set GDB target to ‘esp32s3.cpu0’
[esp32s3.cpu0] Target halted, PC=0x40041A76, debug_reason=00000000
Set GDB target to ‘esp32s3.cpu0’
Info : [esp32s3.cpu1] Target halted, PC=0x40043A40, debug_reason=00000000
[esp32s3.cpu1] Target halted, PC=0x40043A40, debug_reason=00000000

Program
received signal SIGINT, Interrupt.
0x40041a76 in ?? ()
continue
Continuing.
{“token”:16,“outOfBandRecord”:
,“resultRecords”:{“resultClass”:“running”,“results”:
}}

I am showing you this so you get the feedback I promised to post, when I had the time to test it and not that you try to find out the problem.

I can not believe that being the ESP32-S3 already 5 years old, I am having so much trouble getting the USB-JTAG interface working for a DEBUG session. Clearly from your experience it is not everybodies problem.

Could this be solved paying for support? I doubt it!

Thanks for your code example. I am wondering if my ESP32-S3-DevKitC-1-N8R2 might be faulty?

Frustrating as hell. I really regret having chosen ESP32-S3-WROOM for the 10 prototype boards that are already in the manufacturing process (a 6 sided PCB with more than 570 components each and a lot of money spent).

Sorry for the rant!

Hi Thomas,

If your module is 5 years old it may be the first version of the S3 and that could cause some issues.

I think you have two many possible issues, possible faulty module, PlatformIO on VSCode not working, possible code faults and even some USB cables don’t work well. Your module has 2 x USBC connectors, I assume you have the USB cable plugged into the USB port on the module and not the COM port? I suggest you diagnose it step by step i.e.

1: Do you have another newer module to try, if not buy a known good quality Xiao board from: Seeed XIAO ESP32S3 - The Pi Hut

2: The Xiao only has one USBC connector so plug it into your computer then look in Device Manager. You should see a COM port in the Ports section called USB JTAG/serial debug unit (Interface 0) COMx and also a USB JTAG/serial debug unit in the Universal Serial Bus Devices section. Both of these should dissappear when the module is unplugged. If you don’t see both these interfaces use Zadig (https://zadig.akeo.ie/) to install the correct USB drivers, again Gemini or any AI will explain the procedure.

3: Assuming you can see both interfaces then create the simplest PlatformIO project using the Xiao ESP32-S3 board and the Arduino framework.

4: INI file:

[env:seeed_xiao_esp32s3]
platform = espressif32
board = seeed_xiao_esp32s3
framework = arduino

; — Serial Upload Configuration —
upload_protocol = esptool
upload_port = COM4 ; change to your Xiao COM port
upload_speed = 921600

; — Debugging remains via Internal JTAG —
debug_tool = esp-builtin
debug_init_break = tbreak setup

5: main.cpp file:

#include <Arduino.h>

// XIAO ESP32-S3 Hardware Note: Onboard User LED is connected to GPIO21

const int ledPin = 21;

void setup() {
// Configure GPIO21 as a digital output
pinMode(ledPin, OUTPUT);
}

void loop() {
// Set GPIO21 High (LED ON)
digitalWrite(ledPin, HIGH);
delay(100); // 100ms pause

// Set GPIO21 Low (LED OFF)
digitalWrite(ledPin, LOW);
delay(100); // 100ms pause
}

6: Build the code and if no errors then upload the code and the orange LED should blink quickly

7: Set a couple of breakpoints at the two digitalWrite lines (16 and 20)

8: Press F5 to start debugging and after about 30 seconds the debugger should stop at a breakpoint. Don’t be concerned if it does not stp at SETUP or the first breakpoint as the S3 can execute lots of instructions before the debugger takes control. To fix this insert some asm(“nop”); with a breakpoint to force the debugger to stop.

9: If you can’t get it working with a “clean” installation of VSCode and PIO, a new Xiao module and the simple code above the you may have corrupted software on your computer and you might have to wipe the machine and reinstall Windows.

10: Gemini and other AIs really can be very helpful but maybe try asking your questions in a different way. One thing I find astonishing is that simply copying an error message into an AI wil often produce a detailed solution - that works!

11: Good luck and let me know how you get on.

Hi Thomas, this is further to my previous post about trying a Xiao ESP32-S3 and probably not want you want to hear, but I have tried just about every MCU and Debug method and if you want to use PlatformIO with its Arduino framework then in my opinion the best combination is an ARM MCU e.g. STM32F103C8 with a J-Link debug probe. It provides a rock solid debug experience, it’s fast to start debugging and the debug behaves how it should e.g. it stops in setup() and breakpoints just work.

Genuine J-Link probes are expensive ÂŁ80 to some hundreds but the Chinese clones work well; if you want to try one look at these links that will cost around ÂŁ10 in total:

J-Link OB = https://www.aliexpress.com/item/1005008849268813.html

STM32F103C8 = https://www.aliexpress.com/item/1005007459081585.html

I like Segger J-Link debug probes because of the great suite of supporting software described here: J-Link Software and which can be downloaded from here: SEGGER - The Embedded Experts - Downloads - J-Link / J-Trace

Unfortunately the ESP32-S3 debug using the JTAG-BUILTIN hardware is the opposite, slow to start debug, stops where it wants in your loop() and never in setup() and is very slow to move from one breakpoint to the next. The best one can say is that it works, just about, and no more. Now this could be the PlatformIO ESP32-S3 environment, or it could be the S3 itself, I have no way of knowing, but either way the debug experience in a production environment will be frustrating to say the least. Espressif would tell you to use the ESP-IDF development environment, which may well be better for debugging, but you loose all the ease and familiarity of the Arduino framework and the vast number of off-the-shelf libraries.

Another alternative that should work just as well is an STM32Fxxxxx module with an ST-LINK debug probe, of which their are many clones e.g. https://www.aliexpress.com/item/1005007096805623.html

If you need any more info let me know.

1 Like