Go Down

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

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...

IntraStellar

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?

@ 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.

Palliser

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.

IntraStellar

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!

ard_newbie


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 :

Code: [Select]


#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.


IntraStellar

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:

Quote from: 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?

ard_newbie

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



Code: [Select]

#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() {
 
}





IntraStellar

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

ard_newbie

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:


Code: [Select]

#define Serial SerialUSB

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

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

}

void loop() {
 
}

IntraStellar

This gives the response: "SYSIO12 = 1"

doritnap

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

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.

Go Up