Set lock bits (GPNVM bit 0) on DUE

I know how to set the lock bits on a 328p so that no one can read my code off the flash memory. But I have not been able to figure out how to do this on the DUE. Can someone point in the right direction? I have an Atmel ICE programmer.

To lock Flash regions with the DUE you can make use of bossac.exe:

On Windows, after a "cmd" command, type these lines after C:\Users...>:

To know all parameters you can use:
AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-arduino\bossac.exe –h

To read a .bin file inside the DUE:

AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-arduino\bossac.exe --port=COM9 -r image.bin

To upload to the DUE a .bin file:

AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-arduino\bossac.exe --port=COM9 -e -w -b image.bin

To unlock all regions before uploading:
AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-arduino\bossac.exe --port=COM9 -e
-u -w -b image.bin

To lock all regions after uploading:
AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-arduino\bossac.exe --port=COM9 -e
-w -l -b image.bin

Of course the COM port number will depend on your PC

The other method to lock Flash regions is to add some lines in the setup() of your code to write GPNVM bits.

Wow, thanks. This is so detailed. I will give it a try.

Once I lock the bits, I assume I can use the same methods to unlock them if I want to change the program? Correct?

1 Like

I didn't try to lock/unlock :slight_smile: Theoretically, an manual Erase should remove any lock bit (push 3 seconds on the Erase button).

I guess you want to lock the Flash read access to prevent customers from reading your software, right ?

FYI, some users of the DueFlashStorage library have reported a bug: sometimes the board locks itself and nothing can unlock the board (not even an manual Erase) except the bossac software with the Unlock option, although once a new sketch has been uploaded, the board is locked again...

OK. I got Atmel Studio 7 and the Atmel ICE working.

Plug in the little 0.5-pitch cable to the SAM port on the ICE, and then to the corresponding header on the DUE. There are fewer pins on the DUE header than there are on the ICE, so the connector hangs off the header (toward the power connector). The red wire on the ribbon cable points toward the power connector.

Load SAM3X8E support into Atmel Studio using the Device Pack Manager in the Tools menu.

Plug in the ICE and the Arduino DUE programming port to the computer's USB. In the Device Programming window, you will find the ICE option for Tool and the ATSAM3X8E option in Devices. Select JTAG interface and "Apply".

Now you can set the Security bit (last option on the left of the dialog), and no one will be able to read the program from the SAM3X anymore.

If you want to reprogram the board, the Arduino IDE works as usual, resetting the board and clearing the security bit before loading the new program.