Chip reset from Software

I’m using my AVR4809s in a remote location and on the odd occasion it might be helpful to do a hardware reset without having to travel to the site to physically press a button. My thought was to trigger a reset by accepting a serial input sequence such as reset# and use a gpio pin to pull the reset pin low. I guess I could try it, but I suspect there might be timing issues.

Otherwise, I could implement a watchdog timer and fail to ping that if a reset sequence is received.

any advice on a good approach much appreciated.

Per datasheet page 106 chapter

The software Reset makes it possible to issue a system Reset from software. The Reset is generated by writing a ‘1’ to the Software Reset Enable bit (SWRE) in the Software Reset register (RSTCTRL.SWRR).

The Reset will take place immediately after the bit is written and the device will be kept in reset until the Reset sequence is completed.

So the firmware itself is well-capable of doing a reset – that is, when the firmware can still execute code and is not stuck somewhere. That’s why it should be a must to activate the watchdog (which is hardware-supported) on top of that and always feed it in the regular codepath, so that a hangup results by design in a watchdog timeout and reset.

Thanks, I’ve tested out setting bit zero of the SWRR reg:

 RSTCTRL.SWRR |= (1<<0);

but on further reading of the datasheet on page 107, RSTCTRL.SWRR is under configuration Change Protection

12.3.4  Configuration Change Protection
This peripheral has registers that are under Configuration Change Protection (CCP). To write to these registers, a
certain key must first be written to the CPU.CCP register, followed by a write access to the protected bits within four
CPU instructions.
Attempting to write to a protected register without following the appropriate CCP unlock sequence leaves the
protected register unchanged.
The following registers are under CCP:
Table 12-2. RSTCTRL - Registers Under Configuration Change Protection
Register Key

So i’ve found this from Microchip, but just recognising I’m ‘out of my depth’ and can’t see how to use the information to write IOREG to CPP.

Any help much appreciated.

Well as I read the datasheet chapter 12.3.4 and the ATMega4809 headers is that what they want is


which compiles, however, may not be safe against optimization because the write to SWRR has to occur within the next 4 cycles. That’s why the Microchip and the Arduino core readme correctly say

void resetViaSWR() {

is a correct way to implement it.

Thanks again, I did think about including the line you mentioned

but couldn’t work out if that would work in the required 4 cycles. I’ll give the second method a try.