-
Notifications
You must be signed in to change notification settings - Fork 5
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
base: master
Are you sure you want to change the base?
Add tests #52
Conversation
Found out that the offset for setting the pull up/down resistor is wrong during #52
use super::*; | ||
|
||
let (gpioa, _) = init(); | ||
let pin = gpioa.pa8; |
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.
Any reason you're picking PA8 for all these tests?
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.
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?
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.
Do you think we should test more ports too, like B, C etc?
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.
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); |
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.
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.
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.
Also, I just put up #61, which should help with doing this derivation
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); | ||
} | ||
} | ||
} |
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.
I put up #61. Maybe that will help with some of these waiting operations?
Adds some simple gpio self tests to be run on a nucleo-h533
See #50