On Arduino Uno, the USB-Serial adaptor controls the RESET pin of ATMega328P through the capacitor. This capacitor will absorb high frequency debug signal and we disconnect it.
Doing so will disable the auto-bootloader entry feature on Arduino. But we won't using it during debug so we can solder the pads back after debugging.
Connect the Arduino the same way as we test the Arduino.
The 5V and GND should be connected. The Reset of Arduino should be connected to A0(P1.1) of CH552. And SPI lines (SCK, MISO, MOSI) should be connected to corresponding pins on CH552.
In Arduino IDE2, Add board "Arduino 8-bit with Debug" by,
Clicking "File"->"Preferences"
Click the button on the right side of Additional boards manager URLs
In the text box, add a new row of the link in the next text box. A long URL seem breaks the layout of this page.
In board manager, search "debug" and install the board "Arduino 8-bit with Debug"
URL here:
https://raw.githubusercontent.com/DeqingSun/unoDebugTestPackage/main/package_uno_debug_index.json
Now open the code you'd like to debug. Select board "Arduino Uno with dwire-debug". The port does not matter as we are not using it.
"Verify" the code to compile it.
Click the left of the line number to add a breakpoint. Then click "Debug".
After a few seconds, the code will pause at the breakpoint. You may add othe breakpoint, view data value, modify data value, stepping, etc. Just like a regular debugger.
You may stop by click the stop button.
When you are done with debugging. You can flash the bootloader back and solder the "RESET-EN" back.
"Power cycle" the Arduino by unplug it and plug it back to your computer.
Try to burn the bootloader twice. The 1st try will fail as expect.
The 2nd try will be successful.
The entering and leaving of debug mode requires changing the fuse bit. ATmega328P only allow you to change it one in each power cycle. That is the reason why you would replug the Arduino before leaving the debug mode.
The In-System Programming (ISP) will not work in debug mode. And the CH552 has special code in such a failure and try to send command to take the ATmega328P out of debug mode. That's how the 2nd burn will be successful.
Text editor powered by tinymce.