Debugging ESP32 S3 in VS Code
Debugging is much better than littering your code with print statements for lots of reasons - which I’m not going to go into here. But setting debugging up is not always straightforward.
To make things easier, I use an esp32 s3 board that had JTAG built into it. I found this article on the internet and loosely followed the instructions: How to use JTAG built-in debugger of the ESP32-S3 in PLATFORMIO.
I’m not sure whether using Zadig is required, but I did do that bit.
Also, I did the ERASE FLASH step using the following command:
1pio run --target erase
The platformio.ini file looked like this:
1[env:esp32-s3-devkitc-1]
2platform = espressif32
3board = esp32-s3-devkitc-1
4framework = arduino
5lib_deps = adafruit/Adafruit NeoPixel@^1.15.5
6
7build_type = debug
8; Ensure the USB CDC (serial) remains active on boot
9;build_flags =
10; -D ARDUINO_USB_MODE=1
11; -D ARDUINO_USB_CDC_ON_BOOT=1
12
13;upload_speed = 2000000 ;ESP32S3 USB-Serial Converter maximum 2000000bps
14;upload_port = COM5
15;upload_flags = --erase-all
16
17monitor_speed = 115200
18monitor_port = COM4
19
20;debug_tool = esp-builtin
21;debug_init_break = break setup
I used the Adafruit NeoPixel library to control the S3 multi-colour pixel. The whole main.cpp file looked like this:
1#include <Arduino.h>
2#include <Adafruit_NeoPixel.h>
3
4#define PIN_NEO_LED 48
5#define NUM_NEO_PIXELS 1
6
7Adafruit_NeoPixel strip(NUM_NEO_PIXELS, PIN_NEO_LED, NEO_GRB + NEO_KHZ800);
8
9struct Colour {
10 int red; int green; int blue;
11};
12
13Colour ColourMap[] =
14{
15 {6,0,0}, {0,6,0}, {0,0,6}, {3,3,0},
16 {3,0,3}, {0,3,3}, {2,2,2}
17};
18
19int ColourMap_NumElements = sizeof(ColourMap)/sizeof(ColourMap[0]);
20
21int loopCounter=0;
22
23void setup() {
24 // put your setup code here, to run once:
25 strip.begin();
26 strip.show();
27 Serial.begin(115200);
28}
29
30void loop() {
31 // put your main code here, to run repeatedly:
32 for (int j=0; j<ColourMap_NumElements; j++)
33 {
34 Colour c = ColourMap[j];
35 strip.setPixelColor(0, strip.Color(c.red, c.green, c.blue));
36 strip.show();
37 Serial.print(loopCounter);
38 Serial.print(" ");
39 loopCounter++;
40 delay(1000);
41 }
42}
This was all I needed - I could then set breakpoints, step through the code and inspect variables.