Un-Protect Flash memory on ATSAM4L series processor

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

    • Un-Protect Flash memory on ATSAM4L series processor


      I got stuck reprogramming SAM4LS8B using Eclipse MCU and J-Link GDB Server. Hopefully this post will be useful to anyone else needing to un-protect flash memory on SAM4L processor.

      [Segger support - Note this is easy to implement and could be added to the J-Flash to enable "Unprotect" for SAM4L processor family ]

      After downloading, My code would crash before hitting "main". Everything *looked* OK - I didn't see any warnings, and the output from J-Link appeared to show successful verification, so I assumed the part had programmed correctly.

      After some work debugging from inside Eclipse, I got a hunch that the flash was programming lower address (where the vector table is at location 0x0000), but not at the address pointed to by the reset vector. My reset vector points to 0xA090, and the code at that address wasn't changing after programming, so things were crashing very early in the boot.

      I tried running J-Flash, and confirmed that I couldn't program or erase flash beyond address 0x8000. I took a guess that the flash protection was enabled. Unfortunately the "Unprotect" option is not available in J-Flash for the SAM4L8

      Using J-Link, I managed to clear the protection bits in the SAM4 with the following command sequence.

      Read words at 0x400A0014 and 0x4000A0018 - Flash General Purpose Fuse Bits. The Flash protection is in the low 16bits of 0x400A0018.
      J-Link>mem32 0x400A0014 2
      400A0014 = FFFFFFFF FFFF0000

      Write the Flash Command to clear the all of the General Purpose Fuse Bits. The flash command register is 0x400A0004. The command is 0xA500000B
      J-Link>w4 0x4000A0004 0xA500000B
      Writing 0xA500000B -> 0x4000A0004

      You can check it works by re-reading the GP Fuse bits:
      J-Link>mem32 0x400A0014 2
      400A0014 = FFFFFFFF FFFFFFFF

      After this, the flash programs successfully.
    • Hello,

      Thank you for your feedback.
      Due to the sheer amount of different target devices supported by J-Link it is possible that some target specific features like Flash protection unlock is not yet implemented.
      Thank you for making us aware of this. We will create a JLinkScript based on this information which will then be shipped with future J-Link versions for automatic Flash protection detection and unlocking.
      Should you need this now you can create your own JLinkScript. How is described in the J-Link user guide UM08001.

      Best regards,
      Please read the forum rules before posting: Forum Rules

      Keep in mind, this is not a support forum. Its main purpose is user to user interaction.
      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 contact us per e-mail.
      Alternatively our support ticketing system can be used as well: segger.com/ticket/