diff options
| author | i509VCB <[email protected]> | 2025-04-06 21:13:49 -0500 |
|---|---|---|
| committer | i509VCB <[email protected]> | 2025-04-06 21:15:42 -0500 |
| commit | 1e23b8114bb1f4b9e092bc50b3cfe4bd2f7ebdb6 (patch) | |
| tree | 78f39de51ef1e399b9e4b0d3786a095134838790 /tests | |
| parent | 717fbc1cd9a038d6601721a6e84f58be264ee624 (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')
| -rw-r--r-- | tests/mspm0/.cargo/config.toml | 8 | ||||
| -rw-r--r-- | tests/mspm0/Cargo.toml | 58 | ||||
| -rw-r--r-- | tests/mspm0/build.rs | 24 | ||||
| -rw-r--r-- | tests/mspm0/memory_g3507.x | 6 | ||||
| -rw-r--r-- | tests/mspm0/src/bin/uart.rs | 83 |
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"))'] | ||
| 2 | runner = "teleprobe local run --chip MSPM0G3507 --protocol swd --elf" | ||
| 3 | |||
| 4 | [build] | ||
| 5 | target = "thumbv6m-none-eabi" | ||
| 6 | |||
| 7 | [env] | ||
| 8 | DEFMT_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] | ||
| 2 | edition = "2021" | ||
| 3 | name = "embassy-mspm0-tests" | ||
| 4 | version = "0.1.0" | ||
| 5 | license = "MIT OR Apache-2.0" | ||
| 6 | |||
| 7 | [features] | ||
| 8 | mspm0g3507 = [ "embassy-mspm0/mspm0g350x" ] | ||
| 9 | |||
| 10 | [dependencies] | ||
| 11 | teleprobe-meta = "1.1" | ||
| 12 | |||
| 13 | embassy-sync = { version = "0.6.2", path = "../../embassy-sync", features = [ "defmt" ] } | ||
| 14 | embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = [ "arch-cortex-m", "executor-thread", "defmt" ] } | ||
| 15 | embassy-time = { version = "0.4.0", path = "../../embassy-time", features = [ "defmt" ] } | ||
| 16 | embassy-mspm0 = { version = "0.1.0", path = "../../embassy-mspm0", features = [ "rt", "defmt", "unstable-pac", "time-driver-any" ] } | ||
| 17 | embassy-embedded-hal = { version = "0.3.0", path = "../../embassy-embedded-hal/"} | ||
| 18 | |||
| 19 | defmt = "1.0.1" | ||
| 20 | defmt-rtt = "1.0.0" | ||
| 21 | |||
| 22 | cortex-m = { version = "0.7.6", features = [ "inline-asm", "critical-section-single-core" ]} | ||
| 23 | cortex-m-rt = "0.7.0" | ||
| 24 | embedded-hal = { package = "embedded-hal", version = "1.0" } | ||
| 25 | embedded-hal-async = { version = "1.0" } | ||
| 26 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | ||
| 27 | static_cell = "2" | ||
| 28 | portable-atomic = { version = "1.5", features = ["critical-section"] } | ||
| 29 | |||
| 30 | [profile.dev] | ||
| 31 | debug = 2 | ||
| 32 | debug-assertions = true | ||
| 33 | opt-level = 's' | ||
| 34 | overflow-checks = true | ||
| 35 | |||
| 36 | [profile.release] | ||
| 37 | codegen-units = 1 | ||
| 38 | debug = 2 | ||
| 39 | debug-assertions = false | ||
| 40 | incremental = false | ||
| 41 | lto = "fat" | ||
| 42 | opt-level = 's' | ||
| 43 | overflow-checks = false | ||
| 44 | |||
| 45 | # do not optimize proc-macro crates = faster builds from scratch | ||
| 46 | [profile.dev.build-override] | ||
| 47 | codegen-units = 8 | ||
| 48 | debug = false | ||
| 49 | debug-assertions = false | ||
| 50 | opt-level = 0 | ||
| 51 | overflow-checks = false | ||
| 52 | |||
| 53 | [profile.release.build-override] | ||
| 54 | codegen-units = 8 | ||
| 55 | debug = false | ||
| 56 | debug-assertions = false | ||
| 57 | opt-level = 0 | ||
| 58 | overflow-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 @@ | |||
| 1 | use std::error::Error; | ||
| 2 | use std::path::PathBuf; | ||
| 3 | use std::{env, fs}; | ||
| 4 | |||
| 5 | fn 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 @@ | |||
| 1 | MEMORY | ||
| 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")] | ||
| 5 | teleprobe_meta::target!(b"lp-mspm0g3507"); | ||
| 6 | |||
| 7 | use defmt::{assert_eq, unwrap, *}; | ||
| 8 | use embassy_executor::Spawner; | ||
| 9 | use embassy_mspm0::mode::Blocking; | ||
| 10 | use embassy_mspm0::uart::{ClockSel, Config, Error, Uart}; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | fn 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] | ||
| 20 | async 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 | } | ||
