Due software reset

Hello All,

I have a need to perform a software reset via code. This was nice and easy on all other boards besides the Due as you would just do this:

#include <avr/wdt.h>

void software_Reboot()
{
  wdt_enable(WDTO_15MS);
  while(1)
  {
  }
}

Then, all you had to do was call the method software_Reboot and the Arduino would reset. This was perfect and exactly what I am looking for. However, this does not work on the Due. First of all, it appears that avr/wdt.h does not exist for the Due.

Anybody have a quick and easy way to reset the Due from code, similar to above, but that works for the Due?

Thanks!

Mike

I have a need to perform a software reset via code.

That is extremely unlikely. More likely, you need to fix the real problem with your code.

it appears that avr/wdt.h does not exist for the Due.

(my emphasis)

More likely, you need to fix the real problem with your code.

PaulS, how can you make that snide remark when you have no clue why I would need to do a reset? There are some good reasons why one might need to do a reset even with perfect code.

Very unproductive.....thanks for nothing.

1 Like

check out section 14.4.4.4 of the SAM3X/A manual: http://www.keil.com/dd/docs/datashts/atmel/sam3xa/doc11057.pdf

this describes the software reset procedure.

Hi all,

Not sure if this helps, but it helped me. I was looking for a way to properly reset the Due without using a pin, the WDT, or the jump to 0. After lots of searching the web and pouring over the SAM datasheet, the following is code should will work on any ARMv7-M architecture such as the SAM3X used on the DUE.

Add these defines to the start of your code;

//Defines so the device can do a self reset
#define SYSRESETREQ    (1<<2)
#define VECTKEY        (0x05fa0000UL)
#define VECTKEY_MASK   (0x0000ffffUL)
#define AIRCR          (*(uint32_t*)0xe000ed0cUL) // fixed arch-defined address
#define REQUEST_EXTERNAL_RESET (AIRCR=(AIRCR&VECTKEY_MASK)|VECTKEY|SYSRESETREQ)

The SYSRESETREQ is bit 2 in the AIRCR register and needs to be set to request a reset. Before this can be done, 0x05FA needs to be put into AIRCR register VECTKEY bits16:31 or the write to SYSRESETREQ will be ignored.
The final line simply puts it all together to create the actual command to reset REQUEST_EXTERNAL_RESET and could be renamed as you desire.

Use this command when you want to reset the DUE.

REQUEST_EXTERNAL_RESET;

This worked for me, but I did need to add some delay (I used 1000mS) after a Serial.println("Something to print"); as it reset before the data got out to the terminal.

Hope this helps some of you.

This Due reset code worked perfectly, thank you!

Hi gjt211,

I tried your method to write to AIRCR Register like what you showed.

But I am not able to get the RESET. By RESET, I am expecting that the setup() function will be re-executed.

I am using your code with the Native USB Port.

Please do let me know if I am doing anything wrongly.

Awaiting your reply.

Thanks,
Sunny

Hi,

I use ntp server to update clock (RTC).

Reset works fine but my connection to ftp server not work.. it's possible to reset ethernet shield with this code ?

thanks

I've found a dead simple method for resetting the Arudino Due:

RSTC->RSTC_CR = 0xA5000005; // Reset processor and internal peripherals

Seriously, that's it.

If you want the external reset pin to also get pulled low (e.g. to reset external peripherals, like jot4p's ethernet shield) just change it to:

RSTC->RSTC_MR = 0xA5000801; // Set RST pin to go low for 256 clock cycles on reset
RSTC->RSTC_CR = 0xA5000013; // Reset processor, internal peripherals, and pull external RST pin low.

The relevant section of the datasheet is pages 223-233.

1 Like

I realise this is an old topic but it's #1 on google for queries on how to software reset Due.

The atmel asf (the SDK atmel/microchip provide for the sam3x8e), which Arduino uses and is therefore usable in your own sketches, provides a simple software reset function:-

rstc_start_software_reset(RSTC);

is all you need to do.

1 Like

slippyr4:
I realise this is an old topic but it's #1 on google for queries on how to software reset Due.

The atmel asf (the SDK atmel/microchip provide for the sam3x8e), which Arduino uses and is therefore usable in your own sketches, provides a simple software reset function:-

rstc_start_software_reset(RSTC);

is all you need to do.

OMG, only this method worked. Thank you!

1 Like