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 |
From: Tomas V. <to...@us...> - 2015-10-21 07:18:22
|
Hi, please first check if you have up to date ST-Link firmware. And use shortest cables as possible to avoid interference problems. Feel free to post to OpendOCD-devel as you already dig into depth of the problem. Please attach full -d3 log next time. I've never tested SAMD with STLink. I'm currently working with a SAMC21 custom board so I eventually try with STLink. Tomas On 21.10.2015 8:05, Tony DiCola wrote: > 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 > > ------------------------------------------------------------------------------ > _______________________________________________ > OpenOCD-user mailing list > Ope...@li... > https://lists.sourceforge.net/lists/listinfo/openocd-user > |
From: Tony D. <to...@to...> - 2015-10-21 17:55:23
|
Hi Tomas, thanks for the advice! I just tried STLink's firmware tool and it looks like my STLink V2 was on firmware version V2J17S4 and a newer version V2J24S4 was available. I upgraded to that latest firmware V2J24S4 and wouldn't you know it everything works now! I can see the load_image command works great and responds that all the data was written: > load_image samd21_firmware.hex 6328 bytes written at address 0x00000000 downloaded 6328 bytes in 0.222035s (27.832 KiB/s) Thanks again for the advice, and FYI to anyone else using the STLink with SAMD (and maybe other SAM chips), make sure to upgrade to the latest firmware. Thanks! -Tony On Wed, Oct 21, 2015 at 12:18 AM, Tomas Vanek <to...@us...> wrote: > Hi, > > please first check if you have up to date ST-Link firmware. And use > shortest cables > as possible to avoid interference problems. > Feel free to post to OpendOCD-devel as you already dig into depth of the > problem. > Please attach full -d3 log next time. > > I've never tested SAMD with STLink. I'm currently working with a SAMC21 > custom > board so I eventually try with STLink. > > Tomas > > On 21.10.2015 8:05, Tony DiCola wrote: >> 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 >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> OpenOCD-user mailing list >> Ope...@li... >> https://lists.sourceforge.net/lists/listinfo/openocd-user >> > > > ------------------------------------------------------------------------------ > _______________________________________________ > OpenOCD-user mailing list > Ope...@li... > https://lists.sourceforge.net/lists/listinfo/openocd-user |
From: Tomas V. <to...@us...> - 2015-10-23 19:36:14
|
Hi Tony STLink V2J17 was the very version I experienced problems with PSoC4. However I don't think that even upgraded STLink is usable for SAMD. You succeeded with load_image command. It writes directly to memory and is usually used for loading to RAM. SAMD21 version A has a weird errata: *1 - Default value of MANW in NVM.CTRLB is 0. Errata reference: 13134* This can lead to spurious writes to the NVM if a data write is done through a pointer with a wrong address corresponding to NVM area. *Fix/Workaround:* Set MANW in the NVM.CTRLB to 1 at startup So it means that you can write image to a clean device with possible problem with unpadded last sector - without any use of SAMD flash driver. I tested flash write_image intended for flash operation and got same error like you: 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 Similar error is raised in erase_sector a probably in any other flash command. AFAIK the problem is in half word (16-bit) write to NVMCTRL->CTRLA register. STLink does not implement half word memory access and OpenOCD emulates is as two byte operations. Unfortunately CTRLA register comprises from key and command an have to be written atomically. If STLink writes two bytes, NVM controller sets PROGE bit in STATUS: "An invalid command and/or a bad keyword was/were written in the NVM Command register" I tested to use word (32-bit) write instead of half word and it solved the problem. However this is a dirty workaround for one (not too suitable) SWD adapter and I'm reluctant to propose it as change of SAMD driver. On the other hand we should not neglect that SAMD21 is in Arduino Zero (original with mEDBG and clones with bootloader only?) and this problem may become a FAQ. Anyway I recommend you to use other adapter than STLink for Atmel SAM MCUs. Tomas On 21.10.2015 19:24, Tony DiCola wrote: > Hi Tomas, thanks for the advice! I just tried STLink's firmware tool > and it looks like my STLink V2 was on firmware version V2J17S4 and a > newer version V2J24S4 was available. I upgraded to that latest > firmware V2J24S4 and wouldn't you know it everything works now! I can > see the load_image command works great and responds that all the data > was written: > >> load_image samd21_firmware.hex > 6328 bytes written at address 0x00000000 > downloaded 6328 bytes in 0.222035s (27.832 KiB/s) > > Thanks again for the advice, and FYI to anyone else using the STLink > with SAMD (and maybe other SAM chips), make sure to upgrade to the > latest firmware. Thanks! > > -Tony > > On Wed, Oct 21, 2015 at 12:18 AM, Tomas Vanek > <to...@us...> wrote: >> Hi, >> >> please first check if you have up to date ST-Link firmware. And use >> shortest cables >> as possible to avoid interference problems. >> Feel free to post to OpendOCD-devel as you already dig into depth of the >> problem. >> Please attach full -d3 log next time. >> >> I've never tested SAMD with STLink. I'm currently working with a SAMC21 >> custom >> board so I eventually try with STLink. >> >> Tomas >> >> On 21.10.2015 8:05, Tony DiCola wrote: >>> 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 >>> >>> ------------------------------------------------------------------------------ >>> _______________________________________________ >>> OpenOCD-user mailing list >>> Ope...@li... >>> https://lists.sourceforge.net/lists/listinfo/openocd-user >>> >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> OpenOCD-user mailing list >> Ope...@li... >> https://lists.sourceforge.net/lists/listinfo/openocd-user |
From: Paul F. <fer...@gm...> - 2015-10-23 19:46:01
|
Hey Tomas, On Fri, Oct 23, 2015 at 09:36:04PM +0200, Tomas Vanek wrote: > I tested to use word (32-bit) write instead of half word and it solved the > problem. > However this is a dirty workaround for one (not too suitable) SWD adapter and > I'm reluctant to propose it as change of SAMD driver. I personally wouldn't be against such a hack, especially if a clarifying comment is added as well. It works with the current devices and it doesn't seem likely that it might break with the newer. And if it does, we'll learn about it in no time, and the fix would be obvious. -- Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software! mailto:fer...@gm... |
From: Tomas V. <to...@us...> - 2015-10-23 20:10:44
|
Paul, if we had an "adapter quirk" bitfield and a driver was able to get a trustworthy information "halfword access is emulated" then I go along. But if the driver tests for a hla adapter, does it mean emulated halfword access? Or do you recommend just to use word write on any adapter? High half is marked as reserved, it should be ok (I checked just 3 manuals of at least 10). Tom On 23.10.2015 21:45, Paul Fertser wrote: > Hey Tomas, > > On Fri, Oct 23, 2015 at 09:36:04PM +0200, Tomas Vanek wrote: >> I tested to use word (32-bit) write instead of half word and it solved the >> problem. >> However this is a dirty workaround for one (not too suitable) SWD adapter and >> I'm reluctant to propose it as change of SAMD driver. > I personally wouldn't be against such a hack, especially if a > clarifying comment is added as well. It works with the current devices > and it doesn't seem likely that it might break with the newer. And if > it does, we'll learn about it in no time, and the fix would be > obvious. > |
From: Paul F. <fer...@gm...> - 2015-10-23 20:15:38
|
On Fri, Oct 23, 2015 at 10:10:40PM +0200, Tomas Vanek wrote: > Or do you recommend just to use word write on any adapter? High half is > marked as reserved, > it should be ok (I checked just 3 manuals of at least 10). I suggest exactly this, going with a 32-bit write on every adapter, for the reasons outlined before. -- Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software! mailto:fer...@gm... |
From: Paul F. <fer...@gm...> - 2015-10-23 20:18:18
|
On Fri, Oct 23, 2015 at 10:10:40PM +0200, Tomas Vanek wrote: > But if the driver tests for a hla adapter, does it mean emulated halfword > access? I think TI's ICDI can do honest 16-bit access, so no, that wouldn't be accurate. I wonder stlink driver should print a warning every time a 16-bit write is attempted. IMHO that would help troubleshooting. I'd also probably changed the emulation to do 32bit read, mask, 32bit write instead of what it does currently, chances are it will work for more usecases and will likely break nothing. -- Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software! mailto:fer...@gm... |
From: Tony D. <to...@to...> - 2015-10-23 20:30:25
|
Oh interesting, thanks for the tips Tomas. Yeah I actually spoke a little too soon, the load_image commands works for me but the flash write_image command still fails with the same error. I need to read your reply a little more and check out the registers you mention. I did however find a bug with the samd core and its use of the NVMEM controller cache. This section of the samd NVMEM write is trying to flip bit 18 on a 16 bit value to disable the NVMEM controller cache functionality: https://github.com/ntfreak/openocd/blob/d28ab08cfafb3ad7ff8dc539644883217e89f8c4/src/flash/nor/at91samd.c#L420-L424 Unfortunately this doesn't have the intended effect (if you enable debug output you can see it writes a 0 value to the ctrl B reg, but reading the datasheet (page 367 here http://www.atmel.com/images/atmel-42181-sam-d21_datasheet.pdf) and the cache is actually enabled. The problem I ran into is with the cache enabled a load_image command seems to miss writing the last page of the cache to flash memory. The cache is 64 bytes large and I noticed the last 56 bytes of my program memory was't being written to the flash memory. The load_image command succeeds, but running verify_image fails and notices the missing data. Kind a nasty bug to catch unfortunately since for small writes it's probably never noticed. Haven't had a chance to send a formal bug report about it yet, but I want to try patching that function to treat the ctrl B register as a 32 bit value instead of a 16 bit value like it does today. From the DS the register is 32-bits large, at least for the samd21 (but I assume all the other samd's?), so I think the whole function needs to be adjusted slightly to account for this. On Fri, Oct 23, 2015 at 1:18 PM, Paul Fertser <fer...@gm...> wrote: > On Fri, Oct 23, 2015 at 10:10:40PM +0200, Tomas Vanek wrote: >> But if the driver tests for a hla adapter, does it mean emulated halfword >> access? > > I think TI's ICDI can do honest 16-bit access, so no, that wouldn't be > accurate. > > I wonder stlink driver should print a warning every time a 16-bit > write is attempted. IMHO that would help troubleshooting. I'd also > probably changed the emulation to do 32bit read, mask, 32bit write > instead of what it does currently, chances are it will work for more > usecases and will likely break nothing. > > -- > Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software! > mailto:fer...@gm... |
From: Tomas V. <to...@us...> - 2015-10-24 03:00:16
|
Tony, sure, this is a bug. Please don't waste time by a bug report. Read HACKING file in OpenOCD root and push a patch for review. CACHEDIS bit of NVMCTRL->CTRLB disables caching during read. This is not related to your problem: last page was not written to flash just because you used load_image instead of "flash write_image" (and therefore flash command "write page" was not issued after incomplete sector write). That is exactly what I meant > So it means that you can write image to a clean device *with possible > problem** > **with unpadded last sector* - without any use of SAMD flash driver. Tomas P.S. If you cannot wait, forget load_image and try this --- a/src/flash/nor/at91samd.c +++ b/src/flash/nor/at91samd.c @@ -452,7 +452,7 @@ static int samd_issue_nvmctrl_command(struct target *target, return res; /* Issue the NVM command */ - int res_cmd = target_write_u16(target, + int res_cmd = target_write_u32(target, SAMD_NVMCTRL + SAMD_NVMCTRL_CTRLA, SAMD_NVM_CMD(cmd)); /* Try to restore configuration, regardless of NVM command write On 23.10.2015 22:30, Tony DiCola wrote: > I did however find a bug with the samd core and its use of the NVMEM > controller cache. This section of the samd NVMEM write is trying to > flip bit 18 on a 16 bit value to disable the NVMEM controller cache > functionality: https://github.com/ntfreak/openocd/blob/d28ab08cfafb3ad7ff8dc539644883217e89f8c4/src/flash/nor/at91samd.c#L420-L424 > Unfortunately this doesn't have the intended effect (if you enable > debug output you can see it writes a 0 value to the ctrl B reg, but > reading the datasheet (page 367 here > http://www.atmel.com/images/atmel-42181-sam-d21_datasheet.pdf) and the > cache is actually enabled. > > The problem I ran into is with the cache enabled a load_image command > seems to miss writing the last page of the cache to flash memory. The > cache is 64 bytes large and I noticed the last 56 bytes of my program > memory was't being written to the flash memory. The load_image > command succeeds, but running verify_image fails and notices the > missing data. Kind a nasty bug to catch unfortunately since for small > writes it's probably never noticed. > > Haven't had a chance to send a formal bug report about it yet, but I > want to try patching that function to treat the ctrl B register as a > 32 bit value instead of a 16 bit value like it does today. From the > DS the register is 32-bits large, at least for the samd21 (but I > assume all the other samd's?), so I think the whole function needs to > be adjusted slightly to account for this. > > On Fri, Oct 23, 2015 at 1:18 PM, Paul Fertser <fer...@gm...> wrote: >> On Fri, Oct 23, 2015 at 10:10:40PM +0200, Tomas Vanek wrote: >>> But if the driver tests for a hla adapter, does it mean emulated halfword >>> access? >> I think TI's ICDI can do honest 16-bit access, so no, that wouldn't be >> accurate. >> >> I wonder stlink driver should print a warning every time a 16-bit >> write is attempted. IMHO that would help troubleshooting. I'd also >> probably changed the emulation to do 32bit read, mask, 32bit write >> instead of what it does currently, chances are it will work for more >> usecases and will likely break nothing. >> >> -- >> Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software! >> mailto:fer...@gm... |
From: Tomas V. <to...@us...> - 2015-10-24 06:48:10
|
On 24.10.2015 5:00, Tomas Vanek wrote: > Tony, > > sure, this is a bug. Please don't waste time by a bug report. Read > HACKING file > in OpenOCD root and push a patch for review. Do not. Reference manual 21.6.8: Commands affecting NVM content automatically invalidate cache lines. Disabling cache is useless. Tomas |