|

|  How to implement a soft reset using C on ARM Cortex-M without triggering a watchdog?

How to implement a soft reset using C on ARM Cortex-M without triggering a watchdog?

October 14, 2024

Learn to perform a soft reset on ARM Cortex-M using C, bypassing the watchdog. A must-read guide for firmware developers seeking efficient reset techniques.

How to implement a soft reset using C on ARM Cortex-M without triggering a watchdog?

 

Understanding Soft Reset on ARM Cortex-M

 

A soft reset on an ARM Cortex-M microcontroller is essentially a way to restart the processor through software control without resorting to hardware solutions like toggling a reset pin. Implementing such a reset involves re-initializing the microcontroller's state to mimic a power-on without actually turning off the power. This process can usually be done without triggering a watchdog timer, which might otherwise reset the system if it thinks the system has become unresponsive.

 

Why Avoid Triggering a Watchdog?

 

  • The watchdog timer is designed to detect sysfailure and reset the processor. If triggered during a soft reset sequence, it can interfere with the process and might lead to unintended system behavior.
  • It’s important to properly configure and handle the watchdog during a reset to ensure that the system restarts cleanly without unintended watchdog activations.

 

Steps to Implement a Soft Reset

 

Disable Interrupts

 

  • Before performing a reset, it is crucial to disable all interrupts. This ensures that no interrupt routines interfere with the reset process.
__disable_irq();

 

Reset the Microcontroller

 

  • To initiate a software reset, you can use the System Control Block's Application Interrupt and Reset Control Register (SCB->AIRCR). This register controls whether to perform a system reset when writing to it. In particular, you will set the SYSRESETREQ bit to request a software reset.

  • Make sure to unlock the sequence by writing the key (0x5FA) to the VECTKEY field.

#include "stm32f4xx.h"  // Use specific header for the STM32 family

void SystemReset(void) {
    SCB->AIRCR  = ((0x5FA << SCB_AIRCR_VECTKEY_Pos)  |   // VECTKEY
                   (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |   // Keep priority group unchanged
                   SCB_AIRCR_SYSRESETREQ_Msk);             // Set SYSRESETREQ bit
    __DSB();                                                // Ensure all outstanding memory accesses included buffered write are completed before reset
}

 

Handling Application-Specific Tasks

 

  • Before conducting a reset, ensure any application-specific operations such as saving context, closing files, or committing data to non-volatile memory have been completed, if necessary. This will prevent data loss on reset.

  • Implement functions that handle or prepare the system for a reset without leaving the system in an undetermined state.

void PrepareForReset(void) {
    // Example: Save system state
    SaveCriticalData();
    // Example: Shut down peripherals
    ShutdownPeripherals();
}

 

Re-Enabling Interrupts

 

  • Although part of the soft reset sequence involves disabling interrupts, once the reset process begins, hardware will handle returning the system to its initial state of interrupts based on startup code settings.

 

Testing and Verification

 

  • Rigorous testing is essential to ensure the soft reset completes as expected. Check processor state, peripheral statuses, and debug for anomalies post-reset.

  • Use breakpoints and debug logs if needed to verify that the reset sequence is correct and comprehensive.

 

Conclusion

 

By correctly implementing a soft reset, your system can reboot without manual interferences or watchdog interruptions. This methodology is particularly useful in embedded systems designs where uptime is critical and manual resets are impractical. Always follow the datasheets and reference manuals of the specific ARM Cortex-M architecture you are working with, as there can be variations across different microcontrollers.

Pre-order Friend AI Necklace

Pre-Order Friend Dev Kit

Open-source AI wearable
Build using the power of recall

Order Now

OMI AI PLATFORM
Remember Every Moment,
Talk to AI and Get Feedback

Omi Necklace

The #1 Open Source AI necklace: Experiment with how you capture and manage conversations.

Build and test with your own Omi Dev Kit 2.

Omi App

Fully Open-Source AI wearable app: build and use reminders, meeting summaries, task suggestions and more. All in one simple app.

Github →

Join the #1 open-source AI wearable community

Build faster and better with 3900+ community members on Omi Discord

Participate in hackathons to expand the Omi platform and win prizes

Participate in hackathons to expand the Omi platform and win prizes

Get cash bounties, free Omi devices and priority access by taking part in community activities

Join our Discord → 

OMI NECKLACE + OMI APP
First & only open-source AI wearable platform

a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded

OMI NECKLACE: DEV KIT
Order your Omi Dev Kit 2 now and create your use cases

Omi Dev Kit 2

Endless customization

OMI DEV KIT 2

$69.99

Make your life more fun with your AI wearable clone. It gives you thoughts, personalized feedback and becomes your second brain to discuss your thoughts and feelings. Available on iOS and Android.

Your Omi will seamlessly sync with your existing omi persona, giving you a full clone of yourself – with limitless potential for use cases:

  • Real-time conversation transcription and processing;
  • Develop your own use cases for fun and productivity;
  • Hundreds of community apps to make use of your Omi Persona and conversations.

Learn more

Omi Dev Kit 2: build at a new level

Key Specs

OMI DEV KIT

OMI DEV KIT 2

Microphone

Yes

Yes

Battery

4 days (250mAH)

2 days (250mAH)

On-board memory (works without phone)

No

Yes

Speaker

No

Yes

Programmable button

No

Yes

Estimated Delivery 

-

1 week

What people say

“Helping with MEMORY,

COMMUNICATION

with business/life partner,

capturing IDEAS, and solving for

a hearing CHALLENGE."

Nathan Sudds

“I wish I had this device

last summer

to RECORD

A CONVERSATION."

Chris Y.

“Fixed my ADHD and

helped me stay

organized."

David Nigh

OMI NECKLACE: DEV KIT
Take your brain to the next level

LATEST NEWS
Follow and be first in the know

Latest news
FOLLOW AND BE FIRST IN THE KNOW

thought to action

team@basedhardware.com

company

careers

invest

privacy

products

omi

omi dev kit

personas

resources

apps

affiliate

docs

github

help