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,11 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# replace MSPM0C1104 with your chip as listed in `probe-rs chip list`
runner = "probe-rs run --chip MSPM0C1104 --protocol=swd"
[build]
target = "thumbv6m-none-eabi"
[env]
DEFMT_LOG = "debug"
# defmt's buffer needs to be shrunk since the MSPM0C1104 only has 1KB of ram.
DEFMT_RTT_BUFFER_SIZE = "72"

View File

@@ -0,0 +1,32 @@
[package]
edition = "2021"
name = "embassy-mspm0-c1104-examples"
version = "0.1.0"
license = "MIT OR Apache-2.0"
[dependencies]
embassy-mspm0 = { version = "0.1.0", path = "../../embassy-mspm0", features = ["mspm0c110x", "rt", "time-driver-any"] }
embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = ["task-arena-size-128", "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"
# The chip only has 1KB of ram, so we must optimize binaries regardless
[profile.dev]
debug = 2
opt-level = "z"
lto = true
codegen-units = 1
# strip = true
[profile.release]
debug = 2
opt-level = "z"
lto = true
codegen-units = 1

View File

@@ -0,0 +1,27 @@
# Examples for MSPM0C110x 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-MSPM0C1104](https://www.ti.com/tool/LP-MSPM0C1104) 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 C1104 it should be `probe-rs run --chip MSPM0C1104`. (use `probe-rs chip list` to find your chip)
* [ ] 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.
* [ ] 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,5 @@
MEMORY
{
FLASH : ORIGIN = 0x00000000, LENGTH = 16K
RAM : ORIGIN = 0x20000000, LENGTH = 1K
}

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.PA22, 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.PA22;
let s2 = p.PA16;
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();
}
}