From 93ba2c9c95721f1fe16269f09c219b161b2969cb Mon Sep 17 00:00:00 2001 From: Siarhei B Date: Thu, 21 Aug 2025 09:32:05 +0200 Subject: [PATCH] mspm0-watchdog: add watchdog examples for all chips --- examples/mspm0c1104/src/bin/wwdt.rs | 54 +++++++++++++++++++++++++++++ examples/mspm0g3507/src/bin/wwdt.rs | 54 +++++++++++++++++++++++++++++ examples/mspm0g3519/src/bin/wwdt.rs | 54 +++++++++++++++++++++++++++++ examples/mspm0l1306/src/bin/wwdt.rs | 54 +++++++++++++++++++++++++++++ examples/mspm0l2228/src/bin/wwdt.rs | 54 +++++++++++++++++++++++++++++ 5 files changed, 270 insertions(+) create mode 100644 examples/mspm0c1104/src/bin/wwdt.rs create mode 100644 examples/mspm0g3507/src/bin/wwdt.rs create mode 100644 examples/mspm0g3519/src/bin/wwdt.rs create mode 100644 examples/mspm0l1306/src/bin/wwdt.rs create mode 100644 examples/mspm0l2228/src/bin/wwdt.rs diff --git a/examples/mspm0c1104/src/bin/wwdt.rs b/examples/mspm0c1104/src/bin/wwdt.rs new file mode 100644 index 000000000..4aa3caca9 --- /dev/null +++ b/examples/mspm0c1104/src/bin/wwdt.rs @@ -0,0 +1,54 @@ +//! Example of using window watchdog timer in the MSPM0C1104 chip. +//! +//! It tests the use case when watchdog timer is expired and when watchdog is pet too early. + +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_mspm0::gpio::{Level, Output}; +use embassy_mspm0::watchdog::{ClosedWindowPercentage, Config, Timeout, Watchdog}; +use embassy_time::Timer; +use {defmt_rtt as _, panic_halt as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + info!("Hello world!"); + + let p = embassy_mspm0::init(Default::default()); + let mut conf = Config::default(); + conf.timeout = Timeout::Sec1; + + // watchdog also resets the system if the pet comes too early, + // less than 250 msec == 25% from 1 sec + conf.closed_window = ClosedWindowPercentage::TwentyFive; + let mut wdt = Watchdog::new(p.WWDT0, conf); + info!("Started the watchdog timer"); + + let mut led1 = Output::new(p.PA0, Level::High); + led1.set_inversion(true); + Timer::after_millis(900).await; + + for _ in 1..=5 { + info!("pet watchdog"); + led1.toggle(); + wdt.pet(); + Timer::after_millis(500).await; + } + + // watchdog timeout test + info!("Stopped the pet command, device will reset in less than 1 second"); + loop { + led1.toggle(); + Timer::after_millis(500).await; + } + + // watchdog "too early" test + // info!("Device will reset when the pet comes too early"); + // loop { + // led1.toggle(); + // wdt.pet(); + // Timer::after_millis(200).await; + // } +} diff --git a/examples/mspm0g3507/src/bin/wwdt.rs b/examples/mspm0g3507/src/bin/wwdt.rs new file mode 100644 index 000000000..6d3240ff7 --- /dev/null +++ b/examples/mspm0g3507/src/bin/wwdt.rs @@ -0,0 +1,54 @@ +//! Example of using window watchdog timer in the MSPM0G3507 chip. +//! +//! It tests the use case when watchdog timer is expired and when watchdog is pet too early. + +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_mspm0::gpio::{Level, Output}; +use embassy_mspm0::watchdog::{ClosedWindowPercentage, Config, Timeout, Watchdog}; +use embassy_time::Timer; +use {defmt_rtt as _, panic_halt as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + info!("Hello world!"); + + let p = embassy_mspm0::init(Default::default()); + let mut conf = Config::default(); + conf.timeout = Timeout::Sec1; + + // watchdog also resets the system if the pet comes too early, + // less than 250 msec == 25% from 1 sec + conf.closed_window = ClosedWindowPercentage::TwentyFive; + let mut wdt = Watchdog::new(p.WWDT0, conf); + info!("Started the watchdog timer"); + + let mut led1 = Output::new(p.PA0, Level::High); + led1.set_inversion(true); + Timer::after_millis(900).await; + + for _ in 1..=5 { + info!("pet watchdog"); + led1.toggle(); + wdt.pet(); + Timer::after_millis(500).await; + } + + // watchdog timeout test + info!("Stopped the pet command, device will reset in less than 1 second"); + loop { + led1.toggle(); + Timer::after_millis(500).await; + } + + // watchdog "too early" test + // info!("Device will reset when the pet comes too early"); + // loop { + // led1.toggle(); + // wdt.pet(); + // Timer::after_millis(200).await; + // } +} diff --git a/examples/mspm0g3519/src/bin/wwdt.rs b/examples/mspm0g3519/src/bin/wwdt.rs new file mode 100644 index 000000000..dee941274 --- /dev/null +++ b/examples/mspm0g3519/src/bin/wwdt.rs @@ -0,0 +1,54 @@ +//! Example of using window watchdog timer in the MSPM0G3519 chip. +//! +//! It tests the use case when watchdog timer is expired and when watchdog is pet too early. + +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_mspm0::gpio::{Level, Output}; +use embassy_mspm0::watchdog::{ClosedWindowPercentage, Config, Timeout, Watchdog}; +use embassy_time::Timer; +use {defmt_rtt as _, panic_halt as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + info!("Hello world!"); + + let p = embassy_mspm0::init(Default::default()); + let mut conf = Config::default(); + conf.timeout = Timeout::Sec1; + + // watchdog also resets the system if the pet comes too early, + // less than 250 msec == 25% from 1 sec + conf.closed_window = ClosedWindowPercentage::TwentyFive; + let mut wdt = Watchdog::new(p.WWDT0, conf); + info!("Started the watchdog timer"); + + let mut led1 = Output::new(p.PA0, Level::High); + led1.set_inversion(true); + Timer::after_millis(900).await; + + for _ in 1..=5 { + info!("pet watchdog"); + led1.toggle(); + wdt.pet(); + Timer::after_millis(500).await; + } + + // watchdog timeout test + info!("Stopped the pet command, device will reset in less than 1 second"); + loop { + led1.toggle(); + Timer::after_millis(500).await; + } + + // watchdog "too early" test + // info!("Device will reset when the pet comes too early"); + // loop { + // led1.toggle(); + // wdt.pet(); + // Timer::after_millis(200).await; + // } +} diff --git a/examples/mspm0l1306/src/bin/wwdt.rs b/examples/mspm0l1306/src/bin/wwdt.rs new file mode 100644 index 000000000..f2bbe5701 --- /dev/null +++ b/examples/mspm0l1306/src/bin/wwdt.rs @@ -0,0 +1,54 @@ +//! Example of using window watchdog timer in the MSPM0L1306 chip. +//! +//! It tests the use case when watchdog timer is expired and when watchdog is pet too early. + +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_mspm0::gpio::{Level, Output}; +use embassy_mspm0::watchdog::{ClosedWindowPercentage, Config, Timeout, Watchdog}; +use embassy_time::Timer; +use {defmt_rtt as _, panic_halt as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + info!("Hello world!"); + + let p = embassy_mspm0::init(Default::default()); + let mut conf = Config::default(); + conf.timeout = Timeout::Sec1; + + // watchdog also resets the system if the pet comes too early, + // less than 250 msec == 25% from 1 sec + conf.closed_window = ClosedWindowPercentage::TwentyFive; + let mut wdt = Watchdog::new(p.WWDT0, conf); + info!("Started the watchdog timer"); + + let mut led1 = Output::new(p.PA0, Level::High); + led1.set_inversion(true); + Timer::after_millis(900).await; + + for _ in 1..=5 { + info!("pet watchdog"); + led1.toggle(); + wdt.pet(); + Timer::after_millis(500).await; + } + + // watchdog timeout test + info!("Stopped the pet command, device will reset in less than 1 second"); + loop { + led1.toggle(); + Timer::after_millis(500).await; + } + + // watchdog "too early" test + // info!("Device will reset when the pet comes too early"); + // loop { + // led1.toggle(); + // wdt.pet(); + // Timer::after_millis(200).await; + // } +} diff --git a/examples/mspm0l2228/src/bin/wwdt.rs b/examples/mspm0l2228/src/bin/wwdt.rs new file mode 100644 index 000000000..6fd18247a --- /dev/null +++ b/examples/mspm0l2228/src/bin/wwdt.rs @@ -0,0 +1,54 @@ +//! Example of using window watchdog timer in the MSPM0L2228 chip. +//! +//! It tests the use case when watchdog timer is expired and when watchdog is pet too early. + +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_mspm0::gpio::{Level, Output}; +use embassy_mspm0::watchdog::{ClosedWindowPercentage, Config, Timeout, Watchdog}; +use embassy_time::Timer; +use {defmt_rtt as _, panic_halt as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + info!("Hello world!"); + + let p = embassy_mspm0::init(Default::default()); + let mut conf = Config::default(); + conf.timeout = Timeout::Sec1; + + // watchdog also resets the system if the pet comes too early, + // less than 250 msec == 25% from 1 sec + conf.closed_window = ClosedWindowPercentage::TwentyFive; + let mut wdt = Watchdog::new(p.WWDT0, conf); + info!("Started the watchdog timer"); + + let mut led1 = Output::new(p.PA0, Level::High); + led1.set_inversion(true); + Timer::after_millis(900).await; + + for _ in 1..=5 { + info!("pet watchdog"); + led1.toggle(); + wdt.pet(); + Timer::after_millis(500).await; + } + + // watchdog timeout test + info!("Stopped the pet command, device will reset in less than 1 second"); + loop { + led1.toggle(); + Timer::after_millis(500).await; + } + + // watchdog "too early" test + // info!("Device will reset when the pet comes too early"); + // loop { + // led1.toggle(); + // wdt.pet(); + // Timer::after_millis(200).await; + // } +}