Introduction: Arduino GDB Debug ESP32
Often you need to get to the bottom of what is happening in your Arduino code, but are restricted to constant code changes for logging, or terminal based software which can become difficult with a larger project.
In this instructable we will show you how to get setup with the hardware debugging with an ESP32 board, using the Visual Micro plugin for Visual Studio.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Get Everything Ready
Ensure you have all the hardware below and Visual Micro installed on your PC, along with the sketch you want to debug.
ESP32 based board + USB cable
Hardware Debugger + USB Cable
7 x Jumper wires
Step 2: Setting Up the Hardware
First we need to get the board and debugger wired together correctly, and it depends which ESP32 board you have and which debugger you are using, as to exactly how these wire together.
These connect using the standard JTAG interface and the generic wiring table is above, as the pin layouts often differ between the boards, and the debuggers in some cases.
In our case we are using the FT2232H Dual RS232 Adapter, which can be purchased at a very competitive price, and can be seen in the last image above wired to our ESP32 Board.
Step 3: Setting Up Additional Drivers
Some boards need additional drivers installing to allow the debugger to work correctly.
If you aren't sure then check the Debugger Support Listing on the Visual Micro Website for your Debugger / Board combination.
How to install these can be seen in the video in the next step, as well as below:
1. Install Zadig from "https://zadig.akeo.ie/"
2. Ensure Debugger is connected via USB port
3. Run Zadig as an Administrator
4. Select Options > List all devices
5. Drop down the list until you see your debugger device (in our case "Dual RS232 HS (Interface 0)")
Note - Ensure you select Interface 0 of your debugger
Step 4: Setting Up the Software
Now we can fire up Visual Studio with the Visual Micro plugin installed and get to the bottom of the problem.
First ensure you have the project loaded you want to debug, and correct Target and COM port.
Change the option on the Debugger Menu to be "Hardware"
Then select the correct debugger from the list.
Finally change the Optimisation setting to the recommended "No Optimization"
Step 5: Start Debugging
Now all we need to do is decide where we want to stop in the code to inspect what is happening.
Simply click in the left hand margin of your code, and you will see break point (red circle) appear.
Breakpoints can be adjusted once the code has been uploaded to the board if needed, but there are often a few places of interest.
Now you can Build & Upload, and start debugging by simply pressing Build > Start Debugger
The debugger will stop on the first break point, and allow you to inspect variables and step through the code to let you see what is happening line by line.
You can also use Visual Micro to upload the code to the board as a programmer, which may be useful if there is no USB > Serial link on the target board.
Then simply select the Programmer from the Programmers list, and check the "Enable Programmer" button.
Now when you Upload it will use the selected programmer instead of the standard USB COM port.
Step 6: More Information....
More about Visual Micro:
All Hardware Debuggers supported in Visual Micro
[the Visual Micro Serial Debugger supports all boards with a Serial / Software Serial interface as well - more soon]
Visual Micro Youtube Videos:
If you want to know more about JTAG debugging outside of Visual Micro: