From: Tony D. <to...@to...> - 2015-10-21 06:34:04
|
Hi all, I'm running into a lot of trouble programming the flash memory of an Atmel SAMD21 chip (specifically the ATSAMD21G18A, a 256kb flash memory Cortex M0) and am curious if anyone has pointers or experience programming this chip with an STLink V2 programmer & OpenOCD. Here's a little bit about my setup: - OpenOCD version: 0.9.0 (2015-06-30-17:02) - Target: ATSAMD21G18A (same as in the Arduino Zero board), using the stock at91samXX.cfg target config - Interface: STLink V2, using the stock stlink-v2.cfg - Protocol: SWD The problem is that I can't get any of the flash memory programming functions to work. I can connect just fine to the chip, halt it, read memory, do a full chip erase (with the 'at91samd chip-erase' command), etc. However I've tried all the flash programming commands I can find and each fail in a slightly different but related way. And just to answer an obvious question, yes I've checked that any flash write protection and bootloader protection is disabled (using the 'at91samd bootloader 0' command to disable bootloader protection--the 'flash info 0' command also shows all 16 sections are not protected too). - flash write_image throws an error "Failed to erase row containing 00000000". Digging into the debug output (with -d 3) I see the problem is this: Debug: 470 272275 target.c:2288 target_write_u16(): address: 0x41004000, value: 0x0000a502 Debug: 471 272275 hla_target.c:766 adapter_write_memory(): adapter_write_memory 0x41004000 2 1 Debug: 472 272276 stlink_usb.c:399 stlink_usb_error_check(): Verify error Debug: 473 272276 target.c:2293 target_write_u16(): failed: -4 Crawling through the code a bit it looks like after issuing the erase row command to the NVMEM controller on the chip the STLink is throwing back a STLINK_JTAG_WRITE_VERIF_ERROR error. I'm kind of at a loss at this point as to what the problem could be--anyone hit this issue and have suggestions? - load_image executes but silently fails. A blank line is output, but examining the debug output I see it's hitting a timeout error: Debug: 513 854015 target.c:1970 target_write_buffer(): writing buffer of 6328 byte at 0x00000000 Debug: 514 854015 hla_target.c:766 adapter_write_memory(): adapter_write_memory 0x00000000 4 1582 Debug: 515 854027 stlink_usb.c:393 stlink_usb_error_check(): wait status SWD_DP_WAIT (0x10) Debug: 516 854042 stlink_usb.c:393 stlink_usb_error_check(): wait status SWD_DP_WAIT (0x10) Debug: 517 854080 stlink_usb.c:393 stlink_usb_error_check(): wait status SWD_DP_WAIT (0x10) Debug: 518 854098 stlink_usb.c:393 stlink_usb_error_check(): wait status SWD_DP_WAIT (0x10) Debug: 519 854142 stlink_usb.c:393 stlink_usb_error_check(): wait status SWD_DP_WAIT (0x10) Debug: 520 854172 stlink_usb.c:393 stlink_usb_error_check(): wait status SWD_DP_WAIT (0x10) Debug: 521 854239 stlink_usb.c:393 stlink_usb_error_check(): wait status SWD_DP_WAIT (0x10) Debug: 522 854318 stlink_usb.c:393 stlink_usb_error_check(): wait status SWD_DP_WAIT (0x10) Debug: 523 854481 stlink_usb.c:393 stlink_usb_error_check(): wait status SWD_DP_WAIT (0x10) Debug: 524 854481 command.c:628 run_command(): Command failed with error code -5 Looking at the code it looks like there's a minor bug in OpenOCD error logging here--the stlink_usb.c function stlink_usb_write_mem can fail without logging an error if it exceeds the number of retries from a ERROR_WAIT response (this code: https://github.com/ntfreak/openocd/blob/master/src/jtag/drivers/stlink_usb.c#L1509-L1514). This goes against the assumption in the comments here that commands will print out an error if they fail: https://github.com/ntfreak/openocd/blob/master/src/helper/command.c#L624-L629 This is just a minor issue though and not related to my problem--I just wanted to raise it in case anyone else has noticed commands silently failing. Back to the load_image problem it appears I'm hitting the timeout while writing to the chip. Has anyone run into this issue and have any workarounds? From looking at the code it looks like it's hardcoded to a max of 8 retries over the course of about 0.25 seconds. - Finally the program command fails with the same "Failed to erase row containing 00000000" error as flash write_image above. I assume internally the program script is just calling flash write_image so it's the same JTAG verify error. Unfortunately I'm really stumped why I can't seem to get OpenOCD to program this chip using a STLink V2 programmer. I can program the same chip just fine with a Segger J-Link and their JLink tools so it doesn't appear to be a hardware or other physical issue. I've also used this same STLink V2 to program a few other chips from Nordic, STM, etc. without issue so it should be fine. And as mentioned earlier OpenOCD can connect and control the chip just fine, it's only the flash memory writes that fail. Anyone have any pointers or idea what could be going wrong trying to flash the ATSAMD21 with the STLink? I'd really like to be able to use the STLink V2 programmer here but I'm kind of hitting a brick wall with the JTAG verify error & hard coded timeout. Also let me know if the user list isn't appropriate for this issue and if I should move it to the developer list instead. Thanks! -Tony |