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

Add OTG_HS support for STM32H7R/S #3337

Merged
merged 3 commits into from
Sep 23, 2024

Conversation

doesnotcompete
Copy link
Contributor

This adds support for the embedded high-speed USB peripheral on the STM32H7R/S series. I've confirmed the usb_serial example works on a Nucleo-H7S3 board using the internal HS PHY.
These changes build on prior work by @RileyLeff in #3289.

There are some remaining issues:

  • I haven't tested this with the OTG_FS peripheral or on other boards with different clock configurations.
  • I'm not sure the way I've implemented the clock configuration is ideal. The USBPHYC on the H7R/S series embeds a PLL that can receive a range of different frequencies via the USBPHYCSEL clock mux and generates the necessary 48 and 60MHz clocks for the OTG blocks internally (see the clock diagram below). I've simply added USBPHYC as a fallback clock for the OTG_HS peripheral in stm32-data to get the clock generator to generate a mux definition and then explicitly pick the corresponding reference clock in the H-series RCC driver, but this approach results in the PLL input frequency being registered as the actual OTG kernel clock.
  • Possibly related to this, ahb_freq in otg.rs doesn't represent the AHB bus frequency, but just this USBPHYC PLL input frequency. I've just skipped the check of a sufficient AHB clock on the H7R/S, as I didn't find a straight-forward solution and the USBPHYC PLL input might very well be below 30MHz, but this is likely not ideal.

usb_clk

@doesnotcompete
Copy link
Contributor Author

The CI failure is apparently caused by a missing definition of the OTG_HS IP block in the cubedb source files of stm32-data.
STM32H7R7A8Ix.xml and STM32H7S7Z8Jx.xml only include the block for USB_OTG_FS, although all H7R/S MCUs, including the H7R7A8 and H7S7Z8, should have HS USB with an integrated PHY.
I'm not sure what'd be the best way to fix this.

@RileyLeff
Copy link

really appreciate your continued work on this! i'm pretty out of my depth here, would not have figured this out myself.

@Dirbaio
Copy link
Member

Dirbaio commented Sep 17, 2024

The CI failure is apparently caused by a missing definition of the OTG_HS IP block in the cubedb source files of stm32-data.
STM32H7R7A8Ix.xml and STM32H7S7Z8Jx.xml only include the block for USB_OTG_FS, although all H7R/S MCUs, including the H7R7A8 and H7S7Z8, should have HS USB with an integrated PHY.

wow that's annoying. I've tried updating the xmls from the latest Cube but OTG_HS is still missing. I'd just workaround it for now: use #[cfg(peri_otg_hs)] to conditionally-compile code only if OTG_HS is present.

I'd wait for ST to fix it, perhaps report it. Where do you report cubemx bugs? 🤔

@doesnotcompete
Copy link
Contributor Author

The CI failure is apparently caused by a missing definition of the OTG_HS IP block in the cubedb source files of stm32-data.
STM32H7R7A8Ix.xml and STM32H7S7Z8Jx.xml only include the block for USB_OTG_FS, although all H7R/S MCUs, including the H7R7A8 and H7S7Z8, should have HS USB with an integrated PHY.

wow that's annoying. I've tried updating the xmls from the latest Cube but OTG_HS is still missing. I'd just workaround it for now: use #[cfg(peri_otg_hs)] to conditionally-compile code only if OTG_HS is present.

I'd wait for ST to fix it, perhaps report it. Where do you report cubemx bugs? 🤔

That's a great idea :) I've added a check in the latest commit and also tried reporting the issue to ST here on GitHub.

Copy link
Member

@Dirbaio Dirbaio left a comment

Choose a reason for hiding this comment

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

thanks! 🚀

@Dirbaio Dirbaio added this pull request to the merge queue Sep 22, 2024
Merged via the queue into embassy-rs:main with commit 9705f33 Sep 23, 2024
6 checks passed
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.

3 participants