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 ?