diff options
| author | i509VCB <[email protected]> | 2025-03-13 22:10:45 -0500 |
|---|---|---|
| committer | i509VCB <[email protected]> | 2025-03-13 22:10:45 -0500 |
| commit | e0cdc356ccd7f9e20c2b5355cc52b7eb7610147b (patch) | |
| tree | 0c34424508b1ee8d5010dc186247b72fac7aca69 /examples/mspm0c1104 | |
| parent | 38f26137fc67beb874aa73c9a7ab2150d9f3d372 (diff) | |
Embassy for MSPM0
This adds an embassy hal for the Texas Instruments MSPM0 microcontroller series.
So far the GPIO and time drivers have been implemented. I have tested these drivers on the following parts:
- C1104
- L1306
- L2228
- G3507
- G3519
The PAC is generated at https://github.com/mspm0-rs
Diffstat (limited to 'examples/mspm0c1104')
| -rw-r--r-- | examples/mspm0c1104/.cargo/config.toml | 11 | ||||
| -rw-r--r-- | examples/mspm0c1104/Cargo.toml | 32 | ||||
| -rw-r--r-- | examples/mspm0c1104/README.md | 27 | ||||
| -rw-r--r-- | examples/mspm0c1104/build.rs | 35 | ||||
| -rw-r--r-- | examples/mspm0c1104/memory.x | 5 | ||||
| -rw-r--r-- | examples/mspm0c1104/src/bin/blinky.rs | 27 | ||||
| -rw-r--r-- | examples/mspm0c1104/src/bin/button.rs | 35 |
7 files changed, 172 insertions, 0 deletions
diff --git a/examples/mspm0c1104/.cargo/config.toml b/examples/mspm0c1104/.cargo/config.toml new file mode 100644 index 000000000..204a56b1c --- /dev/null +++ b/examples/mspm0c1104/.cargo/config.toml | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 2 | # replace MSPM0C1104 with your chip as listed in `probe-rs chip list` | ||
| 3 | runner = "probe-rs run --chip MSPM0C1104 --protocol=swd" | ||
| 4 | |||
| 5 | [build] | ||
| 6 | target = "thumbv6m-none-eabi" | ||
| 7 | |||
| 8 | [env] | ||
| 9 | DEFMT_LOG = "debug" | ||
| 10 | # defmt's buffer needs to be shrunk since the MSPM0C1104 only has 1KB of ram. | ||
| 11 | DEFMT_RTT_BUFFER_SIZE = "72" | ||
diff --git a/examples/mspm0c1104/Cargo.toml b/examples/mspm0c1104/Cargo.toml new file mode 100644 index 000000000..35c9b1358 --- /dev/null +++ b/examples/mspm0c1104/Cargo.toml | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | [package] | ||
| 2 | edition = "2021" | ||
| 3 | name = "embassy-mspm0-c1104-examples" | ||
| 4 | version = "0.1.0" | ||
| 5 | license = "MIT OR Apache-2.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | embassy-mspm0 = { version = "0.1.0", path = "../../embassy-mspm0", features = ["mspm0c110x", "rt", "time-driver-any"] } | ||
| 9 | embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["task-arena-size-128", "arch-cortex-m", "executor-thread", "executor-interrupt"] } | ||
| 10 | embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = ["defmt"] } | ||
| 11 | embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt"] } | ||
| 12 | panic-halt = "0.2.0" | ||
| 13 | cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] } | ||
| 14 | cortex-m-rt = { version = "0.7.0"} | ||
| 15 | defmt = "0.3" | ||
| 16 | defmt-rtt = "0.4" | ||
| 17 | panic-probe = { version = "0.3.2", features = ["print-defmt"] } | ||
| 18 | panic-semihosting = "0.6.0" | ||
| 19 | |||
| 20 | # The chip only has 1KB of ram, so we must optimize binaries regardless | ||
| 21 | [profile.dev] | ||
| 22 | debug = 2 | ||
| 23 | opt-level = "z" | ||
| 24 | lto = true | ||
| 25 | codegen-units = 1 | ||
| 26 | # strip = true | ||
| 27 | |||
| 28 | [profile.release] | ||
| 29 | debug = 2 | ||
| 30 | opt-level = "z" | ||
| 31 | lto = true | ||
| 32 | codegen-units = 1 | ||
diff --git a/examples/mspm0c1104/README.md b/examples/mspm0c1104/README.md new file mode 100644 index 000000000..e5c9f961d --- /dev/null +++ b/examples/mspm0c1104/README.md | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | # Examples for MSPM0C110x family | ||
| 2 | |||
| 3 | Run individual examples with | ||
| 4 | ``` | ||
| 5 | cargo run --bin <module-name> | ||
| 6 | ``` | ||
| 7 | for example | ||
| 8 | ``` | ||
| 9 | cargo run --bin blinky | ||
| 10 | ``` | ||
| 11 | |||
| 12 | ## Checklist before running examples | ||
| 13 | A large number of the examples are written for the [LP-MSPM0C1104](https://www.ti.com/tool/LP-MSPM0C1104) board. | ||
| 14 | |||
| 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 | |||
| 17 | * [ ] Update .cargo/config.toml with the correct probe-rs command to use your specific MCU. For example for C1104 it should be `probe-rs run --chip MSPM0C1104`. (use `probe-rs chip list` to find your chip) | ||
| 18 | * [ ] Update Cargo.toml to have the correct `embassy-mspm0` feature. For example for C1104 it should be `mspm0c1104`. 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. | ||
| 20 | * [ ] If your board has different pin mapping, update any pin numbers or peripherals in the given example code to match your schematic | ||
| 21 | |||
| 22 | If you are unsure, please drop by the Embassy Matrix chat for support, and let us know: | ||
| 23 | |||
| 24 | * Which example you are trying to run | ||
| 25 | * Which chip and board you are using | ||
| 26 | |||
| 27 | Embassy Chat: https://matrix.to/#/#embassy-rs:matrix.org | ||
diff --git a/examples/mspm0c1104/build.rs b/examples/mspm0c1104/build.rs new file mode 100644 index 000000000..30691aa97 --- /dev/null +++ b/examples/mspm0c1104/build.rs | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | //! This build script copies the `memory.x` file from the crate root into | ||
| 2 | //! a directory where the linker can always find it at build time. | ||
| 3 | //! For many projects this is optional, as the linker always searches the | ||
| 4 | //! project root directory -- wherever `Cargo.toml` is. However, if you | ||
| 5 | //! are using a workspace or have a more complicated build setup, this | ||
| 6 | //! build script becomes required. Additionally, by requesting that | ||
| 7 | //! Cargo re-run the build script whenever `memory.x` is changed, | ||
| 8 | //! updating `memory.x` ensures a rebuild of the application with the | ||
| 9 | //! new memory settings. | ||
| 10 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn main() { | ||
| 17 | // Put `memory.x` in our output directory and ensure it's | ||
| 18 | // on the linker search path. | ||
| 19 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 20 | File::create(out.join("memory.x")) | ||
| 21 | .unwrap() | ||
| 22 | .write_all(include_bytes!("memory.x")) | ||
| 23 | .unwrap(); | ||
| 24 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 25 | |||
| 26 | // By default, Cargo will re-run a build script whenever | ||
| 27 | // any file in the project changes. By specifying `memory.x` | ||
| 28 | // here, we ensure the build script is only re-run when | ||
| 29 | // `memory.x` is changed. | ||
| 30 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 31 | |||
| 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
| 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | ||
| 34 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
| 35 | } | ||
diff --git a/examples/mspm0c1104/memory.x b/examples/mspm0c1104/memory.x new file mode 100644 index 000000000..a9108835a --- /dev/null +++ b/examples/mspm0c1104/memory.x | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | FLASH : ORIGIN = 0x00000000, LENGTH = 16K | ||
| 4 | RAM : ORIGIN = 0x20000000, LENGTH = 1K | ||
| 5 | } | ||
diff --git a/examples/mspm0c1104/src/bin/blinky.rs b/examples/mspm0c1104/src/bin/blinky.rs new file mode 100644 index 000000000..264ea3eb5 --- /dev/null +++ b/examples/mspm0c1104/src/bin/blinky.rs | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::*; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_mspm0::{ | ||
| 7 | gpio::{Level, Output}, | ||
| 8 | Config, | ||
| 9 | }; | ||
| 10 | use embassy_time::Timer; | ||
| 11 | use {defmt_rtt as _, panic_halt as _}; | ||
| 12 | |||
| 13 | #[embassy_executor::main] | ||
| 14 | async fn main(_spawner: Spawner) -> ! { | ||
| 15 | info!("Hello world!"); | ||
| 16 | let p = embassy_mspm0::init(Config::default()); | ||
| 17 | |||
| 18 | let mut led1 = Output::new(p.PA22, Level::Low); | ||
| 19 | led1.set_inversion(true); | ||
| 20 | |||
| 21 | loop { | ||
| 22 | Timer::after_millis(400).await; | ||
| 23 | |||
| 24 | info!("Toggle"); | ||
| 25 | led1.toggle(); | ||
| 26 | } | ||
| 27 | } | ||
diff --git a/examples/mspm0c1104/src/bin/button.rs b/examples/mspm0c1104/src/bin/button.rs new file mode 100644 index 000000000..988170ef9 --- /dev/null +++ b/examples/mspm0c1104/src/bin/button.rs | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::*; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_mspm0::{ | ||
| 7 | gpio::{Input, Level, Output, Pull}, | ||
| 8 | Config, | ||
| 9 | }; | ||
| 10 | use {defmt_rtt as _, panic_halt as _}; | ||
| 11 | |||
| 12 | #[embassy_executor::main] | ||
| 13 | async fn main(_spawner: Spawner) -> ! { | ||
| 14 | info!("Hello world!"); | ||
| 15 | |||
| 16 | let p = embassy_mspm0::init(Config::default()); | ||
| 17 | |||
| 18 | let led1 = p.PA22; | ||
| 19 | let s2 = p.PA16; | ||
| 20 | |||
| 21 | let mut led1 = Output::new(led1, Level::Low); | ||
| 22 | |||
| 23 | let mut s2 = Input::new(s2, Pull::Up); | ||
| 24 | |||
| 25 | // led1 is active low | ||
| 26 | led1.set_high(); | ||
| 27 | |||
| 28 | loop { | ||
| 29 | s2.wait_for_falling_edge().await; | ||
| 30 | |||
| 31 | info!("Switch 2 was pressed"); | ||
| 32 | |||
| 33 | led1.toggle(); | ||
| 34 | } | ||
| 35 | } | ||
