aboutsummaryrefslogtreecommitdiff
path: root/embassy-mcxa/src
diff options
context:
space:
mode:
authorFelipe Balbi <[email protected]>2025-12-10 12:29:03 -0800
committerFelipe Balbi <[email protected]>2025-12-10 12:29:03 -0800
commit0a798fc533962c7094883d4ddbbf92abe621c7f3 (patch)
tree49bccb1306e363fba9a48b40525107514363d8e8 /embassy-mcxa/src
parent4915b9f530877f3db1e9c2a7813b52795b5a4ec3 (diff)
MCXA: Add a function to read Reset Reason
Diffstat (limited to 'embassy-mcxa/src')
-rw-r--r--embassy-mcxa/src/lib.rs1
-rw-r--r--embassy-mcxa/src/reset_reason.rs108
2 files changed, 109 insertions, 0 deletions
diff --git a/embassy-mcxa/src/lib.rs b/embassy-mcxa/src/lib.rs
index be279e509..7de5839be 100644
--- a/embassy-mcxa/src/lib.rs
+++ b/embassy-mcxa/src/lib.rs
@@ -17,6 +17,7 @@ pub mod i2c;
17pub mod interrupt; 17pub mod interrupt;
18pub mod lpuart; 18pub mod lpuart;
19pub mod ostimer; 19pub mod ostimer;
20pub mod reset_reason;
20pub mod rtc; 21pub mod rtc;
21 22
22pub use crate::pac::NVIC_PRIO_BITS; 23pub use crate::pac::NVIC_PRIO_BITS;
diff --git a/embassy-mcxa/src/reset_reason.rs b/embassy-mcxa/src/reset_reason.rs
new file mode 100644
index 000000000..1f5a0ec1f
--- /dev/null
+++ b/embassy-mcxa/src/reset_reason.rs
@@ -0,0 +1,108 @@
1//! Reset reason
2//!
3//! MCXA families keep the most recent reset reason in the SRS
4//! register of the CMC block. This lets users understand why the MCU
5//! has reset and take appropriate corrective actions if required.
6
7/// Reads the most recent reset reason from the Core Mode Controller
8/// (CMC).
9pub fn reset_reason() -> ResetReason {
10 critical_section::with(|_| {
11 let regs = unsafe { &*crate::pac::Cmc::steal() };
12
13 let srs = regs.srs().read();
14
15 if srs.wakeup().is_enabled() {
16 ResetReason::WakeUp
17 } else if srs.por().bit_is_set() {
18 ResetReason::Por
19 } else if srs.vd().bit_is_set() {
20 ResetReason::VoltageDetect
21 } else if srs.warm().bit_is_set() {
22 ResetReason::Warm
23 } else if srs.fatal().bit_is_set() {
24 ResetReason::Fatal
25 } else if srs.pin().bit_is_set() {
26 ResetReason::Pin
27 } else if srs.dap().bit_is_set() {
28 ResetReason::Dap
29 } else if srs.rstack().bit_is_set() {
30 ResetReason::ResetAckTimeout
31 } else if srs.lpack().bit_is_set() {
32 ResetReason::LowPowerAckTimeout
33 } else if srs.scg().bit_is_set() {
34 ResetReason::SystemClockGeneration
35 } else if srs.wwdt0().bit_is_set() {
36 ResetReason::Wwdt0
37 } else if srs.sw().bit_is_set() {
38 ResetReason::Software
39 } else if srs.lockup().bit_is_set() {
40 ResetReason::Lockup
41 } else if srs.cdog0().bit_is_set() {
42 ResetReason::Cdog0
43 } else if srs.cdog1().bit_is_set() {
44 ResetReason::Cdog1
45 } else if srs.jtag().bit_is_set() {
46 ResetReason::Jtag
47 } else {
48 ResetReason::Tamper
49 }
50 })
51}
52
53/// Indicates the type and source of the most recent reset.
54#[derive(Clone, Copy, Debug)]
55#[cfg_attr(feature = "defmt", derive(defmt::Format))]
56#[non_exhaustive]
57pub enum ResetReason {
58 /// Tamper reset.
59 Tamper,
60
61 /// JTAG System Reset request.
62 Jtag,
63
64 /// Code Watchdog 0 reset.
65 Cdog0,
66
67 /// Code Watchdog 1 reset.
68 Cdog1,
69
70 /// Lockup reset.
71 Lockup,
72
73 /// Software reset.
74 Software,
75
76 /// Windowed Watchdog 0 reset.
77 Wwdt0,
78
79 /// System clock generation reset.
80 SystemClockGeneration,
81
82 /// Low Power Acknowledge Timeout reset.
83 LowPowerAckTimeout,
84
85 /// Reset Timeout.
86 ResetAckTimeout,
87
88 /// Debug Access Port reset.
89 Dap,
90
91 /// External assertion of RESET_b pin.
92 Pin,
93
94 /// Fatal reset.
95 Fatal,
96
97 /// Warm reset.
98 Warm,
99
100 /// Voltage detect reset.
101 VoltageDetect,
102
103 /// Power-on reset.
104 Por,
105
106 /// Wake-up reset.
107 WakeUp,
108}