diff options
Diffstat (limited to 'embassy-mspm0')
| -rw-r--r-- | embassy-mspm0/CHANGELOG.md | 1 | ||||
| -rw-r--r-- | embassy-mspm0/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-mspm0/src/lib.rs | 111 |
3 files changed, 114 insertions, 2 deletions
diff --git a/embassy-mspm0/CHANGELOG.md b/embassy-mspm0/CHANGELOG.md index d9910a7ab..f0b5868f4 100644 --- a/embassy-mspm0/CHANGELOG.md +++ b/embassy-mspm0/CHANGELOG.md | |||
| @@ -18,3 +18,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
| 18 | - feat: add MSPM0H3216 support | 18 | - feat: add MSPM0H3216 support |
| 19 | - feat: Add i2c target implementation (#4605) | 19 | - feat: Add i2c target implementation (#4605) |
| 20 | - fix: group irq handlers must check for NO_INTR (#4785) | 20 | - fix: group irq handlers must check for NO_INTR (#4785) |
| 21 | - feat: Add read_reset_cause function | ||
diff --git a/embassy-mspm0/Cargo.toml b/embassy-mspm0/Cargo.toml index df6176ff6..b76bc7e41 100644 --- a/embassy-mspm0/Cargo.toml +++ b/embassy-mspm0/Cargo.toml | |||
| @@ -72,7 +72,7 @@ cortex-m = "0.7.6" | |||
| 72 | critical-section = "1.2.0" | 72 | critical-section = "1.2.0" |
| 73 | 73 | ||
| 74 | # mspm0-metapac = { version = "" } | 74 | # mspm0-metapac = { version = "" } |
| 75 | mspm0-metapac = { git = "https://github.com/mspm0-rs/mspm0-data-generated/", tag = "mspm0-data-e7de4103a0713772695ffcad52c3c2f07414dc29" } | 75 | mspm0-metapac = { git = "https://github.com/mspm0-rs/mspm0-data-generated/", tag = "mspm0-data-8542f260cc89645a983b7f1a874c87b21822279e" } |
| 76 | 76 | ||
| 77 | [build-dependencies] | 77 | [build-dependencies] |
| 78 | proc-macro2 = "1.0.94" | 78 | proc-macro2 = "1.0.94" |
| @@ -80,7 +80,7 @@ quote = "1.0.40" | |||
| 80 | cfg_aliases = "0.2.1" | 80 | cfg_aliases = "0.2.1" |
| 81 | 81 | ||
| 82 | # mspm0-metapac = { version = "", default-features = false, features = ["metadata"] } | 82 | # mspm0-metapac = { version = "", default-features = false, features = ["metadata"] } |
| 83 | mspm0-metapac = { git = "https://github.com/mspm0-rs/mspm0-data-generated/", tag = "mspm0-data-e7de4103a0713772695ffcad52c3c2f07414dc29", default-features = false, features = ["metadata"] } | 83 | mspm0-metapac = { git = "https://github.com/mspm0-rs/mspm0-data-generated/", tag = "mspm0-data-8542f260cc89645a983b7f1a874c87b21822279e", default-features = false, features = ["metadata"] } |
| 84 | 84 | ||
| 85 | [features] | 85 | [features] |
| 86 | default = ["rt"] | 86 | default = ["rt"] |
diff --git a/embassy-mspm0/src/lib.rs b/embassy-mspm0/src/lib.rs index 7135dd9f0..9f3e4d5e8 100644 --- a/embassy-mspm0/src/lib.rs +++ b/embassy-mspm0/src/lib.rs | |||
| @@ -234,3 +234,114 @@ impl Iterator for BitIter { | |||
| 234 | } | 234 | } |
| 235 | } | 235 | } |
| 236 | } | 236 | } |
| 237 | |||
| 238 | /// Reset cause values from SYSCTL.RSTCAUSE register. | ||
| 239 | /// Based on MSPM0 L-series Technical Reference Manual Table 2-9 and | ||
| 240 | /// MSPM0 G-series Technical Reference Manual Table 2-12. | ||
| 241 | #[derive(Clone, Copy, PartialEq, Eq, Debug)] | ||
| 242 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 243 | pub enum ResetCause { | ||
| 244 | /// No reset since last read | ||
| 245 | NoReset, | ||
| 246 | /// VDD < POR- violation, PMU trim parity fault, or SHUTDNSTOREx parity fault | ||
| 247 | PorHwFailure, | ||
| 248 | /// NRST pin reset (>1s) | ||
| 249 | PorExternalNrst, | ||
| 250 | /// Software-triggered POR | ||
| 251 | PorSwTriggered, | ||
| 252 | /// VDD < BOR- violation | ||
| 253 | BorSupplyFailure, | ||
| 254 | /// Wake from SHUTDOWN | ||
| 255 | BorWakeFromShutdown, | ||
| 256 | /// Non-PMU trim parity fault | ||
| 257 | #[cfg(not(any( | ||
| 258 | mspm0c110x, | ||
| 259 | mspm0c1105_c1106, | ||
| 260 | mspm0g110x, | ||
| 261 | mspm0g150x, | ||
| 262 | mspm0g151x, | ||
| 263 | mspm0g310x, | ||
| 264 | mspm0g350x, | ||
| 265 | mspm0g351x | ||
| 266 | )))] | ||
| 267 | BootrstNonPmuParityFault, | ||
| 268 | /// Fatal clock fault | ||
| 269 | BootrstClockFault, | ||
| 270 | /// Software-triggered BOOTRST | ||
| 271 | BootrstSwTriggered, | ||
| 272 | /// NRST pin reset (<1s) | ||
| 273 | BootrstExternalNrst, | ||
| 274 | /// WWDT0 violation | ||
| 275 | BootrstWwdt0Violation, | ||
| 276 | /// WWDT1 violation (G-series only) | ||
| 277 | #[cfg(any(mspm0g110x, mspm0g150x, mspm0g151x, mspm0g310x, mspm0g350x, mspm0g351x))] | ||
| 278 | SysrstWwdt1Violation, | ||
| 279 | /// BSL exit (if present) | ||
| 280 | SysrstBslExit, | ||
| 281 | /// BSL entry (if present) | ||
| 282 | SysrstBslEntry, | ||
| 283 | /// Uncorrectable flash ECC error (if present) | ||
| 284 | #[cfg(not(any(mspm0c110x, mspm0c1105_c1106, mspm0g351x, mspm0g151x)))] | ||
| 285 | SysrstFlashEccError, | ||
| 286 | /// CPU lockup violation | ||
| 287 | SysrstCpuLockupViolation, | ||
| 288 | /// Debug-triggered SYSRST | ||
| 289 | SysrstDebugTriggered, | ||
| 290 | /// Software-triggered SYSRST | ||
| 291 | SysrstSwTriggered, | ||
| 292 | /// Debug-triggered CPURST | ||
| 293 | CpurstDebugTriggered, | ||
| 294 | /// Software-triggered CPURST | ||
| 295 | CpurstSwTriggered, | ||
| 296 | } | ||
| 297 | |||
| 298 | /// Read the reset cause from the SYSCTL.RSTCAUSE register. | ||
| 299 | /// | ||
| 300 | /// This function reads the reset cause register which indicates why the last | ||
| 301 | /// system reset occurred. The register is automatically cleared after being read, | ||
| 302 | /// so this should be called only once per application startup. | ||
| 303 | /// | ||
| 304 | /// If the reset cause is not recognized, an `Err` containing the raw value is returned. | ||
| 305 | #[must_use = "Reading reset cause will clear it"] | ||
| 306 | pub fn read_reset_cause() -> Result<ResetCause, u8> { | ||
| 307 | let cause_raw = pac::SYSCTL.rstcause().read().id(); | ||
| 308 | |||
| 309 | use ResetCause::*; | ||
| 310 | use pac::sysctl::vals::Id; | ||
| 311 | |||
| 312 | match cause_raw { | ||
| 313 | Id::NORST => Ok(NoReset), | ||
| 314 | Id::PORHWFAIL => Ok(PorHwFailure), | ||
| 315 | Id::POREXNRST => Ok(PorExternalNrst), | ||
| 316 | Id::PORSW => Ok(PorSwTriggered), | ||
| 317 | Id::BORSUPPLY => Ok(BorSupplyFailure), | ||
| 318 | Id::BORWAKESHUTDN => Ok(BorWakeFromShutdown), | ||
| 319 | #[cfg(not(any( | ||
| 320 | mspm0c110x, | ||
| 321 | mspm0c1105_c1106, | ||
| 322 | mspm0g110x, | ||
| 323 | mspm0g150x, | ||
| 324 | mspm0g151x, | ||
| 325 | mspm0g310x, | ||
| 326 | mspm0g350x, | ||
| 327 | mspm0g351x | ||
| 328 | )))] | ||
| 329 | Id::BOOTNONPMUPARITY => Ok(BootrstNonPmuParityFault), | ||
| 330 | Id::BOOTCLKFAIL => Ok(BootrstClockFault), | ||
| 331 | Id::BOOTSW => Ok(BootrstSwTriggered), | ||
| 332 | Id::BOOTEXNRST => Ok(BootrstExternalNrst), | ||
| 333 | Id::BOOTWWDT0 => Ok(BootrstWwdt0Violation), | ||
| 334 | Id::SYSBSLEXIT => Ok(SysrstBslExit), | ||
| 335 | Id::SYSBSLENTRY => Ok(SysrstBslEntry), | ||
| 336 | #[cfg(any(mspm0g110x, mspm0g150x, mspm0g151x, mspm0g310x, mspm0g350x, mspm0g351x))] | ||
| 337 | Id::SYSWWDT1 => Ok(SysrstWwdt1Violation), | ||
| 338 | #[cfg(not(any(mspm0c110x, mspm0c1105_c1106, mspm0g351x, mspm0g151x)))] | ||
| 339 | Id::SYSFLASHECC => Ok(SysrstFlashEccError), | ||
| 340 | Id::SYSCPULOCK => Ok(SysrstCpuLockupViolation), | ||
| 341 | Id::SYSDBG => Ok(SysrstDebugTriggered), | ||
| 342 | Id::SYSSW => Ok(SysrstSwTriggered), | ||
| 343 | Id::CPUDBG => Ok(CpurstDebugTriggered), | ||
| 344 | Id::CPUSW => Ok(CpurstSwTriggered), | ||
| 345 | other => Err(other as u8), | ||
| 346 | } | ||
| 347 | } | ||
