[SOLVED] Problem programming ATSAMD21G18

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • [SOLVED] Problem programming ATSAMD21G18

    Hi, I am unable to program this chip with either JLink Edu Mini, JLink Edu or on board with an Arduino Zero.

    I can program ATSAMD21J18, ATSAMD20J18 and ATSAMC21J18 (All XPro boards) without any issue but for the ATSAMD21G18 I am completely out of luck.
    I have one Arduino Zero, one Robodyn Clone with only 10pin connector and a MKRZero, they all show the same error message:

    Restarting due to program error (possibly skipped erasure of half-way erased sector).
    Skip optimizations disabled for second try.

    (Logs are attached)

    I read in another thread in the forum that USB cables may play a role with this issue so I tried five different Cables, result is always the same.
    I also tried on my Mac and on a Windows 10 PC, same result on both computers, flashing fails.

    Any help greatly appreciated,

    Michael
    Files
    • atsamd21g18.log

      (2.18 kB, downloaded 460 times, last: )
  • I also tried openocd and received the following:

    Error: SAMD: NVM lock error
    Error: Failed to erase row containing 00000000
    Error: SAMD: failed to erase sector 0 at 0x00000000
    Error: failed erasing sectors 0 to 32
    Error: flash_erase returned -4

    I think I saw comments on NVM lock here on the forum too, could this be a good hint?

    I did read out Values of NVM:
    J-Link>mem32 0x00804000 2
    00804000 = D8E0C7F9 FFFFFC5D

    I found default values in another thread:

    community.atmel.com/forum/samd…using-programming-failure

    0xD8E0C7FF and 0xFFFFFC5D

    and the SAMD21 datashield mentions defaults for Bits 0-2 and 4-6 as %111. Bits 0-2 are %001 in my device


    I connected my working SAMD21J18 & SAMD20J18 and there I see:

    mem32 0x00804000 2
    00804000 = D8E0C7FF FFFFFC5D

    The post was edited 4 times, last by MiR ().

  • Hello,

    Thank you for your inquiry.
    Such an issue is not known to us.
    We tried to reproduce the issue using a Arduino Zero board with a J-Link V10 using the connector marked "SWD" with a 9-pin adapter.
    Attached is a connection sequence with erase and programming of a example hex file.
    As you can see everything was working as expected.

    Which tool are you using for programming currently?
    What on board debugger do you have installed on the Arduino Zero? The EDBG or did you Flash a J-Link OB?

    MiR wrote:

    I think I saw comments on NVM lock here on the forum too, could this be a good hint?
    J-Link software would detect a NVM locked device and unlock it with a mass erase. So that should be covered.
    More information can be found here: wiki.segger.com/ATSAM_Device_Series

    Best regards,
    Nino
    Images
    • Capture.PNG

      67.6 kB, 807×942, viewed 1,085 times
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • I now did some more testing, tried to reproduce the steps you did, still no luck.

    I tried two Arduino Zeros and one Robodyn Board. I also tried to connect the 10 pin header turned 180 degrees, only difference is that I see the Secured Atmel SAMD device message in every case (also on the Robodyn where I do not get that message when I connect properly.

    Does it help you when I send you one of the Zeros and one of the RoboDyn Devices?

    Michael
    Images
    • robotdyn via edu.png

      126.8 kB, 2,304×1,627, viewed 621 times
    • robotdyn via edumini.png

      126.8 kB, 2,304×1,627, viewed 521 times
    • arduinozero via edbg.png

      110.21 kB, 2,304×1,390, viewed 528 times
    • arduinozero via edbg2.png

      111.04 kB, 2,304×1,494, viewed 619 times
    • arduinozero via edumini.png

      98.83 kB, 2,304×1,390, viewed 569 times
    • arduinozero via edumini2.png

      110.46 kB, 2,304×1,494, viewed 614 times
    • IMG_0726.JPG

      98.47 kB, 480×640, viewed 682 times
    • IMG_0727.JPG

      96.13 kB, 480×640, viewed 651 times
    • IMG_0728.JPG

      93.48 kB, 480×640, viewed 734 times
  • Hello,

    Thank you for providing the extra information.
    The behaviour on the Android Zero that an external J-Link does not work is known.
    This happens if you overwrite the original EDBG FW with J-Link FW. For this particular target device the J-Link EDBG FW is not officially supported. One reason is exactly this behaviour that due to hardware design decisions on the Arduino Zero an external J-Link can't be used anymore: segger.com/products/debug-prob…ther-j-links/j-link-edbg/
    But you should still be able to Flash your image with the J-Link EDBG.
    Could you provide your .hex file for verification with our setup?

    Regarding the RoboDyn board we do not see why it should not be working. We will try to get our hands on such boards our selves and investigate this behaviour.

    Best regards,
    Nino
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hello,

    Quick update. We received the Robodyn boards and the reported issue was reporoducible.
    It seems that the board is running some kind of bootloader that might impact the accessibility of Flash on that board.
    We will see if we can find a workaround for this, but if the Bootloader is locking Flash access and we can't remove it, then there is not much we can do about it.

    Best regards,
    Nino
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • I played arround a little bit tonight with one of my Arduino Zero boards and here are the results:

    using the method described in my last post did not help at all --> neither the mot file nor directly modifying the memory changed anything, after unplugging/replugging usb the value at address 804000 stayed wrong, F9 instead of FF

    What helped in the end was to install Atmel Studio and follow the instructions from the adafruit link:

    learn.adafruit.com/proper-step…o-m0/restoring-bootloader

    I now have correct value at 804000:

    J-Link>mem8 804000,10
    00804000 = FF C7 E0 D8 5D FC FF FF FF FF FF FF FF FF FF FF

    and my Blinky program loads just fine.....

    So it should be possible for you to fix writing the flash protection, all steps in Atmel Studio were done via JLink Interface programmed on the Arduino Zero.

    I also managed to properly set the byte on the RoboDyn Board, first it looked as if it does not work, then I did a flash erase in Atmel Studio and after that the problems with setting the byte were gone.

    The post was edited 1 time, last by MiR ().