jwestmoreland:
It appears the .bin that's on github is an html file that has been converted to a .bin file -
Good catch. I checked an embarrassingly I had the wrong binary. Now I have the correct one but I'm still encountering issues with OpenOCD. It seems to be able to communicate fine but fails to write anything to flash. Here is my openocd.cfg and a log from trying to program it:
source [find interface/raspberrypi2-native.cfg]
transport select swd
set CHIPNAME at91samd21g18
source [find target/at91samdXX.cfg]
# gpio pins
bcm2835gpio_swd_nums 25 24
bcm2835gpio_trst_num 7
bcm2835gpio_srst_num 18
reset_config srst_nogate
adapter_nsrst_delay 100
adapter_nsrst_assert_width 100
init
targets
reset halt
# write bootloader
at91samd bootloader 0
program samd21_sam_ba.bin verify
at91samd bootloader 8192
reset
shutdown
BCM2835 GPIO config: tck = 11, tms = 25, tdi = 10, tdo = 9
BCM2835 GPIO nums: swclk = 11, swdio = 25
none separate
adapter speed: 400 kHz
cortex_m reset_config sysresetreq
BCM2835 GPIO nums: swclk = 25, swdio = 24
BCM2835 GPIO config: trst = 7
BCM2835 GPIO config: srst = 18
none separate
adapter_nsrst_delay: 100
adapter_nsrst_assert_width: 100
Info : BCM2835 GPIO JTAG/SWD bitbang driver
Info : JTAG and SWD modes enabled
Info : clock speed 400 kHz
Info : SWD DPIDR 0x0bc11477
Info : at91samd21g18.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : Listening on port 3333 for gdb connections
TargetName Type Endian TapName State
-- ------------------ ---------- ------ ------------------ ------------
0* at91samd21g18.cpu cortex_m little at91samd21g18.cpu halted
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0xfffffffe msp: 0xfffffffc
target halted due to debug-request, current mode: Thread
xPSR: 0xf1000000 pc: 0xfffffffe msp: 0xfffffffc
** Programming Started **
auto erase enabled
Info : SAMD MCU: SAMD21G18A (256KB Flash, 32KB RAM)
Error: SAMD: NVM programming error
Error: Failed to erase row containing 00000100
Error: SAMD: failed to erase sector 1 at 0x00000100
Error: failed erasing sectors 0 to 31
embedded:startup.tcl:480: Error: ** Programming Failed **
in procedure 'script'
at file "embedded:startup.tcl", line 63
in procedure 'program' called at file "openocd.cfg", line 29
in procedure 'program_error' called at file "embedded:startup.tcl", line 539
at file "embedded:startup.tcl", line 480
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
shutdown command invoked
Based on the logs I suspect some issue with the NVM settings. I got the NVM user row with the command "at19samd nvmuserrow". The output was the following:
NVMUSERROW: 0xFFFFFC5DD8E00007
Would anyone with a functional board mind checking to compare? As far as I can tell, the way I'm invoking OpenOCD is identical to the way in the Arduino IDE scripts. I could potentially try that Adafruit SWD debugger although I would have to order it. I'm also open to any other suggestions.
Edit: I checked my flash dump against yours, John and unfortunately the section that should contain the bootloader (0x0 all the way up to 0x48F0) is filled entirely with ones. So this pretty much confirms that the bootloader got toasted somehow.
Edit 2: I checked the memory of the board using "mdw 0x804000 2" and checked the same location in your memory dump. They appear to be the same but with the endian-ness flipped. Specifically OpenOCD reported the following:
0x00804000: d8e00007 fffffc5d
I assume whatever tool you used to dump memory flipped the bytes. So that rules out issues with the NVM. Now I'm really confused as to what could be going wrong.