[Solved] Due: JTAG and SWD do not work after pressing erase button

Hi all,

I have an Arduino Due board. I can successfully upload code to it using Arduino upload via USB.
However I am also exploring another approach, which is to upload code via Atmel studio using an Atmel ICE and JTAG connection. Usually this works fine (the code uploads, and a simple “blink” sketch makes the onboard LED flash).

However when I press the erase button, and then try to upload the same sketch via Atmel Studio and JTAG, something strange happens. The code uploads fine:
Erasing device… OK
Programming Flash…OK
Verifying Flash…OK
But then the program on the Due does not actually execute. The LED does not start to ‘blink’. If I then again upload via USB (programming port) and the Arduino IDE, the blink program does work. And when I then upload via Atmel Studio and JTAG again without pressing the erase button, everything happens as expected too (LED blinks etc).
Does anyone have any idea what might be going on? The reason I ask is because I would like to design a board using only a JTAG connection. Do you think the above problem could cause issues when using a ‘blank’ factory SAM MCU as well?

See attachment (due to exceeding character length) for the Atmel Studio upload logs, both for a “normal” upload, and a “faulty” upload (the upload doesn’t actually seem to be faulty, but the execution of the program code does).

EDIT: the same problem applies to SWD.

Blink sketch that i am uploading:

#define led LED_BUILTIN

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(600);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(600);               // wait for a second
}

Verbose Upload Atmel studio_Faulty.txt (76.4 KB)

Verbose Upload Atmel studio_Normal.txt (81 KB)

Did you try this:

Press Erase button (3s), upload via JTAG then press Reset button.

Press Erase button (3s), upload via JTAG then press Reset button.

Just tried it. Doesn't seem to make difference. Also I looked in the datasheet quite extensively, couldn't find a lot of info about what the erase pin actually does.
I did find this passage under "errata", not sure what it means but maybe it is relevant:

49.1.5.1 JJTAG Boundary: PC0/ERASE
In JTAG Boundary Scan mode, the PIO PC0 which is by default the ERASE pin may erase the Flash content if the
pin is set to high level.
Problem Fix/Workaround
Do not use PC0/ERASE (or tie to 0) or set PC0/ERASE at high level during a time lower than 150 ms in Boundary
JTAG Scan mode or program the Flash after using this mode.

AFAIK erasing flash memory (i.e. all flash memory cells are set to 0xFF) is compulsory before uploading a new .bin file.

Erase button immediately triggers flash erase you don't need to hold it for seconds.

ard_newbie:
AFAIK erasing flash memory (i.e. all flash memory cells are set to 0xFF) is compulsory before uploading a new .bin file.

Interesting that you mention uploading a .bin file. I was using a .elf file before. I just tried it with a .bin file. Doesn't make a difference unfortunately.

There is bossac.exe to upload a .bin file (resulting from a sketch compilation, either from arduino IDE or Atmel studio):
Firstly, push the Erase button for 3 seconds, then the Reset button for 3 seconds, then:
Thru the programming port (if COM9 is the selected port):
...AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-arduino\bossac.exe --port=COM9 -U true -e -w -u -b image.bin
Or
Thru the Native USB port:
...AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-arduino\bossac.exe -U true -e -w -u -b -R image.bin

ard_newbie:
There is bossac.exe to upload a .bin file (resulting from a sketch compilation, either from arduino IDE or Atmel studio):
Firstly, push the Erase button for 3 seconds, then the Reset button for 3 seconds, then:
Thru the programming port (if COM9 is the selected port):
...AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-arduino\bossac.exe --port=COM9 -U true -e -w -u -b image.bin
Or
Thru the Native USB port:
...AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-arduino\bossac.exe -U true -e -w -u -b -R image.bin

Thanks :slight_smile: but that's still using the USB connection though isn't it? It's not applicable to JTAG?

What is the JTAG adapter do you use? ICE?

Most people use SWD rather than JTAG.

You can use any SWD debugger on Keil, Rowley, ... etc
Obviously AS7.0 is owned by Microchip. So AS7.0 only accepts ATMEL-ICE, PK4, SNAP, JLINK.

David.

phr3ak:
What is the JTAG adapter do you use? ICE?

Yes!

Most people use SWD rather than JTAG.

So I considered this, but I'm not quite sure how to connect it to the Due. From the Atmel Ice manual it seems it's the exact same plug (and therefore same connection on the Due). Then the only difference with JTAG would be to select the SWD interface from the dropdown menu in microchip studio "programming device" window instead of JTAG, correct?
So I tried that, and that doesn't solve the problem either unfortunately.

Solved! :slight_smile: :slight_smile: :slight_smile: :slight_smile:

With SWD: After uploading via Microchip Studio, go to the GPNVM bits section of "device programming" window. Make sure boot mode is set to "boot from flash". Also check that GPNVMBITS register is set to 0x00000002. Then press "program". The sketch you uploaded to the MCU should now work.

So it seems what happens is that pressing the erase button resets the GPNVM bits so that the MCU boots from ROM, but then Atmel ICE + JTAG/SWD does not set the boot mode back to flash after (succesfully) programming the MCU.

Thanks everyone for your contributions!

can you rename the topic to more relevant title?

can you rename the topic to more relevant title?

Sure, do you have any suggestions?