The basic idea of debugWIRE is that the RESET line is used as a communication line between the target system (the system you want to debug) and the hardware debugger. The line is open-drain and is used in a half-duplex way. The hardware debugger sends commands and the target responds. The communication protocol is asynchronous serial communication (8 bits, no parity, one stop bit).
A debug session is initiated by sending a break condition (the line is hold low longer than a character time) to the target system. The target responds with the character ‘U’, which is used by the hardware debugger to deduce the communication speed.
The idea of using only a single line that is not used otherwise is very cool because it does not waste any of the other pins for debugging purposes (as does, e.g., the JTAG interface). It means, that two wires (signal and GND) are enough to connect the hardware debugger with the target. In practice, however, one also needs the ISP lines, as we will see below.
Using the RESET line as a communication channel means, of course, that one cannot use the RESET line to reset the MCU anymore. Furthermore, one cannot any longer use ISP programming to upload new firmware to the MCU or change the fuses of the MCU.
With respect to the debugWIRE protocol, there are three states your MCU could be in:
- The normal state in which the DWEN (debugWIRE enable) fuse is disabled. In this state, you can use ISP programming to change fuses and to upload programs. By enabling the DWEN fuse, one reaches the transitional state.
- The transitional state is the state in which the DWEN fuse is enabled. In this state, you could use ISP programming to disable the DWEN fuse again, to reach the normal state. By power-cycling (switching the target system off and on again), one reaches the debugWIRE state.
- The debugWIRE state is the state in which a hardware debugger can control the target system. If you want to return to the normal state, a particular debugWIRE command leads to the transitional state, from which one can reach the normal state using ordinary ISP programming by disabling the DWEN fuse.
If you have a hardware debugger that powers the target system, the debugger can handle all state changes (power-cycling the target system when necessary). Otherwise, you will be asked to do that, and when you are done debugging, you will have to manually request that your MCU transition to its normal state.
A final complication can arise when the electrical characteristic of the RESET line on a target board allows to reset the MCU, but high-speed communication is impossible because of a capacitive load on the RESET line. This is the case with the Arduino UNO boards. In this case it is possible to reach the debugWIRE state, but impossible to leave it.