A software reset is a method to reset the processor in an ARM Cortex M-based microcontroller without requiring any external hardware. It can be achieved by writing to the System Control Block (SCB) Application Interrupt and Reset Control Register (AIRCR). This register contains the security privileges, reset types and reset request bits needed to initiate a software reset.
Reasons for a Software Reset
There are several reasons why a software reset may be necessary in a Cortex M device:
- Recover from a locked-up or crashed state
- Restart the application after updating firmware
- Reset peripheral registers to default values
- Re-initialize hardware from a known clean state
Since the processor does not need to be power cycled, a software reset allows the system to reboot faster than a hardware reset. It also does not require any additional hardware and can be invoked from software at any time.
AIRCR Register
The SCB AIRCR register is a 32-bit write-only register which controls resets in the Cortex M processor. The register contains the following bitfields:
- Bits [31:16] – Vector Key: Must write 0x05FA to write to other register bits
- Bits [15:11] – Reserved
- Bits [10:8] – PRIGROUP: Interrupt priority grouping
- Bit [2] – SYSRESETREQ: Generates a system reset when set to 1
- Bits [1:0] – VECTRESET: Type of reset to perform
To generate a software reset, the VECTRESET and SYSRESETREQ bits must be set to the appropriate values while writing the key to bits [31:16].
Reset Types
There are several types of software resets that can be initiated by writing to the AIRCR register:
- VECTRESET=0b00, SYSRESETREQ=1 – Reset entire system
- VECTRESET=0b01, SYSRESETREQ=1 – Reset core only
- VECTRESET=0b10, SYSRESETREQ=1 – Reset system and core
The most common software reset uses VECTRESET=0b00 and SYSRESETREQ=1 to reset the entire system including core peripherals. This causes the processor to restart execution at the reset vector as if a hardware reset occurred.
Code Examples
Here are some examples of how to trigger a software reset from C code:
ARM GCC
/* Reset entire system */ SCB->AIRCR = 0x05FA0004; /* Reset core only */ SCB->AIRCR = 0x05FA0005;
ARM MDK
/* Reset entire system */ SCB->AIRCR = 0x05FA0004; /* Reset core only */ SCB->AIRCR = 0x05FA0005;
Reset Handlers
After a software reset occurs, code execution will resume from one of the processor’s reset handlers located in the startup code:
- Reset_Handler – Executes on a full system reset
- Default_Handler – Executes on a core only reset
These handlers are responsible for initializing hardware, setting up the stack pointer, copying .data sections to RAM, and jumping to the application entry point main().
Precautions
There are some precautions that should be taken when using software resets:
- Make sure to re-initialize hardware peripherals and RAM contents as needed
- Critical global variables may need to be re-initialized
- Code execution will start from the reset vector, not the point where reset was called
- Software resets can be privileged – check security control bits
It is also good practice to minimize the use of software resets and only use them as a last resort if the system is unrecoverable.
Summary
The SCB AIRCR register provides an easy method to reset an ARM Cortex M processor through software. Setting the VECTRESET and SYSRESETREQ bits will initiate a system, core, or full reset from code without external hardware.
Software resets are useful for recovering from crashes, restarting the application, or initializing hardware peripherals. However, care must be taken to re-initialize critical variables and hardware state when using software resets.