[ABANDONED] Flash programming using JLink on Atmel ATSAM

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

  • [ABANDONED] Flash programming using JLink on Atmel ATSAM

    Hello,

    I am trying to use JLink to program the "USER_PAGE" of an Atmel chip (ATSAML21J18 ).
    This USER_PAGE is a flash sector (256 bytes) that defines, among others, the size of the bootloader that I need to flash on this chip.

    I can correctly connect and read memory at this sector and write does not give me an error, however the memory is not programmed...

    Connecting to J-Link via USB...O.K.
    Firmware: J-Link V9 compiled Mar 29 2016 18:46:37
    Hardware version: V9.30
    S/N: 59XXXX50
    License(s): GDB
    VTref = 2.731V

    [...]
    Device "ATSAMD20J18" selected.

    Found SWD-DP with ID 0x0BC11477
    Found SWD-DP with ID 0x0BC11477
    Found Cortex-M0 r0p1, Little endian.
    [...]
    J-Link>mem32 0x00804000 2
    00804000 = B11E86FB FFFFF8BB

    J-Link>w4 0x00804000 0xB11E86FF
    Writing B11E86FF -> 00804000

    J-Link>mem32 0x00804000 2
    00804000 = B11E86FB FFFFF8BB

    I tried writing one byte at a time, 16bits word, 32 bits, nothing works.
    I also even try to write an hex file of the sector and load it on the flash :

    Source Code

    1. :0200000200807C
    2. :10400000FF861EB1BBF8FFFFFFFFFFFFFFFFFFFFB3


    J-Link>loadfile C:\Users\Me\Atmel\USER_PAGE.hex 0
    Connection to device lost. Trying to reconnect to target.
    Found SWD-DP with ID 0x0BC11477
    Downloading file [C:\Users\Me\Atmel\USER_PAGE.hex]...

    **************************
    WARNING: CPU is running at low speed (5310 kHz).
    **************************

    J-Link: Flash download: Flash programming performed for 1 range (256 bytes)
    J-Link: Flash download: Total time needed: 0.080s (Prepare: 0.069s, Compare: 0.001s, Erase: 0.003s, Program: 0.001s, Verify: 0.000s, Restore: 0.003s)
    O.K.
    J-Link>mem32 0x804000 2
    00804000 = B11E86FB FFFFF8BB

    Same result, and even worse, if I try to load the file again I have this:
    J-Link: Flash download: Flash download skipped. Flash contents already match
    O.K.
    But when I read the memory again the value is not changed. I am really confused here.

    I know that this memory sector has some reserved bits, could that prevent me to program this sector?
    Is there any way to program only one bit of a byte using jlink?

    Thank you very much for your help.



  • Hi,

    the w1/w2/w4 commands can be used to write to RAM, not Flash.

    Using a .hex file is a possible way, but it seems that you have a typo in your .hex file.

    C Source Code

    1. :0200000400807A
    2. :10400000B11E86FBFFFFFFF8BB00000003000000AD
    3. :00000001FF


    Please not that you doing this an your own risk. I did not look up want writing this value into the config area of the Atmel chip does.

    Best regards,
    Niklas
    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.
  • RE: Flash programming using JLink on Atmel ATSAM

    gecko667 wrote:

    Hello,

    I am trying to use JLink to program the "USER_PAGE" of an Atmel chip (ATSAML21J18 ).
    This USER_PAGE is a flash sector (256 bytes) that defines, among others, the size of the bootloader that I need to flash on this chip.

    I can correctly connect and read memory at this sector and write does not give me an error, however the memory is not programmed...

    Connecting to J-Link via USB...O.K.
    Firmware: J-Link V9 compiled Mar 29 2016 18:46:37
    Hardware version: V9.30
    S/N: 59XXXX50
    License(s): GDB
    VTref = 2.731V

    [...]
    Device "ATSAMD20J18" selected.

    Found SWD-DP with ID 0x0BC11477
    Found SWD-DP with ID 0x0BC11477
    Found Cortex-M0 r0p1, Little endian.
    [...]
    J-Link>mem32 0x00804000 2
    00804000 = B11E86FB FFFFF8BB

    J-Link>w4 0x00804000 0xB11E86FF
    Writing B11E86FF -> 00804000

    J-Link>mem32 0x00804000 2
    00804000 = B11E86FB FFFFF8BB

    I tried writing one byte at a time, 16bits word, 32 bits, nothing works.
    I also even try to write an hex file of the sector and load it on the flash :

    Source Code

    1. :0200000200807C
    2. :10400000FF861EB1BBF8FFFFFFFFFFFFFFFFFFFFB3


    J-Link>loadfile C:\Users\Me\Atmel\USER_PAGE.hex 0
    Connection to device lost. Trying to reconnect to target.
    Found SWD-DP with ID 0x0BC11477
    Downloading file [C:\Users\Me\Atmel\USER_PAGE.hex]...

    **************************
    WARNING: CPU is running at low speed (5310 kHz).
    **************************

    J-Link: Flash download: Flash programming performed for 1 range (256 bytes)
    J-Link: Flash download: Total time needed: 0.080s (Prepare: 0.069s, Compare: 0.001s, Erase: 0.003s, Program: 0.001s, Verify: 0.000s, Restore: 0.003s)
    O.K.
    J-Link>mem32 0x804000 2
    00804000 = B11E86FB FFFFF8BB

    Same result, and even worse, if I try to load the file again I have this:
    J-Link: Flash download: Flash download skipped. Flash contents already match
    O.K.
    But when I read the memory again the value is not changed. I am really confused here.

    I know that this memory sector has some reserved bits, could that prevent me to program this sector?
    Is there any way to program only one bit of a byte using jlink?

    Thank you very much for your help.





    Datasheet: atmel.com/Images/Atmel-42385-SAM-L21-Datasheet.pdf

    I've worked a lot with the atsaml21j18, both the a and b revisions, in the past year. Unfortunately, changing the NVM User Row is not as simple as just writing the bits to address 0x00804000.

    For your own reference I suggest reading up on the NVMCTRL section of the datasheet, section 28, page 489. Of particular interest is section 28.6.4, even more specifically sections 28.6.4.3 NVM Write. Note that these are general instructions, and unfortunately the datasheet does not do a great job explaining the steps needed to modify the nvm user row, located in nvm auxillary space. Below I'll outline these steps.

    So the order of operations (I'm using the asf/sam0/drivers/nvm/nvm.c driver as reference)

    1. Read NVM user row 0x00804000 and modify the specific bits you want.
    2. NVM erase AUX Row: NVMCTRL.ADDR[21:0] = 0x00804000 / 4; NVMCTRL.CTRLA[15:0] = 0x05 (EAR) | 0xA500 (CMDEX);
    3. NVM clear page buffer: NVMCTRL.CTRLA[15:0] = 0x44(PBC) | 0xA500 (CMDEX);
    4. Write NVM user row, the full 64 bits, to address 0x00804000
    5. NVM write AUX Row: NVMCTRL.ADDR[21:0] = 0x00804000 / 4; NVMCTRL.CTRLA[15:0] = 0x06 (WAP) | 0xA500 (CMDEX);


    This procedure should modify the user row bits.

    Let me know if you have any trouble, I can try and write this out as a jlink command set, which I need to do for myself here soon anyway