aboutsummaryrefslogtreecommitdiff
path: root/tests/utils/src/bin
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-05-01 21:36:10 +0000
committerGitHub <[email protected]>2023-05-01 21:36:10 +0000
commit6096f0cf4b5ef45b97665166be41bfd490748f40 (patch)
tree3e19fd1bacd3cb2d4276eefc224a81ed6c004ff0 /tests/utils/src/bin
parent855c0d1423cb1aacd4f4f45e255b02b442afde34 (diff)
parenta1d45303c336434929eb8eb7e55629c504a95b0e (diff)
Merge #1404
1404: feat(stm32): Add DMA based, ring-buffer based rx uart, v3 r=Dirbaio a=rmja This PR replaces #1150. Comparing to that PR, this one has the following changes: * The implementation now aligns with the new stm32 dma module, thanks `@Dirbaio!` * Calls to `read()` now returns on either 1) idle line, or 2) ring buffer is at most half full. This is different from the previous pr, which would return a lot of 1 byte reads. Thank you `@chemicstry` for making me realize that it was actually not what I wanted. This is accomplished using half-transfer completed and full-transfer completed interrupts. Both seems to be supported on both dma and bdma. The implementation still have the issue mentioned here: https://github.com/embassy-rs/embassy/pull/1150#discussion_r1094627035 Regarding the todos here: https://github.com/embassy-rs/embassy/pull/1150#issuecomment-1513905925. I have removed the exposure of ndtr from `dma::RingBuffer` to the uart so that the uart now simply calls `ringbuf::reload_position()` to align the position within the ring buffer to that of the actual running dma controller. BDMA and GPDMA is not implemented. I do not have any chips with those dma controllers, so maybe someone else should to this so that it can be tested. The `saturate_serial` test utility inside `tests/utils` has an `--idles` switch which can be used to saturate the uart from a pc, but with random idles. Because embassy-stm32 now can have tests, we should probably run them in ci. I do this locally to test the DmaRingBuffer: `cargo test --no-default-features --features stm32f429ig`. cc `@chemicstry` `@Dirbaio` Co-authored-by: Rasmus Melchior Jacobsen <[email protected]> Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'tests/utils/src/bin')
-rw-r--r--tests/utils/src/bin/saturate_serial.rs53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/utils/src/bin/saturate_serial.rs b/tests/utils/src/bin/saturate_serial.rs
new file mode 100644
index 000000000..18ca12fb7
--- /dev/null
+++ b/tests/utils/src/bin/saturate_serial.rs
@@ -0,0 +1,53 @@
1use std::path::Path;
2use std::time::Duration;
3use std::{env, io, process, thread};
4
5use rand::random;
6use serial::SerialPort;
7
8pub fn main() {
9 if let Some(port_name) = env::args().nth(1) {
10 let idles = env::args().position(|x| x == "--idles").is_some();
11
12 println!("Saturating port {:?} with 115200 8N1", port_name);
13 println!("Idles: {}", idles);
14 println!("Process ID: {}", process::id());
15 let mut port = serial::open(&port_name).unwrap();
16 if saturate(&mut port, idles).is_err() {
17 eprintln!("Unable to saturate port");
18 }
19 } else {
20 let path = env::args().next().unwrap();
21 let basepath = Path::new(&path).with_extension("");
22 let basename = basepath.file_name().unwrap();
23 eprintln!("USAGE: {} <port-name>", basename.to_string_lossy());
24 }
25}
26
27fn saturate<T: SerialPort>(port: &mut T, idles: bool) -> io::Result<()> {
28 port.reconfigure(&|settings| {
29 settings.set_baud_rate(serial::Baud115200)?;
30 settings.set_char_size(serial::Bits8);
31 settings.set_parity(serial::ParityNone);
32 settings.set_stop_bits(serial::Stop1);
33 Ok(())
34 })?;
35
36 let mut written = 0;
37 loop {
38 let len = random::<usize>() % 0x1000;
39 let buf: Vec<u8> = (written..written + len).map(|x| x as u8).collect();
40
41 port.write_all(&buf)?;
42
43 if idles {
44 let micros = (random::<usize>() % 1000) as u64;
45 println!("Sleeping {}us", micros);
46 port.flush().unwrap();
47 thread::sleep(Duration::from_micros(micros));
48 }
49
50 written += len;
51 println!("Written: {}", written);
52 }
53}