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
This commit is contained in:
i509VCB
2025-03-13 22:10:45 -05:00
parent 38f26137fc
commit e0cdc356cc
51 changed files with 4476 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# replace MSPM0L2228 with your chip as listed in `probe-rs chip list`
# TODO: Remove description path after new chiptool release
runner = "probe-rs run --restore-unwritten --verify --chip MSPM0L2228 --protocol=swd --chip-description-path ./MSPM0L122X_L222X_Series.yaml"
[build]
target = "thumbv6m-none-eabi"
[env]
DEFMT_LOG = "trace"

View File

@@ -0,0 +1,21 @@
[package]
edition = "2021"
name = "embassy-mspm0-l2228-examples"
version = "0.1.0"
license = "MIT OR Apache-2.0"
[dependencies]
embassy-mspm0 = { version = "0.1.0", path = "../../embassy-mspm0", features = ["mspm0l222x", "rt", "time-driver-any"] }
embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["task-arena-size-1024", "arch-cortex-m", "executor-thread", "executor-interrupt"] }
embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = ["defmt"] }
embassy-time = { version = "0.4.0", path = "../../embassy-time", features = ["defmt"] }
panic-halt = "0.2.0"
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = { version = "0.7.0"}
defmt = "0.3"
defmt-rtt = "0.4"
panic-probe = { version = "0.3.2", features = ["print-defmt"] }
panic-semihosting = "0.6.0"
[profile.release]
debug = 2

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,27 @@
# Examples for MSPM0L222x family
Run individual examples with
```
cargo run --bin <module-name>
```
for example
```
cargo run --bin blinky
```
## Checklist before running examples
A large number of the examples are written for the [LP-MSPM0L2228](https://www.ti.com/tool/LP-MSPM0L2228) board.
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.
* [ ] Update .cargo/config.toml with the correct probe-rs command to use your specific MCU. For example for L2228 it should be `probe-rs run --chip MSPM0L2228`. (use `probe-rs chip list` to find your chip)
* [ ] Update Cargo.toml to have the correct `embassy-mspm0` feature. For example for L2228 it should be `mspm0l2228`. Look in the `Cargo.toml` file of the `embassy-mspm0` project to find the correct feature flag for your chip.
* [ ] If your board has a special clock or power configuration, make sure that it is set up appropriately.
* [ ] If your board has different pin mapping, update any pin numbers or peripherals in the given example code to match your schematic
If you are unsure, please drop by the Embassy Matrix chat for support, and let us know:
* Which example you are trying to run
* Which chip and board you are using
Embassy Chat: https://matrix.to/#/#embassy-rs:matrix.org

View File

@@ -0,0 +1,35 @@
//! This build script copies the `memory.x` file from the crate root into
//! a directory where the linker can always find it at build time.
//! For many projects this is optional, as the linker always searches the
//! project root directory -- wherever `Cargo.toml` is. However, if you
//! are using a workspace or have a more complicated build setup, this
//! build script becomes required. Additionally, by requesting that
//! Cargo re-run the build script whenever `memory.x` is changed,
//! updating `memory.x` ensures a rebuild of the application with the
//! new memory settings.
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
fn main() {
// Put `memory.x` in our output directory and ensure it's
// on the linker search path.
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x"))
.unwrap()
.write_all(include_bytes!("memory.x"))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());
// By default, Cargo will re-run a build script whenever
// any file in the project changes. By specifying `memory.x`
// here, we ensure the build script is only re-run when
// `memory.x` is changed.
println!("cargo:rerun-if-changed=memory.x");
println!("cargo:rustc-link-arg-bins=--nmagic");
println!("cargo:rustc-link-arg-bins=-Tlink.x");
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
}

View File

@@ -0,0 +1,6 @@
MEMORY
{
FLASH : ORIGIN = 0x00000000, LENGTH = 256K
/* Select non-parity range of SRAM due to SRAM_ERR_01 errata in SLAZ758 */
RAM : ORIGIN = 0x20200000, LENGTH = 32K
}

View File

@@ -0,0 +1,27 @@
#![no_std]
#![no_main]
use defmt::*;
use embassy_executor::Spawner;
use embassy_mspm0::{
gpio::{Level, Output},
Config,
};
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(Config::default());
let mut led1 = Output::new(p.PA0, Level::Low);
led1.set_inversion(true);
loop {
Timer::after_millis(400).await;
info!("Toggle");
led1.toggle();
}
}

View File

@@ -0,0 +1,35 @@
#![no_std]
#![no_main]
use defmt::*;
use embassy_executor::Spawner;
use embassy_mspm0::{
gpio::{Input, Level, Output, Pull},
Config,
};
use {defmt_rtt as _, panic_halt as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner) -> ! {
info!("Hello world!");
let p = embassy_mspm0::init(Config::default());
let led1 = p.PA0;
let s2 = p.PB8;
let mut led1 = Output::new(led1, Level::Low);
let mut s2 = Input::new(s2, Pull::Up);
// led1 is active low
led1.set_high();
loop {
s2.wait_for_falling_edge().await;
info!("Switch 2 was pressed");
led1.toggle();
}
}