diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-05-01 21:36:10 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-01 21:36:10 +0000 |
| commit | 6096f0cf4b5ef45b97665166be41bfd490748f40 (patch) | |
| tree | 3e19fd1bacd3cb2d4276eefc224a81ed6c004ff0 /tests/utils | |
| parent | 855c0d1423cb1aacd4f4f45e255b02b442afde34 (diff) | |
| parent | a1d45303c336434929eb8eb7e55629c504a95b0e (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')
| -rw-r--r-- | tests/utils/Cargo.toml | 10 | ||||
| -rw-r--r-- | tests/utils/src/bin/saturate_serial.rs | 53 |
2 files changed, 63 insertions, 0 deletions
diff --git a/tests/utils/Cargo.toml b/tests/utils/Cargo.toml new file mode 100644 index 000000000..7d66fd586 --- /dev/null +++ b/tests/utils/Cargo.toml | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | [package] | ||
| 2 | name = "test-utils" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2021" | ||
| 5 | |||
| 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
| 7 | |||
| 8 | [dependencies] | ||
| 9 | rand = "0.8" | ||
| 10 | serial = "0.4" | ||
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 @@ | |||
| 1 | use std::path::Path; | ||
| 2 | use std::time::Duration; | ||
| 3 | use std::{env, io, process, thread}; | ||
| 4 | |||
| 5 | use rand::random; | ||
| 6 | use serial::SerialPort; | ||
| 7 | |||
| 8 | pub 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 | |||
| 27 | fn 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 | } | ||
