aboutsummaryrefslogtreecommitdiff
path: root/tests/mspm0/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mspm0/src')
-rw-r--r--tests/mspm0/src/bin/uart.rs83
1 files changed, 83 insertions, 0 deletions
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}