Skip to content
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

The code #1

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open

The code #1

wants to merge 24 commits into from

Conversation

usbalbin
Copy link
Owner

@usbalbin usbalbin commented Dec 3, 2024

Compiles for (not at all tested, yet compiles)

  • stm32f334 - Mostly just cfg out the problematic parts for now, the most important parts are active
  • stm32g4x4
    • Examples
  • stm32h7 - Mostly just cfg out the problematic parts for now, the most important parts are active

@usbalbin
Copy link
Owner Author

usbalbin commented Dec 4, 2024

I have sort of tried to get stm32f334 to work(or at least compile). However since this crate is based on the staging pac and the hal is still based on the released pac, well...

Edit: I have updated stm32f3xx-hal for the new pac

@usbalbin
Copy link
Owner Author

usbalbin commented Dec 4, 2024

FYI, here is a very rough attempt at this as its own crate. Nothing too serious for now, mostly just copy paste and fix the errors. Getting it to compile for the stm32f334 was done in the qickest way possible mostly cfg ing out the problematic parts.

CC @liamkinne @AdinAck @burrbull in case you find it interesting

#[cfg(feature = "stm32f3")]
otyper: &mut <PINS::GpioX as hal::gpio::marker::GpioStatic>::OTYPER,
#[cfg(feature = "stm32f3")]
afr: &mut PINS::Afr
Copy link
Owner Author

Choose a reason for hiding this comment

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

Turned out to be quite some differences in how the gpio types work in g4 vs f3 hals. I made an ugly fix for now just to get it to compile but there is a lot if room for improvement there.

The main difference that affects this is how pins are put into alternate mode. The f3 hal requires exclusive access to the gpio blocks shared registers (moder, otyper and afr) which makes sense since it will in fact modify them.

let mut gpioa = dp.GPIOA.split(&mut rcc.ahb);
let pa4 = gpioa
    .pa4
    .into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl);

The g4 hal however, does not require this and just conjures access to these registers internally(likely not sound?).

let gpioa = dp.GPIOA.split(&mut rcc);
let pin = gpioa.pa8.into_alternate();

It is recommended that the pins are connected the HRTIM peripheral only as the last step of initialization to prevent any glitches from occuring on the pins. In my mind, this means that the into_af_push_pull and into_alternate methods should be called by the hrtim init, not by the user. This means that we need to pass in those registers in the f3 case. However there is also the use case where the peripheral is used without any output pins...

@usbalbin
Copy link
Owner Author

The most basic example has been ported for all devices and it compiles. Not sure if it works yet though...

@burrbull
Copy link

Published both https://crates.io/crates/stm32h7-staging and https://crates.io/crates/stm32f3-staging

@usbalbin
Copy link
Owner Author

src/control.rs Outdated

pub fn wait_for_calibration(self) -> (HrTimCalibrated, FaultInputs, EevInputs) {
let common = unsafe { &*HRTIM_COMMON::ptr() };
while common.isr().read().dllrdy().bit_is_clear() {
Copy link
Owner Author

Choose a reason for hiding this comment

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

TODO: Should this even be done on the H7 since they do not have the DLL feature? Should this register field even exist in the pac?

// Start calibration procedure
common
.dllcr()
.write(|w| w.cal().set_bit().calen().clear_bit());
Copy link
Owner Author

Choose a reason for hiding this comment

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

Dont do this for H7 since it does not have DLL

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