Skip to content

Add tests #52

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Add tests #52

wants to merge 5 commits into from

Conversation

usbalbin
Copy link
Member

@usbalbin usbalbin commented May 29, 2025

Adds some simple gpio self tests to be run on a nucleo-h533

See #50

This was referenced May 30, 2025
astapleton pushed a commit that referenced this pull request Jun 2, 2025
Found out that the offset for setting the pull up/down resistor is wrong
during #52
@usbalbin usbalbin marked this pull request as ready for review July 5, 2025 21:22
use super::*;

let (gpioa, _) = init();
let pin = gpioa.pa8;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you're picking PA8 for all these tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not really. I can spread out to a couple more pins. Perhaps both sides of 8 since I believe some settings are split into different registers for pin 0..=7 and 8..=15?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should test more ports too, like B, C etc?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could conceivably do all the pins if you converted each to an ErasedPin and shoved them all into an array? If you wanted to you could modify the Parts struct defined here to implement that instead of doing it here?

use hal::stm32;
use stm32h5xx_hal::{self as hal, gpio};

pub const F_SYS: HertzU32 = HertzU32::MHz(16);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be used to set the core clock frequency? Currently, it is set to 250MHz on line 113, so deriving the cycles per µs is incorrect here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I just put up #61, which should help with doing this derivation

Comment on lines +33 to +67
pub fn await_lo<const CYCLES_PER_US: u32>(
timer: &Timer<CYCLES_PER_US>,
pin: u8,
timeout: MicrosDurationU32,
) -> Result<MicrosDurationU32, ErrorTimedOut> {
await_p(timer, || is_pax_low(pin), timeout)
}

#[allow(dead_code)]
pub fn await_hi<const CYCLES_PER_US: u32>(
timer: &Timer<CYCLES_PER_US>,
pin: u8,
timeout: MicrosDurationU32,
) -> Result<MicrosDurationU32, ErrorTimedOut> {
await_p(timer, || !is_pax_low(pin), timeout)
}

#[allow(dead_code)]
pub fn await_p<const CYCLES_PER_US: u32>(
timer: &Timer<CYCLES_PER_US>,
mut p: impl FnMut() -> bool,
timeout: MicrosDurationU32,
) -> Result<MicrosDurationU32, ErrorTimedOut> {
let before = timer.now();

loop {
let passed_time = timer.now() - before;
if p() {
return Ok(passed_time);
}
if passed_time > timeout {
return Err(ErrorTimedOut);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put up #61. Maybe that will help with some of these waiting operations?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants