Does anybody know how to restart a program on Arduino DUE programmatically? I tried jumping to address 0x80000 but this simply halts the program.
Thanks in advance.
Does anybody know how to restart a program on Arduino DUE programmatically? I tried jumping to address 0x80000 but this simply halts the program.
Thanks in advance.
You can find most of the relevant information to trigger a software reset in Sam3x datasheet RSTC section. There are several ways to trigger a reset, depending on the "deepness" of the Reset.
Here is a code you can use to trigger a software Reset:
void setup(){
Serial.begin(250000);
Serial.println("Ready to Reset");
}
void loop(){
delay(2000);
__DSB;
SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | SCB_AIRCR_SYSRESETREQ_Msk);//software reset
//RSTC->RSTC_CR = RSTC_CR_KEY(0xA5) | RSTC_CR_PERRST | RSTC_CR_PROCRST;
//NVIC_SystemReset();
}
Thanks @ard_newbie for your reply,
I indeed tried similar approaches but all of them bring the board to an undefined state where serial comms are not restarted. Anyway, thanks so much for your help.
I suspect there is an issue somewhere in your code because you (normally) don't have to trigger a software Reset. Post your code (between code tags).
However, if Serial outputs weird characters after a Reset, you can try :
1/ To force a Reset of UART registers just before the Serial.begin() in setup():
UART->UART_CR = UART_CR_RSTRX
| UART_CR_RSTTX
| UART_CR_RSTSTA;
2/ Before triggering a software Reset in loop(), write:
Serial.flush();
Serial.end();
__DSB;
__DMB;
__ISB;
ard_newbie:
You can find most of the relevant information to trigger a software reset in Sam3x datasheet RSTC section. There are several ways to trigger a reset, depending on the "deepness" of the Reset.Here is a code you can use to trigger a software Reset:
void setup(){
Serial.begin(250000);
Serial.println("Ready to Reset");
}
void loop(){
delay(2000);
__DSB;
SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | SCB_AIRCR_SYSRESETREQ_Msk);//software reset
//RSTC->RSTC_CR = RSTC_CR_KEY(0xA5) | RSTC_CR_PERRST | RSTC_CR_PROCRST;
//NVIC_SystemReset();
}
Thanks for this. It works like a charm.
Is this working with SerialUSB as well?