Flash Page is Locked

I am facing the same issue with my Arduino Due - Flash Page is locked. The flow described above with the SAM-BA does give a workaround. However, i wanted to solve it so i can upload scatches from the IDE only.
For this i've connected a SAM ICE ATMEL studio trying to reset the lockbit as described above (by God Member).

What i found is that bit 16 (0x00010000) stays on even after erase Chip. When i verify it's reset, i get an error: "one or more registers differs"

Any idea?

Thanks,
D

I also have the same problem with 2 arduino due boards. I used SAM_BA to load the .bin file, but this is awkward. I solved it by doing the following:

  • Find the platform.txt file in the Hardware / Sam / 1.6.xx /
  • Find the second line from the bottom up: tools.bossac.upload.pattern = "{path.svg} {{cmd}" {upload.verbose} --port = {serial.port.file} -U {upload.native_usb} -e -w {upload.verify} -b "{build.path} / {build.project_name} .bin" -R
  • Add "-u" before "-b": tools.bossac.upload.pattern = "{path.svg / {cmd}" {upload.verbose} --port = {serial.port.file} -U {upload. native_usb} -e -w {upload.verify} -u -b "{build.path} / {build.project_name} .bin" -R
  • This means bossac will unlock all the bits. restar Arduino IDE
    So everything works as well as it used to.

platform.txt (5.43 KB)

I have tried all the above.

But there is still same problem i.e. flash page is locked.

Please help.

Hi everyone :wink:

Just today i started to have the exact same problem, as many already have mention before.

Flash page is locked (47 pages in my case)

I first used the "fix" provided by @ard_newbie, but the problem still persisted:

ard_newbie:
In the IDE window, go to File / Preferences, then click in the url at the bottom of preferences:

c:\Users....\AppData\Local\Arduino15\preferences.txt

Then go to: packages>arduino>hardware>sam>1.6.x>platform.txt

Copy and past platform.txt into a new blank IDE window (without setup() and loop()

At the end of the file, you will find:

-e -w -v -b change this by:
-e -u -w -v -b

For the meaning of -u (unlock all Flash pages), see:
BOSSA | shumatech.com

Then copy the entire new file in platform.txt, save and close all IDE windows.

Open a new IDE window with the minimal sketch (setup() and loop()), all Flash pages should be unlocked now.

(I undid this changes, after i found out that mamoto's approach is working for me)

Right after, I followed the instructions from @mamoto and was able to get my Arduino Due working again. (As far as i can tell by now, done some uploads of different sketches):

mamoto:
I also have the same problem with 2 arduino due boards. I used SAM_BA to load the .bin file, but this is awkward. I solved it by doing the following:

  • Find the platform.txt file in the Hardware / Sam / 1.6.xx /

  • Find the second line from the bottom up:
    tools.bossac.upload.pattern = "{path.svg} {{cmd}" {upload.verbose} --port = {serial.port.file} -U {upload.native_usb} -e -w {upload.verify} -b "{build.path} / {build.project_name} .bin" -R

  • Add "-u" before "-b":
    tools.bossac.upload.pattern = "{path.svg / {cmd}" {upload.verbose} --port = {serial.port.file} -U {upload. native_usb} -e -w {upload.verify} -u -b "{build.path} / {build.project_name} .bin" -R

  • This means bossac will unlock all the bits. restar Arduino IDE

So everything works as well as it used to.

The platform.txt file is located here:

In the IDE window, go to File -> Preferences, then click in the url at the bottom of preferences:

c:\Users....\AppData\Local\Arduino15\preferences.txt

Then go to: packages -> arduino -> hardware -> sam -> 1.6.x -> platform.txt

Complete path: C:\Users\username\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.x

EDIT (20.05.2019): The bug fix of adding a "bossac flash unlock" in form of an "-u" to the platform.txt file, worked for around 3 days!!!

In order to continue working with the Flash on my Due, i tried several changes to the platform.txt file.

Until i found one that was working for me: (Changes are marked RED)

tools.bossac.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -U {upload.native_usb} -e -u -w {upload.verify} -u -b "{build.path}/{build.project_name}.bin" -R

tools.bossac_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -u -w -v -b /tmp/sketch.bin -R

EDIT (21.05.2019): But strangely after around 1 day of working properly, my Flash pages were once again locked!

At this point in time i decided to stop, putting forth more effort in trying to make i run just for a few days and switched to a SPI EEPROM.

Perhabs those work arounds may work for you , but sadly... not for me.

platform.txt (5.54 KB)

ard_newbie:
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):

#define RAMFUNC __attribute__ ((long_call, section (".ramfunc")))

#define IROM_ADDR (0x00100000u)
#define CHIP_FLASH_IAP_ADDRESS (IROM_ADDR + 8)
#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.
RAMFUNC
void ClearAllLockRegions()
{
 boolean Bank_nb;
 uint32_t priMask = __get_PRIMASK ();
 __disable_irq();

/************************************************************************************/
 // 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. 49.1.1.2 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_Msk;
 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
 IAP_function(Bank_nb, EEFC_FCR_FKEY(EEFC_FKEY) |  EEFC_FCR_FCMD(EFC_FCMD_CLB) | EEFC_FCR_FARG(0xFFFF));
 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
 IAP_function(Bank_nb, EEFC_FCR_FKEY(EEFC_FKEY) |  EEFC_FCR_FCMD(EFC_FCMD_CLB) | EEFC_FCR_FARG(0xFFFF));
 while (!(EFC1->EEFC_FSR & EEFC_FSR_FRDY));

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

EFC0->EEFC_FMR &= ~ EEFC_FMR_FWS_Msk;                         // Restore FWS value
 EFC0->EEFC_FMR |= EEFC_FMR_FWS(__FWS);
 /**************************************************************************************/
 __set_PRIMASK (priMask);
}

RAMFUNC
int main (void)
{

WDT_Disable(WDT) ;
 init();      // initialize hardware
 ClearAllLockRegions();
 while(true);

}

Dear ard_newbie, I tryied to fix the problem uploading your above suggestion, using the press erase bottom lotery, and after the program was uploaded succesfully, the Flash page locked message still been issued. Any idea abou what more could be tryed ?

There is another possibility... I've heard somewhere that when you write to the flash memory over 10,000 times the flash dies and the message Flash page locked is always issued. In this case nothing else can be done and your DUE becomes trash... Is it true ?