Go Down

Topic: Flash Page is Locked (Read 12629 times) previous topic - next topic


Nov 09, 2014, 08:56 pm Last Edit: Nov 09, 2014, 09:04 pm by johnf95037
I was happily going along downloading program updates when I get "Flash page is locked".

I tried the push Erase and Reset with no luck.

How do I recover from this?

I did see another thread on this topic with no resolution.



Hello johnf95037,

I also started to experience this with my last batch of Dues.
So far, the only way to make them work is as follows:

With the board powered, press the erase button and after a second, while keeping pressed the erase button, press the reset button. Then, keep them pressed for another second and release them. Now try to upload a sketch. This have worked 100% of the time with my new Dues but I still do not know why this happens. It is a pain when you have stacked other shield with Due and need to do a new upload.




Hey Palliser,

I did try that, but I'll do it again and see what happens.  I curious how the lock bits get set.



I found this statement in the SAM3X datasheet:  Asserting the ERASE pin clears the lock bits, thus unlocking the entire Flash.

It should work.  Hmmm.


Hmm, again.  I did see a post where a guy had the same problem I'm experiencing.  He pressed the erase button then started the upload.  When the upload started, he released the erase button and the load was successful.

I tried this and it worked.  Why, I don't know just yet.  I have an Atmel ICE for debugging it's time to learn to use so I can get in and see what's actually happening.  Are lock bits actually set or is it something else?

A work-around is ok, but a fix is best.


Well the press the erase and release at the proper time really doesn't work.  The IDE is fooled, but the program doesn't load.

ICE is next.




Have you tried using the .bin with bossac via CMD?




I haven't tried Bossac yet.  I do have Atmel Studio 6.2 and an Atmel ICE debugger.  I can see that there is a lock bit set, but I still can't unlock it even with the current tool chain.  I've opened up a case with Atmel tech support to get this resolved.

I'll update.



I'm puzzled on two counts, AFAIK, bossa doesn't set lock bits. Generally that sort of thing DIY users don't need. So I don't know what is setting the bit.

The second is that the ERASE is an erase all/unbrick type operation. It's ok to clear lock bits when doing a bulk erase, because after the erase the code you want protected is wiped. (There are some manufacturers who have a one time only lock which can never be erased, but I don't think Atmel do this).

I guess that something weird is happening that sets a lock bit in a way that also means erase can't clear it, so hopefully Atmel can shed some light on how that can happen.
Please ask questions in the forum so everyone can benefit. PM me for paid work.


Good afternoon. I use in my project Arduino Due. When programming, I get the error: Flash page is locked. I am a beginner to the Arduino. Tell me, what is this error and how to fix it. Thanks.


There are several of these "Flash page is locked" Due posts but none seem to be resolved. 

I've tried installing BOSSA and it fails installation for some unexplained reason.  I've even tried SAMs apps but they don't show any application for Windows 64 bit.  And of course none of the button pushing has worked either.  Also reloading IDE drivers for 32 bit Due.

Like others I was pretty much minding my own business when this occurred.  A minor change to my code and now this expensive POS is locked.  Way too easy to brick this thing.

Is there any direction I can be pointed too?

Thank you,



Arduino IDE only uses BOSSAC which is a software solution buts this flash lock issue can be solved only by using a hardware probe like SAM-ICE together with Atmel Studio tools.

Some  times SAM-BA works but it will depends of how the issue was created (ie. sudden lack of power while writing, messing with RAM memory registers, etc.)


Jun 07, 2017, 04:55 pm Last Edit: Jun 08, 2017, 05:53 am by ard_newbie
As I understand the datasheet, all Flash pages can be locked with the GPNVM bit 0 set to 1 (called security bit), or one or more Flash pages can be locked using specific commands: "Write page and lock" or "Erase page and write page then lock" or " Set Lock Bit" commands with EEFC0/EEFC1.

Although I didn't encountered this issue, if I couldn't upload a sketch and get a "Flash page is locked" error message, and if an manual erase (more than 200 ms) and reset would fail to recover a normal situation, I would try to upload a minimal sketch in SRAM to set GPNVM bit 0 to 0 to unlock all pages. The IAP function in ROM can be used for all these commands.


Jun 09, 2017, 05:58 am Last Edit: Jun 09, 2017, 06:00 am by Palliser
Apart from using according official hardware (SAM-ICE) and software (Atmel Studio 6 or 7) tools to solve this 'Flash page locked' issue, I could not find another consistent way to do it. In my opinion, the real problem here is that there is no easy way for someone inexperienced with ARM to restore a Due after this crash.

Anyway, here a snapshot of AS6 and device programming showing the 31 regions to lock or unlock.




Thanks for this information Palliser. Does this "manip" work for you when you get a "Flash page is locked" error message ?

I did this snippet to unlock all 32 lock bits in Flash bank 0 and Flash bank 1 whatever their previous state (Not tested since I never have the above error message):

Code: [Select]

#define RAMFUNC __attribute__ ((long_call, section (".ramfunc")))
#define IROM_ADDR (0x00100000u)
#define EEFC_FKEY 0x5A

// During this sequence, the software cannot run out of Flash so needs to run out of ROM with the IAP function.
void ClearAllLockRegions()
  boolean Bank_nb;
  uint32_t priMask = __get_PRIMASK ();
  // FWS (Flash Wait States) register should be set to 6 (look at the errata at the end of the datasheet)
  char __FWS;

  // Set bit 16 of EEFC_FMR : See chap. page 1442
  EFC0->EEFC_FMR |= EEFC_FMR_SCOD;                              // Sequential code optimization disable

  __FWS = (EFC0->EEFC_FMR & EEFC_FMR_FWS_Msk) >> EEFC_FMR_FWS_Pos ; // Save FWS value
  EFC0->EEFC_FMR |= EEFC_FMR_FWS(6);                            // 6+1 wait states for read and write operations

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

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

  Bank_nb = 0;    // select flash Bank 0
  while (!(EFC0->EEFC_FSR & EEFC_FSR_FRDY));     // Wait for EEFC0 Ready
  // Clear all 16 regions lock bits of Flash Bank 0
  while (!(EFC0->EEFC_FSR & EEFC_FSR_FRDY));

  Bank_nb = 1;    // select flash Bank 1
  while (!(EFC1->EEFC_FSR & EEFC_FSR_FRDY));     // Wait for EEFC1 Ready
  // Clear all 16 regions lock bits of Flash Bank 1
  while (!(EFC1->EEFC_FSR & EEFC_FSR_FRDY));

  // Clear bit 16 of EEFC_FMR : See chap. page 1442
  EFC0->EEFC_FMR &= ~EEFC_FMR_SCOD;                             // Sequential code optimization enable

  EFC0->EEFC_FMR &= ~ EEFC_FMR_FWS_Msk;                         // Restore FWS value
  __set_PRIMASK (priMask);

int main (void)

  WDT_Disable(WDT) ;
  init();      // initialize hardware

Go Up