aboutsummaryrefslogtreecommitdiff
path: root/embassy-mspm0/src/lib.rs
diff options
context:
space:
mode:
authorRaul Alimbekov <[email protected]>2025-12-16 09:05:22 +0300
committerGitHub <[email protected]>2025-12-16 09:05:22 +0300
commitc9a04b4b732b7a3b696eb8223664c1a7942b1875 (patch)
tree6dbe5c02e66eed8d8762f13f95afd24f8db2b38c /embassy-mspm0/src/lib.rs
parentcde24a3ef1117653ba5ed4184102b33f745782fb (diff)
parent5ae6e060ec1c90561719aabdc29d5b6e7b8b0a82 (diff)
Merge branch 'main' into main
Diffstat (limited to 'embassy-mspm0/src/lib.rs')
-rw-r--r--embassy-mspm0/src/lib.rs129
1 files changed, 124 insertions, 5 deletions
diff --git a/embassy-mspm0/src/lib.rs b/embassy-mspm0/src/lib.rs
index 13f0ce662..548fb33ca 100644
--- a/embassy-mspm0/src/lib.rs
+++ b/embassy-mspm0/src/lib.rs
@@ -1,4 +1,5 @@
1#![no_std] 1#![no_std]
2#![allow(unsafe_op_in_unsafe_fn)]
2// Doc feature labels can be tested locally by running RUSTDOCFLAGS="--cfg=docsrs" cargo +nightly doc 3// Doc feature labels can be tested locally by running RUSTDOCFLAGS="--cfg=docsrs" cargo +nightly doc
3#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg_hide), doc(cfg_hide(doc, docsrs)))] 4#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg_hide), doc(cfg_hide(doc, docsrs)))]
4#![cfg_attr( 5#![cfg_attr(
@@ -7,17 +8,23 @@
7)] 8)]
8#![doc = include_str!("../README.md")] 9#![doc = include_str!("../README.md")]
9 10
10// This mod MUST go first, so that the others see its macros. 11// These mods MUST go first, so that the others see the macros.
11pub(crate) mod fmt; 12pub(crate) mod fmt;
12
13// This must be declared early as well for
14mod macros; 13mod macros;
15 14
16pub mod adc; 15pub mod adc;
17pub mod dma; 16pub mod dma;
18pub mod gpio; 17pub mod gpio;
18// TODO: I2C unicomm
19#[cfg(not(unicomm))]
19pub mod i2c; 20pub mod i2c;
21#[cfg(not(unicomm))]
22pub mod i2c_target;
23#[cfg(any(mspm0g150x, mspm0g151x, mspm0g350x, mspm0g351x))]
24pub mod mathacl;
20pub mod timer; 25pub mod timer;
26// TODO: UART unicomm
27#[cfg(not(unicomm))]
21pub mod uart; 28pub mod uart;
22pub mod wwdt; 29pub mod wwdt;
23 30
@@ -54,7 +61,7 @@ pub(crate) mod _generated {
54 61
55// Reexports 62// Reexports
56pub(crate) use _generated::gpio_pincm; 63pub(crate) use _generated::gpio_pincm;
57pub use _generated::{peripherals, Peripherals}; 64pub use _generated::{Peripherals, peripherals};
58pub use embassy_hal_internal::Peri; 65pub use embassy_hal_internal::Peri;
59#[cfg(feature = "unstable-pac")] 66#[cfg(feature = "unstable-pac")]
60pub use mspm0_metapac as pac; 67pub use mspm0_metapac as pac;
@@ -111,7 +118,7 @@ macro_rules! bind_interrupts {
111 118
112 $( 119 $(
113 #[allow(non_snake_case)] 120 #[allow(non_snake_case)]
114 #[no_mangle] 121 #[unsafe(no_mangle)]
115 $(#[cfg($cond_irq)])? 122 $(#[cfg($cond_irq)])?
116 unsafe extern "C" fn $irq() { 123 unsafe extern "C" fn $irq() {
117 unsafe { 124 unsafe {
@@ -232,3 +239,115 @@ impl Iterator for BitIter {
232 } 239 }
233 } 240 }
234} 241}
242
243/// Reset cause values from SYSCTL.RSTCAUSE register.
244/// Based on MSPM0 L-series Technical Reference Manual Table 2-9 and
245/// MSPM0 G-series Technical Reference Manual Table 2-12.
246#[derive(Clone, Copy, PartialEq, Eq, Debug)]
247#[cfg_attr(feature = "defmt", derive(defmt::Format))]
248pub enum ResetCause {
249 /// No reset since last read
250 NoReset,
251 /// VDD < POR- violation, PMU trim parity fault, or SHUTDNSTOREx parity fault
252 PorHwFailure,
253 /// NRST pin reset (>1s)
254 PorExternalNrst,
255 /// Software-triggered POR
256 PorSwTriggered,
257 /// VDD < BOR- violation
258 BorSupplyFailure,
259 /// Wake from SHUTDOWN
260 BorWakeFromShutdown,
261 /// Non-PMU trim parity fault
262 #[cfg(not(any(
263 mspm0c110x,
264 mspm0c1105_c1106,
265 mspm0g110x,
266 mspm0g150x,
267 mspm0g151x,
268 mspm0g310x,
269 mspm0g350x,
270 mspm0g351x
271 )))]
272 BootrstNonPmuParityFault,
273 /// Fatal clock fault
274 BootrstClockFault,
275 /// Software-triggered BOOTRST
276 BootrstSwTriggered,
277 /// NRST pin reset (<1s)
278 BootrstExternalNrst,
279 /// WWDT0 violation
280 BootrstWwdt0Violation,
281 /// WWDT1 violation (G-series only)
282 #[cfg(any(mspm0g110x, mspm0g150x, mspm0g151x, mspm0g310x, mspm0g350x, mspm0g351x, mspm0g518x))]
283 SysrstWwdt1Violation,
284 /// BSL exit (if present)
285 SysrstBslExit,
286 /// BSL entry (if present)
287 SysrstBslEntry,
288 /// Uncorrectable flash ECC error (if present)
289 #[cfg(not(any(mspm0c110x, mspm0c1105_c1106, mspm0g351x, mspm0g151x)))]
290 SysrstFlashEccError,
291 /// CPU lockup violation
292 SysrstCpuLockupViolation,
293 /// Debug-triggered SYSRST
294 SysrstDebugTriggered,
295 /// Software-triggered SYSRST
296 SysrstSwTriggered,
297 /// Debug-triggered CPURST
298 CpurstDebugTriggered,
299 /// Software-triggered CPURST
300 CpurstSwTriggered,
301}
302
303/// Read the reset cause from the SYSCTL.RSTCAUSE register.
304///
305/// This function reads the reset cause register which indicates why the last
306/// system reset occurred. The register is automatically cleared after being read,
307/// so this should be called only once per application startup.
308///
309/// If the reset cause is not recognized, an `Err` containing the raw value is returned.
310#[must_use = "Reading reset cause will clear it"]
311pub fn read_reset_cause() -> Result<ResetCause, u8> {
312 let cause_raw = pac::SYSCTL.rstcause().read().id();
313
314 use ResetCause::*;
315 use pac::sysctl::vals::Id;
316
317 match cause_raw {
318 Id::NORST => Ok(NoReset),
319 Id::PORHWFAIL => Ok(PorHwFailure),
320 Id::POREXNRST => Ok(PorExternalNrst),
321 Id::PORSW => Ok(PorSwTriggered),
322 Id::BORSUPPLY => Ok(BorSupplyFailure),
323 Id::BORWAKESHUTDN => Ok(BorWakeFromShutdown),
324 #[cfg(not(any(
325 mspm0c110x,
326 mspm0c1105_c1106,
327 mspm0g110x,
328 mspm0g150x,
329 mspm0g151x,
330 mspm0g310x,
331 mspm0g350x,
332 mspm0g351x,
333 mspm0g518x,
334 )))]
335 Id::BOOTNONPMUPARITY => Ok(BootrstNonPmuParityFault),
336 Id::BOOTCLKFAIL => Ok(BootrstClockFault),
337 Id::BOOTSW => Ok(BootrstSwTriggered),
338 Id::BOOTEXNRST => Ok(BootrstExternalNrst),
339 Id::BOOTWWDT0 => Ok(BootrstWwdt0Violation),
340 Id::SYSBSLEXIT => Ok(SysrstBslExit),
341 Id::SYSBSLENTRY => Ok(SysrstBslEntry),
342 #[cfg(any(mspm0g110x, mspm0g150x, mspm0g151x, mspm0g310x, mspm0g350x, mspm0g351x, mspm0g518x))]
343 Id::SYSWWDT1 => Ok(SysrstWwdt1Violation),
344 #[cfg(not(any(mspm0c110x, mspm0c1105_c1106, mspm0g351x, mspm0g151x)))]
345 Id::SYSFLASHECC => Ok(SysrstFlashEccError),
346 Id::SYSCPULOCK => Ok(SysrstCpuLockupViolation),
347 Id::SYSDBG => Ok(SysrstDebugTriggered),
348 Id::SYSSW => Ok(SysrstSwTriggered),
349 Id::CPUDBG => Ok(CpurstDebugTriggered),
350 Id::CPUSW => Ok(CpurstSwTriggered),
351 other => Err(other as u8),
352 }
353}