Skip to content

Commit 3da4ff6

Browse files
committed
sprinkle some delays to fix failures in optimized builds
1 parent 9d0ef96 commit 3da4ff6

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

nrf52840-hal-tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ name = "serial"
2525
harness = false
2626

2727
[dev-dependencies]
28+
cortex-m = "0.7.0"
2829
defmt = "0.1.3"
2930
defmt-rtt = "0.1.0"
3031
defmt-test = "0.1.1"

nrf52840-hal-tests/tests/gpio-input-pull.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct State {
1919

2020
#[defmt_test::tests]
2121
mod tests {
22+
use cortex_m::asm;
2223
use defmt::{assert, unwrap};
2324
use nrf52840_hal::{gpio::p0, pac, prelude::*};
2425

@@ -53,6 +54,8 @@ mod tests {
5354
let pull_pin = unwrap!(state.pull_pin.take());
5455

5556
let pullup_pin = pull_pin.into_pullup_input();
57+
// GPIO re-configuration is not instantaneous so a delay is needed
58+
asm::delay(100);
5659
assert!(state.input_pin.is_high().unwrap());
5760

5861
state.pull_pin = Some(pullup_pin.into_floating_input());

nrf52840-hal-tests/tests/gpio-output-push-pull.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct State {
1919

2020
#[defmt_test::tests]
2121
mod tests {
22+
use cortex_m::asm;
2223
use defmt::{assert, unwrap};
2324
use nrf52840_hal::{
2425
gpio::{p0, Level},
@@ -45,12 +46,16 @@ mod tests {
4546
#[test]
4647
fn set_low_is_low(state: &mut State) {
4748
state.output_pin.set_low().unwrap();
49+
// GPIO operations are not instantaneous so a delay is needed
50+
asm::delay(100);
4851
assert!(state.input_pin.is_low().unwrap());
4952
}
5053

5154
#[test]
5255
fn set_high_is_high(state: &mut State) {
5356
state.output_pin.set_high().unwrap();
57+
// GPIO operations are not instantaneous so a delay is needed
58+
asm::delay(100);
5459
assert!(state.input_pin.is_high().unwrap());
5560
}
5661
}

0 commit comments

Comments
 (0)