-
Notifications
You must be signed in to change notification settings - Fork 468
Prefer reporting an error instead of triggering an assert #5865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -461,6 +461,7 @@ cfg_select! { | |
| struct Context { | ||
| rmt: RMT<'static>, | ||
| pin: AnyPin<'static>, | ||
| pin2: AnyPin<'static>, | ||
| } | ||
|
|
||
| impl Context { | ||
|
|
@@ -505,6 +506,7 @@ impl Context { | |
|
|
||
| #[embedded_test::tests(default_timeout = 1, executor = hil_test::Executor::new())] | ||
| mod tests { | ||
| use esp_hal::gpio::Output; | ||
| #[allow(unused_imports)] | ||
| use hil_test::{assert, assert_eq}; | ||
|
|
||
|
|
@@ -523,11 +525,13 @@ mod tests { | |
|
|
||
| esp_rtos::start(timg0.timer0, software_interrupt.software_interrupt0); | ||
|
|
||
| let pin = AnyPin::from(hil_test::common_test_pins!(peripherals).1); | ||
| let pins = hil_test::common_test_pins!(peripherals); | ||
| let (pin, pin2) = (AnyPin::from(pins.1), AnyPin::from(pins.0)); | ||
|
|
||
| Context { | ||
| rmt: peripherals.RMT, | ||
| pin, | ||
| pin2, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1229,4 +1233,49 @@ mod tests { | |
| "tx with loopcount 0 did not complete immediately" | ||
| ); | ||
| } | ||
|
|
||
| // Regression test for esp-rs/esp-hal#4697 | ||
| // | ||
| // This test is timing dependent and tests ESP32-specific behavior | ||
| #[cfg(esp32)] | ||
| #[test] | ||
| async fn rmt_check_regession_4697(mut ctx: Context) { | ||
| let rmt = Rmt::new(ctx.rmt.reborrow(), FREQ).unwrap().into_async(); | ||
|
|
||
| let (rx, tx) = (ctx.pin, ctx.pin2); | ||
| let mut tx = Output::new(tx, Level::Low, Default::default()); | ||
|
|
||
| let mut rx_channel = rx_channel_creator!(rmt) | ||
| .configure_rx( | ||
| &RxChannelConfig::default() | ||
| .with_clk_divider(255) | ||
| .with_idle_threshold(10000), | ||
| ) | ||
| .unwrap() | ||
| .with_pin(rx); | ||
|
|
||
| // This suspiciously looking code is to drive the hardware into the state that caused the | ||
| // originally failed assertion. We want the async part to go into the first receive | ||
| // phase - then the second future will start "spamming" RMT with pulses. | ||
| // While not really explainable from any documentation, this turned out to drive the | ||
| // hardware into an unexpected state. | ||
| // | ||
| // With the previous assert in place, interestingly the first two receive calls failed as | ||
| // expected but then we ran into the issue where the assert failed instead of seeing | ||
| // the error bit set. | ||
| embassy_futures::join::join( | ||
| async { | ||
| let mut data = [PulseCode::default(); 10]; | ||
| for _ in 0..3 { | ||
| assert!(rx_channel.receive(&mut data).await.is_err()); | ||
| } | ||
| }, | ||
| async { | ||
| for _ in 0..1000 { | ||
| tx.toggle(); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test could use a bit of explanation - why do we toggle a GPIO at full speed in an async block?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok - that looks definitely sus - hope the added comments help a little bit. it's generally an odd issue
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we try and blast a stable-ish SPI clock into the RMT input instead of a GPIO signal of undeterminate frequency?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can try |
||
| }, | ||
| ) | ||
| .await; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs some docs explaining what the return value means imo