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

USB HS support fixes on STM32U5 #80249

Closed

Conversation

erikarn
Copy link

@erikarn erikarn commented Oct 22, 2024

  • The dev board in question has the bits populated to support USB 2.0 high speed, so add it to the documentation and device tree
  • Add support to the STM32 USB 2.0 driver to support a non-default clock source

(This was for pull reuqest 80249, but that was against main and not a branch, and I was asked on discord to put it in a branch)

@erikarn
Copy link
Author

erikarn commented Oct 22, 2024

Yay it passed all the tests!

Copy link
Collaborator

@mathieuchopstm mathieuchopstm left a comment

Choose a reason for hiding this comment

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

Looks OK. A few nits and proposals for simplification:

boards/st/nucleo_u5a5zj_q/doc/index.rst Outdated Show resolved Hide resolved
dts/bindings/phy/st,stm32-otghs-phy.yaml Outdated Show resolved Hide resolved
dts/bindings/phy/st,stm32-otghs-phy.yaml Outdated Show resolved Hide resolved
dts/bindings/phy/st,stm32-otghs-phy.yaml Outdated Show resolved Hide resolved
dts/bindings/phy/st,stm32-otghs-phy.yaml Outdated Show resolved Hide resolved
drivers/usb/device/usb_dc_stm32.c Outdated Show resolved Hide resolved
drivers/usb/device/usb_dc_stm32.c Outdated Show resolved Hide resolved
drivers/usb/device/usb_dc_stm32.c Outdated Show resolved Hide resolved
dts/arm/st/u5/stm32u595.dtsi Outdated Show resolved Hide resolved
dts/arm/st/u5/stm32u595.dtsi Outdated Show resolved Hide resolved
@erikarn erikarn force-pushed the 20241022_adrian_stm32u5_usb branch 2 times, most recently from b50f9bb to 8e7537c Compare October 23, 2024 17:06
@erikarn erikarn force-pushed the 20241022_adrian_stm32u5_usb branch from 8e7537c to 65920fa Compare October 24, 2024 17:10
@zephyrbot zephyrbot requested a review from nordic-krch October 24, 2024 17:10
@erikarn erikarn force-pushed the 20241022_adrian_stm32u5_usb branch from 65920fa to a29b7cb Compare October 24, 2024 18:17
drivers/usb/device/usb_dc_stm32.c Outdated Show resolved Hide resolved
drivers/usb/device/usb_dc_stm32.c Outdated Show resolved Hide resolved
include/zephyr/dt-bindings/phy/stm32u5_otg_hs_phy.h Outdated Show resolved Hide resolved
@erikarn erikarn force-pushed the 20241022_adrian_stm32u5_usb branch 2 times, most recently from a07f824 to 6c9969c Compare October 28, 2024 17:50
@erikarn
Copy link
Author

erikarn commented Oct 29, 2024

anything else? is everything ok to merge? :P

@JarmouniA
Copy link
Collaborator

anything else? is everything ok to merge? :P

This PR will have to go into 4.1 (once 4.0 releases) as we are now in the 4.0 feature freeze.

@erikarn
Copy link
Author

erikarn commented Oct 29, 2024

anything else? is everything ok to merge? :P

This PR will have to go into 4.1 (once 4.0 releases) as we are now in the 4.0 feature freeze.

oh! dang ok, what's the timeline for that? I'm just trying to avoid multiple merges on my side!

@JarmouniA
Copy link
Collaborator

anything else? is everything ok to merge? :P

This PR will have to go into 4.1 (once 4.0 releases) as we are now in the 4.0 feature freeze.

oh! dang ok, what's the timeline for that? I'm just trying to avoid multiple merges on my side!

https://github.com/zephyrproject-rtos/zephyr/milestone/75

@mniestroj
Copy link
Member

Please add usb_device tag to nucleo_u5a5zj_q.yaml.

@erikarn erikarn force-pushed the 20241022_adrian_stm32u5_usb branch from 6c9969c to 02211d8 Compare November 26, 2024 19:05
@erikarn erikarn force-pushed the 20241022_adrian_stm32u5_usb branch from 02211d8 to 641353b Compare December 2, 2024 20:56
@erikarn
Copy link
Author

erikarn commented Dec 2, 2024

Please add usb_device tag to nucleo_u5a5zj_q.yaml.

hi! can you explain that a bit more please?

@erikarn erikarn force-pushed the 20241022_adrian_stm32u5_usb branch 2 times, most recently from bdeb107 to 22dfc2e Compare December 2, 2024 23:48
@mniestroj
Copy link
Member

Please add usb_device tag to nucleo_u5a5zj_q.yaml.

hi! can you explain that a bit more please?

See

. This advertises that USB device mode is supported, so that twister will build samples that utilize USB device mode.

Adrian Chadd added 2 commits December 3, 2024 11:04
…ephyrproject-rtos#79823)

This board has the required clock crystal (X4) and jumper settings
present to enable the USB 2.0 HS support.

* Enable the HSE clock (16MHz)
* Flip the PLL1 configuration over to use the HSE clock, but still
  outputting 160MHz to sysclk/apbclk.
* Add the USB HS device tree node.
* Update the board documentation.

Signed-off-by: Adrian Chadd <[email protected]>
…5xxx

The existing code assumes that the HSE clock is a 16MHz crystal, however
the hardware allows for a list of possible HSE clock values.

Add them here as an enum, configure it for the STM32U595 chipset
(which is the only device I have access to for testing).

This addresses Issue zephyrproject-rtos#79825 .

* Rename USBPHYC_SEL -> OTGHS_SEL which matches the definition in the
  stm32u5 CCIPR2 register (RM0456 Rev 5, Section 11.8.47).
* Add a list of possible values to use in the DT bindings directory
* Add a new PHY (st,stm32-otghs-phy) with an enum list matching the
  above list
* Add support in the USB driver for checking the clock-cfg entry
  and compiling in the correct clock rate.
* And also handle an out of enum configuration by failing compilation.

Signed-off-by: Adrian Chadd <[email protected]>
@erikarn erikarn force-pushed the 20241022_adrian_stm32u5_usb branch from 22dfc2e to e21b99c Compare December 3, 2024 19:04
@erikarn
Copy link
Author

erikarn commented Dec 3, 2024

Please add usb_device tag to nucleo_u5a5zj_q.yaml.

hi! can you explain that a bit more please?

See

. This advertises that USB device mode is supported, so that twister will build samples that utilize USB device mode.

Done!

@erikarn
Copy link
Author

erikarn commented Dec 3, 2024

ok, since this is a long review, would someone please help summarise what's left for me to address? Thanks!

Copy link
Member

@mniestroj mniestroj left a comment

Choose a reason for hiding this comment

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

See some of my comments.

We also need to address OTGEN and OTGHSPHYEN clock enabling in RCC_AHB2ENR1 register. Commit 57723cf has changed from enabling both bits to just enabling OTGHSPHYEN (bit 15) with:

clocks = <&rcc STM32_CLOCK(AHB2, 15U)>,

I think we should choose one of those options:

  1. Select OTG and OTG_PHY clocks separately in each devicetree node. This means that we should add clocks property to OTG_PHY node. That property will allow to define bit that enabled OTG_PHY clock, but will also allow us to select clock configuration (e.g. whether it is HSE, PLL1, HSE/2 or PLL1/2...).
  2. Use only OTG devicetree node to select all clocks (including OTG_PHY). That way we should move clock-cfg selection out of OTG_PHY node, so we are consistent with where we select clock.

Comment on lines +19 to +24
- 1 # OTGHS_PHY_CLK_16MHZ
- 2 # OTGHS_PHY_CLK_19P2MHZ
- 3 # OTGHS_PHY_CLK_20MHZ
- 4 # OTGHS_PHY_CLK_24MHZ
- 5 # OTGHS_PHY_CLK_26MHZ
- 6 # OTGHS_PHY_CLK_32MHZ
Copy link
Member

Choose a reason for hiding this comment

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

I think it makes more sense to define list of possible frequencies:

      - 16000000
      - 19200000
      - 20000000
      - 24000000
      - 26000000
      - 32000000

here. That way it will still be pretty straightforward to select specific configuration in devicetree, e.g. with DT_FREQ_M(16), while being able to drop include/zephyr/dt-bindings/phy/stm32u5_otg_hs_phy.h entirely.

@@ -107,15 +107,15 @@
ram-size = <4096>;
maximum-speed = "high-speed";
clocks = <&rcc STM32_CLOCK(AHB2, 15U)>,
<&rcc STM32_SRC_HSI48 ICKLK_SEL(0)>;
<&rcc STM32_SRC_HSI48 OTGHS_SEL(0)>;
Copy link
Member

Choose a reason for hiding this comment

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

Though STM32_SRC_HSI48 is not used by the driver (only second cell is used to configure clock, i.e. OTGHS_SEL(0)), it is confusing to leave it like that since OTGHS_SEL(0) select HSE and not HSI48 as input clock.

Switching that to STM32_SRC_HSE seems the way to go. However, we need to disable CONFIG_USB_DC_STM32_CLOCK_CHECK so it won't complain about 48MHz frequency. Or we can update that check (it won't be easy to cover all cases, so I guess we can leave that as future enhancement).

@mniestroj
Copy link
Member

Another thing that might be worth considering is calculating 16MHz...32MHz (which in current PR implementation is done with clock-cfg OTG_PHY property) in the driver implementation. In theory we could calculate that speed based on selected clock source (e.g. when we would have clocks = <&clk_hse>; or clocks = <&pll1>; in OTG_PHY). That would probably mean more calculations in runtime, but it would improve developer experience, since there would be much easier way to select clocks (less things to select in devicetree).

@mniestroj
Copy link
Member

Please take a look at #82540, which implements following suggestion I had:

Another thing that might be worth considering is calculating 16MHz...32MHz (which in current PR implementation is done with clock-cfg OTG_PHY property) in the driver implementation. In theory we could calculate that speed based on selected clock source (e.g. when we would have clocks = <&clk_hse>; or clocks = <&pll1>; in OTG_PHY). That would probably mean more calculations in runtime, but it would improve developer experience, since there would be much easier way to select clocks (less things to select in devicetree).

@erikarn
Copy link
Author

erikarn commented Dec 4, 2024

ok, this is all great feedback and ideas, but my goal right now is to get /something/ working into the tree that we can then build on. I kind of feel like I've stumbled into a rabbit hole of many "oh and this sharp corner should be fixed" tasks, which is great and I'd love to help with! But I'd also like to get something working into the tree.

I'll go and re-test today and see if it even works. If it doesn't work without the clock enable then I'd appreciate some hand-holding to get that lined up. Even just getting the /first/ diff in the stack landed to enable USB on this board would be super helpful.

Thanks!

@erikarn
Copy link
Author

erikarn commented Dec 4, 2024

ok, so testing with the cdc_acm demo again:

  • yeah, i needed to enable both clocks for USB init to work
  • USB init is fine, CDC-ADM is fine, linux finds it
  • DTR is never set when I connect to it
  • I hit divide by zero's if I get to the DCD/DSR calls in the demo
  • Commenting them out - I get through to baud rate, but now the echo part isn't working

So, there's been a bunch of other regressions in the meantime. This is why I really want to get this landed in some working form first! :)

@erikarn
Copy link
Author

erikarn commented Dec 4, 2024

ok, PEBKAC - bad USB cable on the USB-C side. Yup, with that clock bit set, the demo still works fine.

So first step - what to do about configuring that missing clock bit (bit 14). This seems like it could be a problem for other boards/parts, no? Should we create a separate diff /just/ for figuring out what to do there?

@erwango
Copy link
Member

erwango commented Dec 5, 2024

So first step - what to do about configuring that missing clock bit (bit 14). This seems like it could be a problem for other boards/parts, no? Should we create a separate diff /just/ for figuring out what to do there?

Can you clarify ?

@erikarn
Copy link
Author

erikarn commented Dec 5, 2024

So first step - what to do about configuring that missing clock bit (bit 14). This seems like it could be a problem for other boards/parts, no? Should we create a separate diff /just/ for figuring out what to do there?

Can you clarify ?

Did any other STM32 parts get caught out by this clock config refactor? is it /just/ the stm32u5 series stuff that was setting >1 clock enable in the RCC?

@erwango
Copy link
Member

erwango commented Dec 6, 2024

Did any other STM32 parts get caught out by this clock config refactor? is it /just/ the stm32u5 series stuff that was setting >1 clock enable in the RCC?

Not that I know, should be limited to U5 indeed.

Copy link
Collaborator

@jfischer-no jfischer-no left a comment

Choose a reason for hiding this comment

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

In the last commit, remove (Issue #79823) from the commit title.

@erwango
Copy link
Member

erwango commented Dec 12, 2024

Closing as superseded by #82540

@erwango erwango closed this Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Clock Control area: USB Universal Serial Bus platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants