diff options
Diffstat (limited to 'examples/mspm0l1306')
| -rw-r--r-- | examples/mspm0l1306/Cargo.toml | 26 | ||||
| -rw-r--r-- | examples/mspm0l1306/README.md | 4 | ||||
| -rw-r--r-- | examples/mspm0l1306/build.rs | 2 | ||||
| -rw-r--r-- | examples/mspm0l1306/src/bin/i2c.rs | 45 | ||||
| -rw-r--r-- | examples/mspm0l1306/src/bin/i2c_async.rs | 50 | ||||
| -rw-r--r-- | examples/mspm0l1306/src/bin/wwdt.rs | 54 |
6 files changed, 171 insertions, 10 deletions
diff --git a/examples/mspm0l1306/Cargo.toml b/examples/mspm0l1306/Cargo.toml index 609b3f205..8100e11da 100644 --- a/examples/mspm0l1306/Cargo.toml +++ b/examples/mspm0l1306/Cargo.toml | |||
| @@ -3,19 +3,29 @@ edition = "2021" | |||
| 3 | name = "embassy-mspm0-l1306-examples" | 3 | name = "embassy-mspm0-l1306-examples" |
| 4 | version = "0.1.0" | 4 | version = "0.1.0" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | publish = false | ||
| 6 | 7 | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | embassy-mspm0 = { version = "0.1.0", path = "../../embassy-mspm0", features = ["mspm0l130x", "defmt", "rt", "time-driver-any"] } | 9 | embassy-mspm0 = { version = "0.1.0", path = "../../embassy-mspm0", features = ["mspm0l1306rhb", "defmt", "rt", "time-driver-any"] } |
| 9 | embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt"] } | 10 | embassy-executor = { version = "0.9.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt"] } |
| 10 | embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = ["defmt"] } | 11 | embassy-sync = { version = "0.7.2", path = "../../embassy-sync", features = ["defmt"] } |
| 11 | embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt"] } | 12 | embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt"] } |
| 12 | panic-halt = "0.2.0" | 13 | panic-halt = "1.0.0" |
| 13 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | 14 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } |
| 14 | cortex-m-rt = { version = "0.7.0"} | 15 | cortex-m-rt = { version = "0.7.0"} |
| 15 | defmt = "0.3" | 16 | defmt = "1.0.1" |
| 16 | defmt-rtt = "0.4" | 17 | defmt-rtt = "1.0.0" |
| 17 | panic-probe = { version = "0.3.2", features = ["print-defmt"] } | 18 | panic-probe = { version = "1.0.0", features = ["print-defmt"] } |
| 18 | panic-semihosting = "0.6.0" | 19 | panic-semihosting = "0.6.0" |
| 19 | 20 | ||
| 20 | [profile.release] | 21 | [profile.release] |
| 21 | debug = 2 | 22 | debug = 2 |
| 23 | |||
| 24 | [profile.dev] | ||
| 25 | debug = 2 | ||
| 26 | opt-level = 2 | ||
| 27 | |||
| 28 | [package.metadata.embassy] | ||
| 29 | build = [ | ||
| 30 | { target = "thumbv6m-none-eabi", artifact-dir = "out/examples/mspm0l1306" } | ||
| 31 | ] | ||
diff --git a/examples/mspm0l1306/README.md b/examples/mspm0l1306/README.md index 5a55d721e..4d698e0fa 100644 --- a/examples/mspm0l1306/README.md +++ b/examples/mspm0l1306/README.md | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # Examples for MSPM0L130x family | 1 | # Examples for MSPM0L1306 |
| 2 | 2 | ||
| 3 | Run individual examples with | 3 | Run individual examples with |
| 4 | ``` | 4 | ``` |
| @@ -15,7 +15,7 @@ A large number of the examples are written for the [LP-MSPM0L1306](https://www.t | |||
| 15 | You might need to adjust `.cargo/config.toml`, `Cargo.toml` and possibly update pin numbers or peripherals to match the specific MCU or board you are using. | 15 | You might need to adjust `.cargo/config.toml`, `Cargo.toml` and possibly update pin numbers or peripherals to match the specific MCU or board you are using. |
| 16 | 16 | ||
| 17 | * [ ] Update .cargo/config.toml with the correct probe-rs command to use your specific MCU. For example for L1306 it should be `probe-rs run --chip MSPM0L1306`. (use `probe-rs chip list` to find your chip) | 17 | * [ ] Update .cargo/config.toml with the correct probe-rs command to use your specific MCU. For example for L1306 it should be `probe-rs run --chip MSPM0L1306`. (use `probe-rs chip list` to find your chip) |
| 18 | * [ ] Update Cargo.toml to have the correct `embassy-mspm0` feature. For example for L1306 it should be `mspm0l1306`. Look in the `Cargo.toml` file of the `embassy-mspm0` project to find the correct feature flag for your chip. | 18 | * [ ] Update Cargo.toml to have the correct `embassy-mspm0` feature. For the LP-MSPM0L1306 it should be `mspm0l1306rhb`. Look in the `Cargo.toml` file of the `embassy-mspm0` project to find the correct feature flag for your chip. |
| 19 | * [ ] If your board has a special clock or power configuration, make sure that it is set up appropriately. | 19 | * [ ] If your board has a special clock or power configuration, make sure that it is set up appropriately. |
| 20 | * [ ] If your board has different pin mapping, update any pin numbers or peripherals in the given example code to match your schematic | 20 | * [ ] If your board has different pin mapping, update any pin numbers or peripherals in the given example code to match your schematic |
| 21 | 21 | ||
diff --git a/examples/mspm0l1306/build.rs b/examples/mspm0l1306/build.rs index 30691aa97..2d777c2d3 100644 --- a/examples/mspm0l1306/build.rs +++ b/examples/mspm0l1306/build.rs | |||
| @@ -32,4 +32,6 @@ fn main() { | |||
| 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); | 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); |
| 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); |
| 34 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | 34 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); |
| 35 | // You must tell cargo to link interrupt groups if the rt feature is enabled. | ||
| 36 | println!("cargo:rustc-link-arg-bins=-Tinterrupt_group.x"); | ||
| 35 | } | 37 | } |
diff --git a/examples/mspm0l1306/src/bin/i2c.rs b/examples/mspm0l1306/src/bin/i2c.rs new file mode 100644 index 000000000..e8801c485 --- /dev/null +++ b/examples/mspm0l1306/src/bin/i2c.rs | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | //! This example uses FIFO with polling, and the maximum FIFO size is 8. | ||
| 2 | //! Refer to async example to handle larger packets. | ||
| 3 | //! | ||
| 4 | //! This example controls AD5171 digital potentiometer via I2C with the LP-MSPM0L1306 board. | ||
| 5 | |||
| 6 | #![no_std] | ||
| 7 | #![no_main] | ||
| 8 | |||
| 9 | use defmt::*; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_mspm0::i2c::{Config, I2c}; | ||
| 12 | use embassy_time::Timer; | ||
| 13 | use {defmt_rtt as _, panic_halt as _}; | ||
| 14 | |||
| 15 | const ADDRESS: u8 = 0x2c; | ||
| 16 | |||
| 17 | #[embassy_executor::main] | ||
| 18 | async fn main(_spawner: Spawner) -> ! { | ||
| 19 | let p = embassy_mspm0::init(Default::default()); | ||
| 20 | |||
| 21 | let instance = p.I2C0; | ||
| 22 | let scl = p.PA1; | ||
| 23 | let sda = p.PA0; | ||
| 24 | |||
| 25 | let mut i2c = unwrap!(I2c::new_blocking(instance, scl, sda, Config::default())); | ||
| 26 | |||
| 27 | let mut pot_value: u8 = 0; | ||
| 28 | |||
| 29 | loop { | ||
| 30 | let to_write = [0u8, pot_value]; | ||
| 31 | |||
| 32 | match i2c.blocking_write(ADDRESS, &to_write) { | ||
| 33 | Ok(()) => info!("New potentioemter value: {}", pot_value), | ||
| 34 | Err(e) => error!("I2c Error: {:?}", e), | ||
| 35 | } | ||
| 36 | |||
| 37 | pot_value += 1; | ||
| 38 | // if reached 64th position (max) | ||
| 39 | // start over from lowest value | ||
| 40 | if pot_value == 64 { | ||
| 41 | pot_value = 0; | ||
| 42 | } | ||
| 43 | Timer::after_millis(500).await; | ||
| 44 | } | ||
| 45 | } | ||
diff --git a/examples/mspm0l1306/src/bin/i2c_async.rs b/examples/mspm0l1306/src/bin/i2c_async.rs new file mode 100644 index 000000000..c4a6938ff --- /dev/null +++ b/examples/mspm0l1306/src/bin/i2c_async.rs | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | //! The example uses FIFO and interrupts, wrapped in async API. | ||
| 2 | //! | ||
| 3 | //! This example controls AD5171 digital potentiometer via I2C with the LP-MSPM0L1306 board. | ||
| 4 | |||
| 5 | #![no_std] | ||
| 6 | #![no_main] | ||
| 7 | |||
| 8 | use defmt::*; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_mspm0::bind_interrupts; | ||
| 11 | use embassy_mspm0::i2c::{Config, I2c, InterruptHandler}; | ||
| 12 | use embassy_mspm0::peripherals::I2C0; | ||
| 13 | use embassy_time::Timer; | ||
| 14 | use {defmt_rtt as _, panic_halt as _}; | ||
| 15 | |||
| 16 | const ADDRESS: u8 = 0x6a; | ||
| 17 | |||
| 18 | bind_interrupts!(struct Irqs { | ||
| 19 | I2C0 => InterruptHandler<I2C0>; | ||
| 20 | }); | ||
| 21 | |||
| 22 | #[embassy_executor::main] | ||
| 23 | async fn main(_spawner: Spawner) -> ! { | ||
| 24 | let p = embassy_mspm0::init(Default::default()); | ||
| 25 | |||
| 26 | let instance = p.I2C0; | ||
| 27 | let scl = p.PA1; | ||
| 28 | let sda = p.PA0; | ||
| 29 | |||
| 30 | let mut i2c = unwrap!(I2c::new_async(instance, scl, sda, Irqs, Config::default())); | ||
| 31 | |||
| 32 | let mut pot_value: u8 = 0; | ||
| 33 | |||
| 34 | loop { | ||
| 35 | let to_write = [0u8, pot_value]; | ||
| 36 | |||
| 37 | match i2c.async_write(ADDRESS, &to_write).await { | ||
| 38 | Ok(()) => info!("New potentioemter value: {}", pot_value), | ||
| 39 | Err(e) => error!("I2c Error: {:?}", e), | ||
| 40 | } | ||
| 41 | |||
| 42 | pot_value += 1; | ||
| 43 | // if reached 64th position (max) | ||
| 44 | // start over from lowest value | ||
| 45 | if pot_value == 64 { | ||
| 46 | pot_value = 0; | ||
| 47 | } | ||
| 48 | Timer::after_millis(500).await; | ||
| 49 | } | ||
| 50 | } | ||
diff --git a/examples/mspm0l1306/src/bin/wwdt.rs b/examples/mspm0l1306/src/bin/wwdt.rs new file mode 100644 index 000000000..b8fb1a1cd --- /dev/null +++ b/examples/mspm0l1306/src/bin/wwdt.rs | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | //! Example of using window watchdog timer in the MSPM0L1306 chip. | ||
| 2 | //! | ||
| 3 | //! It tests the use case when watchdog timer is expired and when watchdog is pet too early. | ||
| 4 | |||
| 5 | #![no_std] | ||
| 6 | #![no_main] | ||
| 7 | |||
| 8 | use defmt::*; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_mspm0::gpio::{Level, Output}; | ||
| 11 | use embassy_mspm0::wwdt::{ClosedWindowPercentage, Config, Timeout, Watchdog}; | ||
| 12 | use embassy_time::Timer; | ||
| 13 | use {defmt_rtt as _, panic_halt as _}; | ||
| 14 | |||
| 15 | #[embassy_executor::main] | ||
| 16 | async fn main(_spawner: Spawner) -> ! { | ||
| 17 | info!("Hello world!"); | ||
| 18 | |||
| 19 | let p = embassy_mspm0::init(Default::default()); | ||
| 20 | let mut conf = Config::default(); | ||
| 21 | conf.timeout = Timeout::Sec1; | ||
| 22 | |||
| 23 | // watchdog also resets the system if the pet comes too early, | ||
| 24 | // less than 250 msec == 25% from 1 sec | ||
| 25 | conf.closed_window = ClosedWindowPercentage::TwentyFive; | ||
| 26 | let mut wdt = Watchdog::new(p.WWDT0, conf); | ||
| 27 | info!("Started the watchdog timer"); | ||
| 28 | |||
| 29 | let mut led1 = Output::new(p.PA0, Level::High); | ||
| 30 | led1.set_inversion(true); | ||
| 31 | Timer::after_millis(900).await; | ||
| 32 | |||
| 33 | for _ in 1..=5 { | ||
| 34 | info!("pet watchdog"); | ||
| 35 | led1.toggle(); | ||
| 36 | wdt.pet(); | ||
| 37 | Timer::after_millis(500).await; | ||
| 38 | } | ||
| 39 | |||
| 40 | // watchdog timeout test | ||
| 41 | info!("Stopped the pet command, device will reset in less than 1 second"); | ||
| 42 | loop { | ||
| 43 | led1.toggle(); | ||
| 44 | Timer::after_millis(500).await; | ||
| 45 | } | ||
| 46 | |||
| 47 | // watchdog "too early" test | ||
| 48 | // info!("Device will reset when the pet comes too early"); | ||
| 49 | // loop { | ||
| 50 | // led1.toggle(); | ||
| 51 | // wdt.pet(); | ||
| 52 | // Timer::after_millis(200).await; | ||
| 53 | // } | ||
| 54 | } | ||
