Author Topic: DISABLING ERASE  (Read 9300 times)


  • Sr. Member
  • ****
  • Posts: 398
« on: February 03, 2014, 08:20:02 am »
The ERASE-Button as a last resort for reprogramming the DigiX / DUE turns into evil, when someone is pressing the button during demonstrations.

Fortunately the function of the ERASE-button can be disabled for such cases. Reading the documentation you will learn, that pin PC0, where the ERASE-button is connected to, can work a a normal GPIO port.
For that, only the bit 12 in the System I/O Configuration Register needs to be cleared.
After that it is helpful, to configure the PIN as INPUT, so that there will occur no shortage, when someone is still pressing the button.  As a side effect, the ERASE-button can be used as a normal input for the running application.

As the ERASE-Pin is currently not broken out, it is not referenced with an pin number in the library. Therefore configuration is somewhat lower level.

Code: [Select]
void disableERASE() {
  // SAM8X3E manual, chapter 23.8.5
  // System I/O Configuration Register bit 12
  //  1: ERASE function selected (Default at reset).
  //  0: PC0 function selected
  REG_CCFG_SYSIO = (REG_CCFG_SYSIO & 0b11111111111111111110111111111111);
  // and now configure PC0 as INPUT
  pmc_enable_periph_clk( ID_PIOC ) ;
  PIO_Configure(PIOC, PIO_INPUT, PIO_PC0, 0) ;

Once this function is called (preferably in setup() ), the ERASE-button is dead.  That leads to the following situation:

In the original DUE the programming port does not longer work. The 16U2, which is driving the programming port, pulls ERASE to HIGH and after that RESET to LOW to trigger an reboot into the  SAM-BA mode. As the RESET pin is disabled, nothing gets deleted, therefore the GPNVM bit 1 is untouched, and the board starts again the programmed sketch, instead of the expected SAM-BA Loader.
However the programming port works again, after an manual erase as described later.

The Arduino DUE or DigiX native port however still works, as deletion there is software based.

If you need to ERASE it is still possible:  You need to press both buttons (ERASE and RESET) together, and release RESET before ERASE.  Then ERASE will work during the start of the CPU before setup() is called.

Perhaps digistump will include PC0 with a own pin-ID in the DigiX core-files. That should make the lines above more usable, especially reading the button state of ERASE as an INPUT button.

« Last Edit: February 03, 2014, 08:44:08 am by gogol »