aboutsummaryrefslogtreecommitdiff
path: root/tests/mspm0
diff options
context:
space:
mode:
authori509VCB <[email protected]>2025-04-06 21:13:49 -0500
committeri509VCB <[email protected]>2025-04-06 21:15:42 -0500
commit1e23b8114bb1f4b9e092bc50b3cfe4bd2f7ebdb6 (patch)
tree78f39de51ef1e399b9e4b0d3786a095134838790 /tests/mspm0
parent717fbc1cd9a038d6601721a6e84f58be264ee624 (diff)
mspm0: add uart tests
This also fixes a bug in the uart clock calculation where it could select an oversampling faster than what the hardware is providing.
Diffstat (limited to 'tests/mspm0')
-rw-r--r--tests/mspm0/.cargo/config.toml8
-rw-r--r--tests/mspm0/Cargo.toml58
-rw-r--r--tests/mspm0/build.rs24
-rw-r--r--tests/mspm0/memory_g3507.x6
-rw-r--r--tests/mspm0/src/bin/uart.rs83
5 files changed, 179 insertions, 0 deletions
diff --git a/tests/mspm0/.cargo/config.toml b/tests/mspm0/.cargo/config.toml
new file mode 100644
index 000000000..825bf3ae9
--- /dev/null
+++ b/tests/mspm0/.cargo/config.toml
@@ -0,0 +1,8 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2runner = "teleprobe local run --chip MSPM0G3507 --protocol swd --elf"
3
4[build]
5target = "thumbv6m-none-eabi"
6
7[env]
8DEFMT_LOG = "trace,embassy_hal_internal=debug"
diff --git a/tests/mspm0/Cargo.toml b/tests/mspm0/Cargo.toml
new file mode 100644
index 000000000..0566807d7
--- /dev/null
+++ b/tests/mspm0/Cargo.toml
@@ -0,0 +1,58 @@
1[package]
2edition = "2021"
3name = "embassy-mspm0-tests"
4version = "0.1.0"
5license = "MIT OR Apache-2.0"
6
7[features]
8mspm0g3507 = [ "embassy-mspm0/mspm0g350x" ]
9
10[dependencies]
11teleprobe-meta = "1.1"
12
13embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = [ "defmt" ] }
14embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = [ "arch-cortex-m", "executor-thread", "defmt" ] }
15embassy-time = { version = "0.4.0", path = "../../embassy-time", features = [ "defmt" ] }
16embassy-mspm0 = { version = "0.1.0", path = "../../embassy-mspm0", features = [ "rt", "defmt", "unstable-pac", "time-driver-any" ] }
17embassy-embedded-hal = { version = "0.3.0", path = "../../embassy-embedded-hal/"}
18
19defmt = "1.0.1"
20defmt-rtt = "1.0.0"
21
22cortex-m = { version = "0.7.6", features = [ "inline-asm", "critical-section-single-core" ]}
23cortex-m-rt = "0.7.0"
24embedded-hal = { package = "embedded-hal", version = "1.0" }
25embedded-hal-async = { version = "1.0" }
26panic-probe = { version = "0.3.0", features = ["print-defmt"] }
27static_cell = "2"
28portable-atomic = { version = "1.5", features = ["critical-section"] }
29
30[profile.dev]
31debug = 2
32debug-assertions = true
33opt-level = 's'
34overflow-checks = true
35
36[profile.release]
37codegen-units = 1
38debug = 2
39debug-assertions = false
40incremental = false
41lto = "fat"
42opt-level = 's'
43overflow-checks = false
44
45# do not optimize proc-macro crates = faster builds from scratch
46[profile.dev.build-override]
47codegen-units = 8
48debug = false
49debug-assertions = false
50opt-level = 0
51overflow-checks = false
52
53[profile.release.build-override]
54codegen-units = 8
55debug = false
56debug-assertions = false
57opt-level = 0
58overflow-checks = false
diff --git a/tests/mspm0/build.rs b/tests/mspm0/build.rs
new file mode 100644
index 000000000..57b592abf
--- /dev/null
+++ b/tests/mspm0/build.rs
@@ -0,0 +1,24 @@
1use std::error::Error;
2use std::path::PathBuf;
3use std::{env, fs};
4
5fn main() -> Result<(), Box<dyn Error>> {
6 let out = PathBuf::from(env::var("OUT_DIR").unwrap());
7
8 #[cfg(feature = "mspm0g3507")]
9 let memory_x = include_bytes!("memory_g3507.x");
10
11 fs::write(out.join("memory.x"), memory_x).unwrap();
12
13 println!("cargo:rustc-link-search={}", out.display());
14 println!("cargo:rerun-if-changed=link_ram.x");
15 // copy main linker script.
16 fs::write(out.join("link_ram.x"), include_bytes!("../link_ram_cortex_m.x")).unwrap();
17
18 println!("cargo:rustc-link-arg-bins=--nmagic");
19 println!("cargo:rustc-link-arg-bins=-Tlink_ram.x");
20 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
21 println!("cargo:rustc-link-arg-bins=-Tteleprobe.x");
22
23 Ok(())
24}
diff --git a/tests/mspm0/memory_g3507.x b/tests/mspm0/memory_g3507.x
new file mode 100644
index 000000000..37e381fbd
--- /dev/null
+++ b/tests/mspm0/memory_g3507.x
@@ -0,0 +1,6 @@
1MEMORY
2{
3 FLASH : ORIGIN = 0x00000000, LENGTH = 128K
4 /* Select non-parity range of SRAM due to SRAM_ERR_01 errata in SLAZ758 */
5 RAM : ORIGIN = 0x20200000, LENGTH = 32K
6}
diff --git a/tests/mspm0/src/bin/uart.rs b/tests/mspm0/src/bin/uart.rs
new file mode 100644
index 000000000..458129d44
--- /dev/null
+++ b/tests/mspm0/src/bin/uart.rs
@@ -0,0 +1,83 @@
1#![no_std]
2#![no_main]
3
4#[cfg(feature = "mspm0g3507")]
5teleprobe_meta::target!(b"lp-mspm0g3507");
6
7use defmt::{assert_eq, unwrap, *};
8use embassy_executor::Spawner;
9use embassy_mspm0::mode::Blocking;
10use embassy_mspm0::uart::{ClockSel, Config, Error, Uart};
11use {defmt_rtt as _, panic_probe as _};
12
13fn read<const N: usize>(uart: &mut Uart<'_, Blocking>) -> Result<[u8; N], Error> {
14 let mut buf = [255; N];
15 uart.blocking_read(&mut buf)?;
16 Ok(buf)
17}
18
19#[embassy_executor::main]
20async fn main(_spawner: Spawner) {
21 let p = embassy_mspm0::init(Default::default());
22 info!("Hello World!");
23
24 // TODO: Allow creating a looped-back UART (so pins are not needed).
25 // Do not select default UART since the virtual COM port is attached to UART0.
26 #[cfg(feature = "mspm0g3507")]
27 let (mut tx, mut rx, mut uart) = (p.PA8, p.PA9, p.UART1);
28
29 const MFCLK_BUAD_RATES: &[u32] = &[1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200];
30
31 for &rate in MFCLK_BUAD_RATES {
32 info!("{} baud using MFCLK", rate);
33
34 let mut config = Config::default();
35 // MSPM0 hardware supports a loopback mode to allow self test.
36 config.loop_back_enable = true;
37 config.baudrate = rate;
38
39 let mut uart = unwrap!(Uart::new_blocking(
40 uart.reborrow(),
41 rx.reborrow(),
42 tx.reborrow(),
43 config
44 ));
45
46 // We can't send too many bytes, they have to fit in the FIFO.
47 // This is because we aren't sending+receiving at the same time.
48
49 let data = [0xC0, 0xDE];
50 unwrap!(uart.blocking_write(&data));
51 assert_eq!(unwrap!(read(&mut uart)), data);
52 }
53
54 // 9600 is the maximum possible value for 32.768 kHz.
55 const LFCLK_BAUD_RATES: &[u32] = &[1200, 2400, 4800, 9600];
56
57 for &rate in LFCLK_BAUD_RATES {
58 info!("{} baud using LFCLK", rate);
59
60 let mut config = Config::default();
61 // MSPM0 hardware supports a loopback mode to allow self test.
62 config.loop_back_enable = true;
63 config.baudrate = rate;
64 config.clock_source = ClockSel::LfClk;
65
66 let mut uart = expect!(Uart::new_blocking(
67 uart.reborrow(),
68 rx.reborrow(),
69 tx.reborrow(),
70 config,
71 ));
72
73 // We can't send too many bytes, they have to fit in the FIFO.
74 // This is because we aren't sending+receiving at the same time.
75
76 let data = [0xC0, 0xDE];
77 unwrap!(uart.blocking_write(&data));
78 assert_eq!(unwrap!(read(&mut uart)), data);
79 }
80
81 info!("Test OK");
82 cortex_m::asm::bkpt();
83}