# Flash Page is Locked

**URL:** <https://forum.arduino.cc/t/flash-page-is-locked/268544>\
**Category:** Due\
**Created:** [November 9, 2014, 7:56pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544 "2014-11-09T19:56:31Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Palliser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/palliser/32/215442_2.png) [@Palliser](https://forum.arduino.cc/u/Palliser)\
**Post date:** [July 28, 2017, 4:20pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/21 "2017-07-28T16:20:58Z")

</div>

Hi IntraStellar,

Sorry to read from you about this Flash page locking issue.

In my experience with a couple of Dues, whatever the damage inside the Due, there is no way to make Arduino IDE to upload any code to the affected Due (via USB prog or native).

As I explained before, the easiest way to program the Due is using the In-system programmer software called SAM-BA via the USB native port. You could use also Atmel Studio 6x with SAM-ICE hardware but it is expensive and elaborated.

Here a link to download SAM-BA.

> **[Empowering Innovation | Microchip Technology](https://www.microchip.com/)**
>
> Microchip Technology is a leading provider of microcontroller, mixed-signal, analog and Flash-IP solutions that also offers outstanding technical support.

Also, this issue (in my cases) is directly related with the use of the DueFlashStorage library, especially if you exploit it (saving/retrieving in more than a dozen of memory registers).

Regards,  
-p

---

<div class="post-metadata">

**Author:** ![IntraStellar](https://avatars.discourse-cdn.com/v4/letter/i/f07891/32.png) [@IntraStellar](https://forum.arduino.cc/u/IntraStellar)\
**Post date:** [July 28, 2017, 8:09pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/22 "2017-07-28T20:09:40Z")

</div>

I will give it a try and get back to you. Thanks for helping me out you guys.

If you know any guide on how to do it or have explained it in another thread I'd appreciate the link to help me reset this pesky bit.

---

<div class="post-metadata">

**Author:** ![Palliser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/palliser/32/215442_2.png) [@Palliser](https://forum.arduino.cc/u/Palliser)\
**Post date:** [July 28, 2017, 9:04pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/23 "2017-07-28T21:04:43Z")

</div>

I am not sure if there is out there a simple procedure but here my steps to upload a sketch in Arduino Due using SAM-BA:

1. Upload or compile your sketch using the Arduino IDE. This step will generate the correspondent .bin file of your sketch.

2. Connect your computer to Arduino Due via USB native (SAM-BA doesn't recognize the USB programming port).

3. Press the Arduino Due Erase button for one second. Then press the Arduino Due Reset button for another second and finally release both buttons. This switches from the 'Arduino Due port' to the 'Bossa Program port' in the Windows Device Manager (COM ports).

4. Open SAM-BA. SAM-BA should detect and select the Arduino Due Bossa port and board type (ar91sam3x8-ek) automatically. Otherwise select the Arduino Due Bossa port.

5. Press the Connect button. Now you have connected SAM-BA with Due.

6. In the Flash tab (center of the main SAM-BA window) click the folder button of Send File Name and select the .bin file you just generated in step1. This file is usually located at C:\Users\YourName\AppData\Local\Temp\arduino\_build\_xxxxxx\yoursketch.ino.bin.

7. Press the Send File button. Click the ‘No’ button to the question about lock regions.

8. Close SAM-BA.

And that's it. Try it and let me know how it goes.

-p

---

<div class="post-metadata">

**Author:** ![IntraStellar](https://avatars.discourse-cdn.com/v4/letter/i/f07891/32.png) [@IntraStellar](https://forum.arduino.cc/u/IntraStellar)\
**Post date:** [July 29, 2017, 11:09am UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/24 "2017-07-29T11:09:21Z")

</div>

I tried it but it didn't work 😕

The windows device manager shows the bossa port but in SAM-BA I can choose from "\USBserial\COM7" or "COM7". I used "\USBserial\COM7" since the other gave me an error. I found the .bin file and sent it.

The response I get from SAM-BA is:

(sam-ba\_2.16) 2 % send\_file {Flash} "C:/Users/Jakob/AppData/Local/Temp/arduino\_build\_693572/fixDueLock.ino.bin" 0x80000 0  
-I- Send File C:/Users/Jakob/AppData/Local/Temp/arduino\_build\_693572/fixDueLock.ino.bin at address 0x80000  
first\_sector 0 last\_sector 1  
-I- Writing: 0x5014 bytes at 0x0 (buffer addr : 0x20002898)  
-I- 0x5014 bytes written by applet  
Do not lock

I then closed SAM-BA, opend Arduino IDE and uploaded the program. I still get the response that it's locked.

edited.

---

<div class="post-metadata">

**Author:** ![Palliser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/palliser/32/215442_2.png) [@Palliser](https://forum.arduino.cc/u/Palliser)\
**Post date:** [July 29, 2017, 2:12pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/25 "2017-07-29T14:12:19Z")

</div>

IntraStellar,

Can you try again but executing first the following three Scripts? (at the bottom of the SAM-BA window):

-Enable Flash access  
-Enable Security Bit (GPNVM0)  
-Erase all flash.

Then, send the file.

-p

---

<div class="post-metadata">

**Author:** ![Palliser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/palliser/32/215442_2.png) [@Palliser](https://forum.arduino.cc/u/Palliser)\
**Post date:** [July 29, 2017, 2:26pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/26 "2017-07-29T14:26:27Z")

</div>

> IntraStellar:  
> I then closed SAM-BA, opend Arduino IDE and uploaded the program. I still get the response that it's locked.
> 
> edited.

I forgot to tell you that once you close samba, your Due is already programmed. DO NOT download again the sketch.

-p

---

<div class="post-metadata">

**Author:** ![IntraStellar](https://avatars.discourse-cdn.com/v4/letter/i/f07891/32.png) [@IntraStellar](https://forum.arduino.cc/u/IntraStellar)\
**Post date:** [July 29, 2017, 3:17pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/27 "2017-07-29T15:17:03Z")

</div>

> Palliser:  
> I forgot to tell you that once you close samba, your Due is already programmed. DO NOT download again the sketch.

I can still upload a unrelated sketch like hello world? Because if this works it should be unlocked and work normally anyway if I understood this correctly. How would I otherwise check that it works?

I tried adding the three additional steps with no success.

Edit: I change from to the programming port after using SAM-BA if that makes any difference.

---

<div class="post-metadata">

**Author:** ![Palliser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/palliser/32/215442_2.png) [@Palliser](https://forum.arduino.cc/u/Palliser)\
**Post date:** [July 29, 2017, 4:08pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/28 "2017-07-29T16:08:32Z")

</div>

Try programming something like Serial.println("Hello World");

This way of programming Due with SAM-BA does not eliminate the issue. It is just a turnaround to program the Due.

-p

---

<div class="post-metadata">

**Author:** ![IntraStellar](https://avatars.discourse-cdn.com/v4/letter/i/f07891/32.png) [@IntraStellar](https://forum.arduino.cc/u/IntraStellar)\
**Post date:** [July 29, 2017, 4:44pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/29 "2017-07-29T16:44:00Z")

</div>

I did upload a hello world sketch to the Due trough a Arduino sketch after doing the SAM-BA steps if that's what you mean.

Do you mean that if this works, I'll still have to program the Due trough SAM-BA?

---

<div class="post-metadata">

**Author:** ![Palliser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/palliser/32/215442_2.png) [@Palliser](https://forum.arduino.cc/u/Palliser)\
**Post date:** [July 29, 2017, 5:14pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/30 "2017-07-29T17:14:49Z")

</div>

Yes. Now on, every time you need to program your 'pesky' Due, you have to use SAM-BA.  
I still don't understand why Due with lock issue is bricked for Arduino IDE, even after a chip erase.

-p

---

<div class="post-metadata">

**Author:** ![ard\_newbie](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ard\_newbie](https://forum.arduino.cc/u/ard_newbie)\
**Post date:** [July 29, 2017, 5:58pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/31 "2017-07-29T17:58:35Z")

</div>

@ IntraStellar

Could you upload the .bin of the skectch I provided in reply #14 with Sam-BA and see if something has changed.

I only clear all lock bits, not GPNVM bit 0 though, I can add this too...

---

<div class="post-metadata">

**Author:** ![IntraStellar](https://avatars.discourse-cdn.com/v4/letter/i/f07891/32.png) [@IntraStellar](https://forum.arduino.cc/u/IntraStellar)\
**Post date:** [July 30, 2017, 8:23am UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/32 "2017-07-30T08:23:38Z")

</div>

> Palliser:  
> Yes. Now on, every time you need to program your 'pesky' Due, you have to use SAM-BA.  
> I still don't understand why Due with lock issue is bricked for Arduino IDE, even after a chip erase.

That does suck. How will I know if the sketch was successfully uploaded? Will SAM-BA function as a serial monitor as well?

> ard\_newbie:  
> @ IntraStellar
> 
> Could you upload the .bin of the skectch I provided in reply #14 with Sam-BA and see if something has changed.
> 
> I only clear all lock bits, not GPNVM bit 0 though, I can add this too...

Yep, that's the file I have been uploading together with hello world.

---

<div class="post-metadata">

**Author:** ![Palliser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/palliser/32/215442_2.png) [@Palliser](https://forum.arduino.cc/u/Palliser)\
**Post date:** [July 30, 2017, 12:27pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/33 "2017-07-30T12:27:14Z")

</div>

> IntraStellar:  
> That does suck. How will I know if the sketch was successfully uploaded? Will SAM-BA function as a serial monitor as well?

Once you have downloaded your sketch using SAM-BA, you can connect your Due to the USB programming port and use the serial monitor of the Arduino IDE as usual.

---

<div class="post-metadata">

**Author:** ![IntraStellar](https://avatars.discourse-cdn.com/v4/letter/i/f07891/32.png) [@IntraStellar](https://forum.arduino.cc/u/IntraStellar)\
**Post date:** [July 30, 2017, 3:59pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/34 "2017-07-30T15:59:19Z")

</div>

That works! Thanks a bunch. I have tried both the 'hello world' sketch and the 'unlocking' sketch and they both run. Unfortunately the error still remains even after running the 'unlocking sketch' trough SAM-BA.

At least I can use the Due now even though it's a hazzle. If anyone have another solution that enables me to upload sketchs trough the Arduino IDE, I'm all ears!

---

<div class="post-metadata">

**Author:** ![ard\_newbie](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ard\_newbie](https://forum.arduino.cc/u/ard_newbie)\
**Post date:** [July 30, 2017, 4:57pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/35 "2017-07-30T16:57:32Z")

</div>

We know that the error message is incorrect since all lock bits are cleared.

We don't know if the security bit is set and if there is an issue with the ERASE process. I suspect the conjonction of several bugs.

I suggest that you upload, via SAM BA and the native USB port, this sketch to read GPNVM bits :

```cpp
#define Serial SerialUSB

#define EEFC_FKEY 0x5A

__attribute__ (( __section__ (".ramfunc")))
uint32_t ReadGPNVM_bits(void)
{
  uint32_t status;
  uint32_t priMask = __get_PRIMASK ();
  __disable_irq();

  static uint32_t (* IAP_function) (boolean, uint32_t);

  IAP_function = (uint32_t(*)(boolean, uint32_t)) * ((uint32_t *) CHIP_FLASH_IAP_ADDRESS);
  // select flash Bank
  while (!(EFC0->EEFC_FSR & EEFC_FSR_FRDY));

  IAP_function(0, EEFC_FCR_FKEY(EEFC_FKEY) | EEFC_FCR_FCMD(EFC_FCMD_GGPB ));
  while (!(EFC0->EEFC_FSR & EEFC_FSR_FRDY));
  status = EFC0->EEFC_FRR;            // Read GPNVM Bits

  __set_PRIMASK (priMask);
  return status;
}
void setup() {
  Serial.begin(250000);
  while(!Serial);

  uint32_t __GPNVM = ReadGPNVM_bits();
  Serial.print(" GPNVM = 0b"); Serial.println(__GPNVM, BIN);
}

void loop() {

}

```

Note that the result wil be printed via the native USB port !! Select the COM port accordingly.

---

<div class="post-metadata">

**Author:** ![IntraStellar](https://avatars.discourse-cdn.com/v4/letter/i/f07891/32.png) [@IntraStellar](https://forum.arduino.cc/u/IntraStellar)\
**Post date:** [August 3, 2017, 8:27am UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/36 "2017-08-03T08:27:41Z")

</div>

The serial response from that code is "GPNVM = 0b1" which would indicate that the lock bit is set if I understand this correctly.

This is from the Due processor (AT91SAM3X8E) datasheet:

> [@](#):
>
> 7.2.3.5 Security Bit Feature  
> The SAM3X/A series features a security bit, based on a specific General Purpose NVM bit (GPNVM bit 0). When  
> the security is enabled, any access to the Flash, either through the ICE interface or through the Fast Flash  
> Programming Interface (FFPI), is forbidden. This ensures the confidentiality of the code programmed in the Flash.  
> This security bit can only be enabled through the “Set General Purpose NVM Bit 0” command of the EEFC0 User  
> Interface. Disabling the security bit can only be achieved by asserting the ERASE pin at 1, and after a full Flash  
> erase is performed. When the security bit is deactivated, all accesses to the Flash are permitted.  
> It is important to note that the assertion of the ERASE pin should always be longer than 200 ms.  
> As the ERASE pin integrates a permanent pull-down, it can be left unconnected during normal operation.  
> However, it is safer to connect it directly to GND for the final application.

I don't really see what they mean by;  
"Disabling the security bit can only be achieved by asserting the ERASE pin at 1, and after a full Flash  
erase is performed."  
Perhaps pressing the ERASE pin after doing a full flash erase trough SAM-BA?

---

<div class="post-metadata">

**Author:** ![ard\_newbie](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ard\_newbie](https://forum.arduino.cc/u/ard_newbie)\
**Post date:** [August 3, 2017, 8:49am UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/37 "2017-08-03T08:49:57Z")

</div>

Now we are sure that the security bit has been set (however we still don't know why ...)

Here is a code to clear GPNVM bit 0, then read again GPNVM bits to know if the security bit has been properly cleard (Note that the result wil be printed via the native USB port !! Select the COM port accordingly.):

```cpp
#define Serial SerialUSB
#define EEFC_FKEY 0x5A

__attribute__ (( __section__ (".ramfunc")))
uint32_t ReadGPNVM_bits(void)
{
  uint32_t status;
  uint32_t priMask = __get_PRIMASK ();
  __disable_irq();

  static uint32_t (* IAP_function) (boolean, uint32_t);

  IAP_function = (uint32_t(*)(boolean, uint32_t)) * ((uint32_t *) CHIP_FLASH_IAP_ADDRESS);
  // select flash Bank
  while (!(EFC0->EEFC_FSR & EEFC_FSR_FRDY));

  IAP_function(0, EEFC_FCR_FKEY(EEFC_FKEY) | EEFC_FCR_FCMD(EFC_FCMD_GGPB ));
  while (!(EFC0->EEFC_FSR & EEFC_FSR_FRDY));
  status = EFC0->EEFC_FRR;            // Read GPNVM Bits

  __set_PRIMASK (priMask);
  return status;
}

__attribute__ (( __section__ (".ramfunc")))
uint32_t ClearGPNVM_bits( uint32_t gpnvm )
{

  uint32_t priMask = __get_PRIMASK ();
  __disable_irq();

  static uint32_t (* IAP_function) (boolean, uint32_t);

  IAP_function = (uint32_t(*)(boolean, uint32_t)) * ((uint32_t *) CHIP_FLASH_IAP_ADDRESS);

  while (!(EFC0->EEFC_FSR & EEFC_FSR_FRDY));
  // select flash Bank 0
  IAP_function(0, EEFC_FCR_FKEY(EEFC_FKEY) | EEFC_FCR_FARG(gpnvm) | EEFC_FCR_FCMD(EFC_FCMD_CGPB ));
  while (!(EFC0->EEFC_FSR & EEFC_FSR_FRDY));

  __set_PRIMASK (priMask);

}
void setup() {
  
  ClearGPNVM_bits( 0 );  // Clear security bit  GPNVM bit 0
  Serial.begin(250000);
  while (!Serial);

  uint32_t __GPNVM = ReadGPNVM_bits();
  Serial.print(" GPNVM = 0b"); Serial.println(__GPNVM, BIN);
}

void loop() {
 
}

```

---

<div class="post-metadata">

**Author:** ![IntraStellar](https://avatars.discourse-cdn.com/v4/letter/i/f07891/32.png) [@IntraStellar](https://forum.arduino.cc/u/IntraStellar)\
**Post date:** [August 3, 2017, 12:48pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/38 "2017-08-03T12:48:01Z")

</div>

Still the same output; "GPNVM = 0b1". So the bit fails to be reset somehow.

---

<div class="post-metadata">

**Author:** ![ard\_newbie](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ard\_newbie](https://forum.arduino.cc/u/ard_newbie)\
**Post date:** [August 3, 2017, 2:11pm UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/39 "2017-08-03T14:11:13Z")

</div>

As per datasheet:

7.2.3.5 Security Bit Feature  
.... Disabling the security bit can only be achieved by asserting the ERASE pin at 1, and after a full Flash  
erase is performed. When the security bit is deactivated, all accesses to the Flash are permitted...

The only guess I can make is that the ERASE procedure is not performed properly or long enough.

Let see if the ERASE pin (PC0) is not driven anymore by the peripheral as it should be. Try to upload this code to print SYSIO12 bit level:

```cpp
#define Serial SerialUSB

void setup() {
  
Serial.begin(250000);
while(!Serial);

boolean  SYSIO12 = MATRIX->CCFG_SYSIO >> 12;  
Serial.print( "SYSIO12 = "); Serial.println(SYSIO12);

}

void loop() {
  
}

```

---

<div class="post-metadata">

**Author:** ![IntraStellar](https://avatars.discourse-cdn.com/v4/letter/i/f07891/32.png) [@IntraStellar](https://forum.arduino.cc/u/IntraStellar)\
**Post date:** [August 5, 2017, 8:41am UTC](https://forum.arduino.cc/t/flash-page-is-locked/268544/40 "2017-08-05T08:41:52Z")

</div>

This gives the response: "SYSIO12 = 1"

[Previous page](https://forum.arduino.cc/t/flash-page-is-locked/268544.md?page=1)

[Next page](https://forum.arduino.cc/t/flash-page-is-locked/268544.md?page=3)
