diff options
| author | i509VCB <[email protected]> | 2025-07-06 17:35:19 -0500 |
|---|---|---|
| committer | i509VCB <[email protected]> | 2025-07-22 11:41:47 -0500 |
| commit | a1867f0d742f597a25384e4a33209beeec7ec676 (patch) | |
| tree | 1ec06338700bff8b9e54fe410d1e77377fa2114d /tests/mspm0 | |
| parent | 209b64a80be8047b32d7407ff0d8a4da54236551 (diff) | |
mspm0: add buffered uart driver
And tests for G3507.
Diffstat (limited to 'tests/mspm0')
| -rw-r--r-- | tests/mspm0/Cargo.toml | 3 | ||||
| -rw-r--r-- | tests/mspm0/src/bin/uart_buffered.rs | 115 |
2 files changed, 118 insertions, 0 deletions
diff --git a/tests/mspm0/Cargo.toml b/tests/mspm0/Cargo.toml index 2d5b8cd52..5ba3e586b 100644 --- a/tests/mspm0/Cargo.toml +++ b/tests/mspm0/Cargo.toml | |||
| @@ -13,6 +13,7 @@ teleprobe-meta = "1.1" | |||
| 13 | 13 | ||
| 14 | embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = [ "defmt" ] } | 14 | embassy-sync = { version = "0.7.0", path = "../../embassy-sync", features = [ "defmt" ] } |
| 15 | embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = [ "arch-cortex-m", "executor-thread", "defmt" ] } | 15 | embassy-executor = { version = "0.7.0", path = "../../embassy-executor", features = [ "arch-cortex-m", "executor-thread", "defmt" ] } |
| 16 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | ||
| 16 | embassy-time = { version = "0.4.0", path = "../../embassy-time", features = [ "defmt" ] } | 17 | embassy-time = { version = "0.4.0", path = "../../embassy-time", features = [ "defmt" ] } |
| 17 | embassy-mspm0 = { version = "0.1.0", path = "../../embassy-mspm0", features = [ "rt", "defmt", "unstable-pac", "time-driver-any" ] } | 18 | embassy-mspm0 = { version = "0.1.0", path = "../../embassy-mspm0", features = [ "rt", "defmt", "unstable-pac", "time-driver-any" ] } |
| 18 | embassy-embedded-hal = { version = "0.3.1", path = "../../embassy-embedded-hal/"} | 19 | embassy-embedded-hal = { version = "0.3.1", path = "../../embassy-embedded-hal/"} |
| @@ -24,6 +25,8 @@ cortex-m = { version = "0.7.6", features = [ "inline-asm", "critical-section-sin | |||
| 24 | cortex-m-rt = "0.7.0" | 25 | cortex-m-rt = "0.7.0" |
| 25 | embedded-hal = { package = "embedded-hal", version = "1.0" } | 26 | embedded-hal = { package = "embedded-hal", version = "1.0" } |
| 26 | embedded-hal-async = { version = "1.0" } | 27 | embedded-hal-async = { version = "1.0" } |
| 28 | embedded-io = { version = "0.6.1", features = ["defmt-03"] } | ||
| 29 | embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } | ||
| 27 | panic-probe = { version = "1.0.0", features = ["print-defmt"] } | 30 | panic-probe = { version = "1.0.0", features = ["print-defmt"] } |
| 28 | static_cell = "2" | 31 | static_cell = "2" |
| 29 | portable-atomic = { version = "1.5", features = ["critical-section"] } | 32 | portable-atomic = { version = "1.5", features = ["critical-section"] } |
diff --git a/tests/mspm0/src/bin/uart_buffered.rs b/tests/mspm0/src/bin/uart_buffered.rs new file mode 100644 index 000000000..135ac1287 --- /dev/null +++ b/tests/mspm0/src/bin/uart_buffered.rs | |||
| @@ -0,0 +1,115 @@ | |||
| 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::uart::{BufferedInterruptHandler, BufferedUart, Config}; | ||
| 10 | use embassy_mspm0::{bind_interrupts, peripherals}; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | bind_interrupts!(struct Irqs { | ||
| 14 | UART1 => BufferedInterruptHandler<peripherals::UART1>; | ||
| 15 | }); | ||
| 16 | |||
| 17 | #[embassy_executor::main] | ||
| 18 | async fn main(_spawner: Spawner) { | ||
| 19 | let p = embassy_mspm0::init(Default::default()); | ||
| 20 | info!("Hello World!"); | ||
| 21 | |||
| 22 | // TODO: Allow creating a looped-back UART (so pins are not needed). | ||
| 23 | // Do not select default UART since the virtual COM port is attached to UART0. | ||
| 24 | #[cfg(any(feature = "mspm0g3507"))] | ||
| 25 | let (mut tx, mut rx, mut uart) = (p.PA8, p.PA9, p.UART1); | ||
| 26 | |||
| 27 | { | ||
| 28 | use embedded_io_async::{Read, Write}; | ||
| 29 | |||
| 30 | let mut config = Config::default(); | ||
| 31 | config.loop_back_enable = true; | ||
| 32 | config.fifo_enable = false; | ||
| 33 | |||
| 34 | let tx_buf = &mut [0u8; 16]; | ||
| 35 | let rx_buf = &mut [0u8; 16]; | ||
| 36 | let mut uart = unwrap!(BufferedUart::new( | ||
| 37 | uart.reborrow(), | ||
| 38 | tx.reborrow(), | ||
| 39 | rx.reborrow(), | ||
| 40 | Irqs, | ||
| 41 | tx_buf, | ||
| 42 | rx_buf, | ||
| 43 | config | ||
| 44 | )); | ||
| 45 | |||
| 46 | let mut buf = [0; 16]; | ||
| 47 | for (j, b) in buf.iter_mut().enumerate() { | ||
| 48 | *b = j as u8; | ||
| 49 | } | ||
| 50 | |||
| 51 | unwrap!(uart.write_all(&buf).await); | ||
| 52 | unwrap!(uart.flush().await); | ||
| 53 | |||
| 54 | unwrap!(uart.read_exact(&mut buf).await); | ||
| 55 | for (j, b) in buf.iter().enumerate() { | ||
| 56 | assert_eq!(*b, j as u8); | ||
| 57 | } | ||
| 58 | |||
| 59 | // Buffer is unclogged, should be able to write again. | ||
| 60 | unwrap!(uart.write_all(&buf).await); | ||
| 61 | unwrap!(uart.flush().await); | ||
| 62 | |||
| 63 | unwrap!(uart.read_exact(&mut buf).await); | ||
| 64 | for (j, b) in buf.iter().enumerate() { | ||
| 65 | assert_eq!(*b, j as u8); | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | info!("Blocking buffered"); | ||
| 70 | { | ||
| 71 | use embedded_io::{Read, Write}; | ||
| 72 | |||
| 73 | let mut config = Config::default(); | ||
| 74 | config.loop_back_enable = true; | ||
| 75 | config.fifo_enable = false; | ||
| 76 | |||
| 77 | let tx_buf = &mut [0u8; 16]; | ||
| 78 | let rx_buf = &mut [0u8; 16]; | ||
| 79 | let mut uart = unwrap!(BufferedUart::new( | ||
| 80 | uart.reborrow(), | ||
| 81 | tx.reborrow(), | ||
| 82 | rx.reborrow(), | ||
| 83 | Irqs, | ||
| 84 | tx_buf, | ||
| 85 | rx_buf, | ||
| 86 | config | ||
| 87 | )); | ||
| 88 | |||
| 89 | let mut buf = [0; 16]; | ||
| 90 | |||
| 91 | for (j, b) in buf.iter_mut().enumerate() { | ||
| 92 | *b = j as u8; | ||
| 93 | } | ||
| 94 | |||
| 95 | unwrap!(uart.write_all(&buf)); | ||
| 96 | unwrap!(uart.blocking_flush()); | ||
| 97 | unwrap!(uart.read_exact(&mut buf)); | ||
| 98 | |||
| 99 | for (j, b) in buf.iter().enumerate() { | ||
| 100 | assert_eq!(*b, j as u8); | ||
| 101 | } | ||
| 102 | |||
| 103 | // Buffer is unclogged, should be able to write again. | ||
| 104 | unwrap!(uart.write_all(&buf)); | ||
| 105 | unwrap!(uart.blocking_flush()); | ||
| 106 | unwrap!(uart.read_exact(&mut buf)); | ||
| 107 | |||
| 108 | for (j, b) in buf.iter().enumerate() { | ||
| 109 | assert_eq!(*b, j as u8, "at {}", j); | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | info!("Test OK"); | ||
| 114 | cortex_m::asm::bkpt(); | ||
| 115 | } | ||
