As the DigiX has an JTAG, I started evaluating how I can do On-Chip-Debugging over the JTAG.
So I took my FT232H cable (see:
http://digistump.com/board/index.php/topic,1127.0.html) and connected the JTAG-relevant Pins to the DigiX.
ADBUS0 D0 TCK/SK
ADBUS1 D1 TDI/DO
ADBUS2 D2 TDO/DI
ADBUS3 D3 TMS/CS
GND to GND
Second I installed OpenOCD (
http://openocd.sourceforge.net/)
I created a new interface-script in /usr/local/share/openocd/scripts/interface/FT232H.cfg
interface ftdi
#ftdi_device_desc "FT232H"
ftdi_vid_pid 0x0403 0x6014
ftdi_layout_init 0x0018 0x05fb
I had to add a udev-rule in /etc/udev/rules.d:
# FTDI FT232H
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", MODE="664", GROUP="plugdev"
Than I started the ARDUINO-IDE and compiled the Blink-Example. I checked, where the /tmp-Directory for the build was created and moved the whole content of that directory in a new generated testdirectory. For later debugging I need to copy the Blink.ino file from the Examples as well to that directory, otherwise the debugger will not find it.
I created in that new test-directory a file called openocd.cfg
source [find interface/FT232H.cfg]
source [find target/at91sam3ax_8x.cfg]
gdb_memory_map disable
than I changed into that directory and started openocd, which identified the Atmel on the DigiX-board.
Info : only one transport option; autoselect 'jtag'
adapter speed: 500 kHz
adapter_nsrst_delay: 100
jtag_ntrst_delay: 100
cortex_m reset_config sysresetreq
Info : clock speed 500 kHz
Info : JTAG tap: sam3.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
Info : sam3.cpu: hardware has 6 breakpoints, 4 watchpoints
The DigiX was running at that time the Blink-Example.
I connected via telnet to openocd: telnet localhost:4444
with the command
reset halt I was able to stop the running program, with
reset run it continued. So far, so good.
next I stopped the mcu with
reset halt and tried:
at91sam3 info which delivered the following output:
CKGR_MOR: [0x400e0420] -> 0x00000000
MOSCXTEN: 0 [0x0000] (main xtal enabled: NO)
MOSCXTBY: 0 [0x0000] (main osc bypass: NO)
MOSCRCEN: 0 [0x0000] (onchip RC-OSC enabled: NO)
MOSCRCF: 0 [0x0000] (onchip RC-OSC freq: 4 MHz)
MOSCXTST: 0 [0x0000] (startup clks, time= 0.000000 uSecs)
MOSCSEL: 0 [0x0000] (mainosc source: internal RC)
CFDEN: 0 [0x0000] (clock failure enabled: NO)
CKGR_MCFR: [0x400e0424] -> 0x00000000
MAINFRDY: 0 [0x0000] (main ready: NO)
MAINF: 0 [0x0000] (0.000 Mhz (32.768khz slowclk)
CKGR_PLLAR: [0x400e0428] -> 0x00000000
DIVA: 0 [0x0000]
MULA: 0 [0x0000]
PLLA Freq: (Disabled,mula = 0)
CKGR_UCKR: [0x400e041c] -> 0x00000000
PMC_FSMR: [0x400e0470] -> 0x00000000
PMC_FSPR: [0x400e0474] -> 0x00000000
PMC_IMR: [0x400e046c] -> 0x00000000
PMC_MCKR: [0x400e0430] -> 0x00000000
CSS: 0 [0x0000] slowclk (0.033 Mhz)
PRES: 0 [0x0000] (selected clock)
Result CPU Freq: 0.033
PMC_PCK0: [0x400e0440] -> 0x000001ff
PMC_PCK1: [0x400e0444] -> 0x000001ff
PMC_PCK2: [0x400e0448] -> 0x000001ff
PMC_PCSR: [0x400e0418] -> 0x00000000
PMC_SCSR: [0x400e0408] -> 0x00000000
PMC_SR: [0x400e0468] -> 0x00000000
CHIPID_CIDR: [0x400e0740] -> 0x285e0a60
Version: 0 [0x0000]
EPROC: 3 [0x0003] cortex-m3
NVPSIZE: 10 [0x000a] 512K bytes
NVPSIZE2: 0 [0x0000] none
SRAMSIZE: 14 [0x000e] 96K Bytes
ARCH: 133 [0x0085] ATSAM3XxE Series (144-pin version)
NVPTYP: 2 [0x0002] embedded flash memory
EXTID: 0 [0x0000] (exists: NO)
CHIPID_CIDR2: [0x400e0940] -> 0x285e0a60
Version: 0 [0x0000]
EPROC: 3 [0x0003] cortex-m3
NVPSIZE: 10 [0x000a] 512K bytes
NVPSIZE2: 0 [0x0000] none
SRAMSIZE: 14 [0x000e] 96K Bytes
ARCH: 133 [0x0085] ATSAM3XxE Series (144-pin version)
NVPTYP: 2 [0x0002] embedded flash memory
EXTID: 0 [0x0000] (exists: NO)
CHIPID_EXID: [0x400e0744] -> 0x00000000
CHIPID_EXID2: [0x400e0944] -> 0x00000000
rc-osc: 0.000 MHz
mainosc: 0.000 MHz
plla: 0.000 MHz
cpu-freq: 0.033 MHz
mclk-freq: 0.033 MHz
UniqueId: 0x53323120 0x35373136 0x31303220 0x38303079
Now I checked the gpnvw bits with:
at91sam3 gpnvmsam3-gpnvm0: 0
sam3-gpnvm1: 1
sam3-gpnvm2: 0
which showed, that the DigiX was currently booting to the firmware in the flash.
With
at91sam3 gpnvm clr 1 I cleared the bit 1, and pressed reset on the digix.
The DigiX booted now -as expected- in the SAM-BA mode, and the program was not running!
lsusb showed:
Bus 001 Device 033: ID 03eb:6124 Atmel Corp. at91sam SAMBA bootloader
Next I entered
at91sam3 gpnvm set 1 followed by
reset init and
reset runThe DigiX restarted, the Blink-Example was running, and
lsusb showed:
Bus 001 Device 004: ID 2341:003e
So far, so good. Now I wished to upload code through JTAG. I erased the FLASH of the DigiX by pressing flash and resetted the device.
Now I entered:
program Blink.cpp.elf verify reset, which brought unfortunately the following result:
JTAG tap: sam3.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00080160 msp: 0x20088000
** Programming Started **
auto erase enabled
sam3 auto-erases while programming (request ignored)
wrote 16384 bytes from file Blink.cpp.elf in 2.188816s (7.310 KiB/s)
** Programming Finished **
** Verify Started **
checksum mismatch - attempting binary compare
diff 0 address 0x0008044c. Was 0x01 instead of 0x4f
diff 1 address 0x0008044d. Was 0xf0 instead of 0xf4
diff 2 address 0x0008044e. Was 0xa2 instead of 0x40
diff 3 address 0x0008044f. Was 0xf8 instead of 0x12
....
diff 126 address 0x000804e1. Was 0x48 instead of 0x01
diff 127 address 0x000804e2. Was 0x00 instead of 0x07
More than 128 errors, the rest are not printed.
** Verify Failed **
** Resetting Target **
JTAG tap: sam3.cpu tap/device found: 0x4ba00477 (mfg: 0x23b, part: 0xba00, ver: 0x4)
shutdown command invoked
> Connection closed by foreign host.
I tried several other ways to write the program to the digiX, direct to the flash-bank, as binary-file instead of elf, however I got all the time verification errors.
After some research I found in the Atmel reference (datasheet) the following information:
49.2.1.1 Flash: Flash Programming
When writing data into the Flash memory plane (either through the EEFC, using the IAP function
or FFPI), the data may not be correctly written (i.e the data written is not the one expected).
Problem Fix/Workaround
Set the number of Wait States (WS) at 6 (FWS = 6) during the programming
Now I am currently stuck. Is that the problem, I am running in? How can I overcome it?
Has anyone else tried already, to program a DigiX or Due via JTAG?
It should be also possible to debug a program, which was loaded through SAM-BA, which makes it necessary to connect the DigiX with two connections and some more workaround in handling.
If others are interested in debugging the DUE, please add information to this thread.