esp-hal/hil-test/tests/uart_regression.rs
Dániel Buga ff2a46dbc8
UART: make async operations cancellation-safe, update others for consistency (#3142)
* Make async operations cancellable

* Handle thresholds

* Fix written amount calculation

* Fix waiting for events

* Don't return 0 bytes, don't modify TX threshold

* Add read_exact implementation

* Fix tests

* Add tests

* Inline constant into the default values

* Make FIFO config stable

* Fix doc links

* Changelog

* Remove duplicate changelog entries

* Check for RX error

* Fix write_async not recalculating available space

* Fix ESP32 timeout loop

* Check the unmasked interrupt bits to actually detect errors

* Improve naming

* Change async handler to not clear interrupt status

* Test and fix case where write_async returned Ok(0)

* Tweak docs

* Address review feedback

* Use embedded_io to fill buffer in test

* Rename
2025-02-20 08:19:55 +00:00

47 lines
1.2 KiB
Rust

//! Misc UART TX/RX regression tests
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES: unstable
#![no_std]
#![no_main]
#[cfg(test)]
#[embedded_test::tests(default_timeout = 3)]
mod tests {
use esp_hal::{
gpio::Flex,
uart::{self, UartRx, UartTx},
};
use hil_test as _;
#[test]
fn test_that_creating_tx_does_not_cause_a_pulse() {
let peripherals = esp_hal::init(esp_hal::Config::default());
let (rx, tx) = hil_test::common_test_pins!(peripherals);
let mut rx = UartRx::new(peripherals.UART1, uart::Config::default())
.unwrap()
.with_rx(rx);
// Start from a low level to verify that UartTx sets the level high initially,
// but don't enable output otherwise we actually pull down against RX's
// pullup resistor.
let mut tx = Flex::new(tx);
tx.set_low();
// set up TX and send a byte
let mut tx = UartTx::new(peripherals.UART0, uart::Config::default())
.unwrap()
.with_tx(tx);
tx.flush().unwrap();
tx.write(&[0x42]).unwrap();
let mut byte = [0u8; 1];
rx.read(&mut byte).unwrap();
assert_eq!(byte[0], 0x42);
}
}