Let's explore whether we can implement @westfw's proposed approach (Fig-1) to achieve single-stepping on the ATmega328P running on the Arduino Uno R3, thereby avoiding the Flash erase-and-reprogram method used by the JTAG interface for single-step debugging.
Figure-1:
Sample Instructions to be single stepped:
`.org $3000`
003000 e000 START: ldi r16, 0x00
003001 b904 out ddrb, r16 ; PB0 - PB5 are inputs
003002 9a25 sbi ddrb, 5 ;pb5 = DPin-13 is output
003003 e200 ldi r16, 0b100000
003004 b905 out portb, r16 ; onboard L is On
003005 940c 3005 HERE: jmp HERE ; wait here for ever
Figure-1:
Intel-HEX File:
:020000020000FC
:0E60000000E004B9259A00E205B90C940530C1
:00000001FF
Fields of an Intel-Hex Frame:
: 0E 6000 00 00E0 04B9 259A 00E2 05B9 0C94 0530 C1
(a) (b) (c) (d) (e)------------------------------> (f)
a: Beginning of a new frame
b: Number of bytes to be transmitted in (e) (14 bytes)
c: Byte location address in flash from which the byes of (e) to be stored
d: 00 indicates there are more Intel-HEX frames to be transmitted
e: Actual data bytes in the frame (here: 0x0E = 14 bytes)
f: Check sum computed over the bytes from (b) to (e)
==> 0E + 60 + 00 + 00 + 00 + E0 + 04 + B9 + 25 + 9A + 00 + E2 + 05 + B9 + 0C + 94 + 05 + 30
==> 053F
==> (discard carries) 3F
==>(take 2's complement) C1
Figure-2:
Procedures:
1. The above sample instrucion code will be loaded into the MCU of the UNO R3 using a ROM Programmer statrting at word locaion 0x3000 (byte location: 0x6000) of the flash so that they stay far away from the application program code related to S/S (Fig-3) routine.
Fig-3: Memoy Spaces of UNO R3
2. Develop S/S Routine using IDE and upload it into UNO R3.
(1) Press RESET Button; LCD will show: 3000 - E000
(2) Press S/S Buton; LCD will show: 3001 - B904
(3) Press RESET Button; LCD will show: 3002 - 9A25
(4) Press S/S Buton; LCD will show: 3003 - E200
(5) Press RESET Button; LCD will show: 3004 - B905
(6) Press S/S Buton; LCD will show: 3005 - 940C
(7) Let us Check that onboard L has turned On.
3. Developing Sketch for S/S Routne
(1) Create sketch for the MCU to read the 16-bit content of word location 0x3000 (E000) and show it on Serial Monitor/LCD.
...in progress




