Arduino with an AVR8 microcontroller can be debugged with debugWIRE. This is often done with a debugger from Atmel and Avr Studio.
I found the dwire-debug project which contains an opensource implementation of debugging probe and server.
On the computer side, Visual Studio Code is capable to debug ARM-based Arduino, here I will also share how to setup VScode for debugging Uno.
The dwire project can use an FT232 or CH340 as debugging probe. However, debugWIRE may require changing fuses occasionally. So I used an Attiny85 both as ISP programmer and debugger.
Components
1×
A Digispark board
Programmed as debugWIRE Probe
1×
An ATmega328p board
mini-pro or a uno with RESET-EN trace cut
The Attiny85 firmware need to disable Reset. If you don't have a high-voltage programmer, you won't be able to program it anymore.
With a bootloader, you don't need a high voltage programmer to update the firmware. However, if your bootloader got damaged or you want to change the fuse, you still need a high voltage programmer.
Before programming bootloader, use ISP programmer to set fuses correctly. I used C1 DD FE fuses. Make sure you checked SELFPRGEN.
Then you use the command-line tool in micronucleus's repo to upload the dwire-debug's firmware.
If you do it correctly, everytime you plug in the ATtiny85 board, it will appear as a Vendor-Specific Device with PID:0x0753 & VID:0x16d0. If you don't upload firmware, it will automatically become USBtinySPI with PID:0x0c9f & VID:0x1781 after 6 seconds.
After you confirm your bootloader is working, set fuse RSTDISBL with the ISP programmer.
2
Step 2, prepare dwire-debug
I did some improvement on dwire-debug and created a release here.
If you are using Mac, you can download binary, add execute permission with chmod +x dwdebug, install libusb with brew install libusb libusb-compat .
If you are using Windows, you need to use libusb-win32 driver for ATtiny85. Refer to Readme of dwire-debug repo for more info.
For other OS, try to compile the source in the release.
3
Step 3, reprogram fuse on ATmega328p
Connect all wires and USB cable. run the following command in terminal to read fuse. If the avrdude on your computer locates in a different location, change the path accordingly.