Introduction: GDBStub Debugging With Serial
Using GDB Stub to debug is very useful, but losing the Serial output can make things difficult from the coding and understanding perspective.
Luckily we can implement the Software Serial Library to replace the Hardware Serial port we lose when using GDBStub, and with a few code changes, we can swap between them easily.
Supplies
Visual Micro
Arduino Uno
FTDI TTL Serial Adapter
3 x Jumper Wires
Step 1: Setting Up GDB Stub
If you haven't already setup GDBStub for your code, visit our Instructable about setting up GDBStub for first use.
Once you have the library, headers and relevant init() / breakpoint() function calls to your code, you can continue with this Instructable.
Step 2: Updating Serial Code
The easiest way to achieve this is to:
- Include the Software Serial Library from vMicro > Add Library > Current Platform
- Add a #define for the Serial Object in use e.g. USE_SERIAL
- Change all references from Serial to USE_SERIAL
- Add the SoftwareSerial object with the Rx/Tx pins you wish to use
That's all that's needed, and you can switch back to Serial by changing the USE_SERIAL define now.
Step 3: Connect Additional Hardware
Now we will need to connect our USB TTL Serial adapter to the Uno, using the pins we defined in the previous step.
More information about Software Serial can be found here.
Step 4: Using Both Serial Ports in Visual Micro
As we now have our Uno on one port for debugging via Serial, and our own Software Serial interface on another COM port, we need to view both when debugging.
Open vMicro > General > Monitor Alternative, and select the USB Port for your TTL Serial Device, a new Serial Monitor Window should appear connected to this port, without changing your upload port.
Step 5: Try It Out
Ensure the correct Uno COM port is set for upload and press Start Debugging / Attach to process depending on whether the code is uploaded.
NOTE - you may need to re-open the alternative serial monitor again after debugging begins the first time. After this it will be remembered as part of your Visual Studio Window Layout.
Step 6: Learn More
Visual Micro Website: https://www.visualmicro.com/
Setting up GDB Stub Instructable: https://www.instructables.com/id/Arduino-Uno-GDB-Debugging/
AVR GDBStub in Visual Micro: https://www.visualmicro.com/page/AVR-Debugging.aspx
ESP8266 GDBStub in Visual Micro: https://www.visualmicro.com/page/ESP8266-Debugging.aspx
You Tube Channel: https://www.youtube.com/channel/UClTkQqFvHRu0VR2ni...
Comments