In this blog post, you will learn how to do software reset ARM Cortex-M Processor. You will also see here two techniques to Reset an ARM Cortex-M with Software.
Reset an ARM Cortex-M with Software:
At some point, you have to reset your MCU device by the software. As we know that we can reset the MCU by pressing the reset button on the board but every time manual reset is not possible.
For example, in remote FUP (firmware upgrade), we have to upgrade the application image with the bootloader (also an application) and we need to perform a reset of the microcontroller to do a restart. In that scenario, we can not press the reset button physically. We require some piece of code that reset the MCU.
Resetting the MCU devices using the piece of code is called software reset. But how to do this from the software and application running on the board, without user manual intervention? Or if we simply want to reset the system for whatever reason?
Let’s see some way to do software reset ARM Cortex-M Processor. If you have any other suggestions that would be great, I will include them in the post.
Using ARM System Reset:
A system or warm reset initializes the majority of the macrocell, excluding the NVIC debug logic, FPB (Flash Patch and Breakpoint), DWT (Data Watchpoint and Trace), and ITM (Instrumentation Trace Macrocell). System reset typically resets a system that has been operating for some time.
We can create SoftwareReset() function using the Application Interrupt and Reset Control Register, (AIRCR). But before writing the SoftwareReset function let’s see the AIRCR.
Important points related to the Application Interrupt and Reset Control Register (AIRCR):
1. The control bit SYSRESETREQ requests a reset by an external system resource. The system reset request bit is implementation-defined.
2. A single write to the AIRCR that sets both SYSRESETREQ and VECTRESET to 1 can cause unpredictable behavior.
3. For SYSRESETREQ, the architecture does not guarantee that the reset takes place immediately
Note: We need to write a 0x05FA to VECTKEY with a 1 to SYSRESETREQ.
Below mentioned program, you can use in your application for the software reset for ARM cortex M.
//Software reset ARM void SoftwareReset(void) { // generic way to request a reset //from software for ARM Cortex SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | SCB_AIRCR_SYSRESETREQ_Msk); for(;;) { /* wait until reset */ } }
If you want to learn STM32 from scratch, you should follow this course “Mastering Microcontroller with Embedded Driver Development“. The course contains video lectures of 18.5-hours length covering all topics like, Microcontroller & Peripheral Driver Development for STM32 GPIO, I2C, SPI, USART using Embedded C.
Enroll In Course
Reset using the watchdog timer:
A watchdog timer (WDT) is a hardware timer that automatically generates a system reset when the watchdog is expired. In simple words, you can say that a watchdog is based on a down counter that counts down from some initial value to zero.
Using the watchdog timer you can reset your device. It is a useful tool in helping your system recover from transient failures. You need to follow the below steps to reset the device using the watchdog timer.
- Configure the watchdog timer as per your requirement.
- Don’t refresh the watchdog timer or you can say don’t “kick the dog” when you want to reset the device.
- When the counter reaches 0, then the watchdog timer asserts the reset signal.
You can also follow this approach to reset your device but for the ARM cortex M, I will go with the first option.