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

drivers/usbdev_synopsys_dwc2: add support for internal UTMI HS PHY #18714

Merged

Conversation

gschorcht
Copy link
Contributor

@gschorcht gschorcht commented Oct 9, 2022

Contribution description

This PR adds the support for internal UTMI+ HS PHYs.

Boards whose MCU integrate an UMTI+ HS PHY for their USB OTG HS peripherals, such as the STM32F723xx used on board stm32f723e-disco, can be used in USB HS mode with this PR. The UTMI+ HS PHY support is enabled by the periph_usbdev_hs_utmi module, which requires the periph_usbdev_hs_utmi feature.

Testing procedure

The best way to test the PR is to use a board with two USB OTG ports (one FS port and one HS port with internal UTMI+ HS PHY, such as the board "stm32f723e-disco") connected to the host with two USB cables.

  1. Compile and flash application tests/usbus_hid
    BOARD=stm32f723e-disco make -C tests/usbus_hid flash term
    
    The FS port should still work.
    Oct  9 17:14:16 gunny8 kernel: [2342975.208076] usb 1-2.2: new full-speed USB device number 86 using xhci_hcd
    Oct  9 17:14:16 gunny8 kernel: [2342975.310550] usb 1-2.2: New USB device found, idVendor=1209, idProduct=7d01, bcdDevice= 1.00
    Oct  9 17:14:16 gunny8 kernel: [2342975.310552] usb 1-2.2: New USB device strings: Mfr=3, Product=2, SerialNumber=4
    Oct  9 17:14:16 gunny8 kernel: [2342975.310554] usb 1-2.2: Product: stm32f723e-disco
    Oct  9 17:14:16 gunny8 kernel: [2342975.310556] usb 1-2.2: Manufacturer: RIOT-os.org
    Oct  9 17:14:16 gunny8 kernel: [2342975.310557] usb 1-2.2: SerialNumber: A7BAC4E1B1E0806B
    Oct  9 17:14:16 gunny8 kernel: [2342975.318366] hid-generic 0003:1209:7D01.01A5: hiddev2,hidraw5: USB HID v1.10 Device [RIOT-os.org stm32f723e-disco] on usb-0000:00:14.0-2.2/input0
  2. Compile and flash application tests/usbus_hid with module periph_usbdev_hs_utmi
    USEMODULE=periph_usbdev_hs_utmi BOARD=stm32f723e-disco make -C tests/usbus_hid flash term
    
    In that case, the HS port should work and should be recognized as HS device.
    Oct  9 16:59:10 gunny8 kernel: [2342069.036905] usb 1-2.4: new high-speed USB device number 84 using xhci_hcd
    Oct  9 16:59:10 gunny8 kernel: [2342069.141739] usb 1-2.4: New USB device found, idVendor=1209, idProduct=7d01, bcdDevice= 1.00
    Oct  9 16:59:10 gunny8 kernel: [2342069.141742] usb 1-2.4: New USB device strings: Mfr=3, Product=2, SerialNumber=4
    Oct  9 16:59:10 gunny8 kernel: [2342069.141743] usb 1-2.4: Product: stm32f723e-disco
    Oct  9 16:59:10 gunny8 kernel: [2342069.141745] usb 1-2.4: Manufacturer: RIOT-os.org
    Oct  9 16:59:10 gunny8 kernel: [2342069.141746] usb 1-2.4: SerialNumber: A7BAC4E1B1E0806B
    Oct  9 16:59:10 gunny8 kernel: [2342069.144525] hid-generic 0003:1209:7D01.01A4: hiddev2,hidraw5: USB HID v1.10 Device [RIOT-os.org stm32f723e-disco] on usb-0000:00:14.0-2.4/input0
  3. A board with USB OTG HS peripheral that uses the on-chip FS PHY, such as stm32f429i-disc1 should still work.
    BOARD=stm32f429i-disco make -C tests/usbus_hid flash term
    
  4. A board with only USB OTG FS peripheral should still work.
    BOARD=nucleo-f767zi make -C tests/usbus_hid flash term
    

Issues/PRs references

The existence of the macros USB_OTG_GUSBCFG_ULPI_UTMI_SEL, USB_OTG_GUSBCFG_PHYIF and USB_OTG_GUSBCFG_DDRSEL depends on a specific STM32 line and not on STM32 itself. Therefore, the settings are made when the macros are defined.
@github-actions github-actions bot added Area: boards Area: Board ports Area: drivers Area: Device drivers Area: Kconfig Area: Kconfig integration labels Oct 9, 2022
@gschorcht gschorcht added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 9, 2022
@riot-ci
Copy link

riot-ci commented Oct 9, 2022

Murdock results

✔️ PASSED

f1bc9af board/stm32f723e-dsico: enable internal UMTI USB HS PHY feature

Success Failures Total Runtime
1983 0 1983 06m:41s

Artifacts

This only reflects a subset of all builds from https://ci-prod.riot-os.org. Please refer to https://ci.riot-os.org for a complete build for now.

@benpicco benpicco requested review from bergzand and fabian18 October 10, 2022 10:15
boards/stm32f723e-disco/include/periph_conf.h Show resolved Hide resolved
/* configure the tuning interface of the USB HS PHY,
* the magic value (USB_HS_PHYC_TUNE_VALUE) from STM32CubeF7 HAL
* Driver MCU Component for F7 is used */
USB_HS_PHYC->USB_HS_PHYC_TUNE |= 0x00000F13U;
Copy link
Member

Choose a reason for hiding this comment

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

Based on the stm32f723 reference manual, this register doesn't look that magical. It does seem to contain quite a number of board-dependent options. Does it make sense to add this to the configuration struct together with some generic 'recommended' value (this 0x0F13U maybe)?

Copy link
Contributor Author

@gschorcht gschorcht Oct 12, 2022

Choose a reason for hiding this comment

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

Based on the stm32f723 reference manual, this register doesn't look that magical.

Yes, I have seen it. However, the number of possible combinations of these options is quite large and might lead to misconfigurations. To be honest, I wouldn't have any idea how to configure it properly. The value is taken from STM32CubeF7.

We could either add it to the configurationstructure or we could use something like the STM32CubeF7 HAL driver in drivers/include/usbdev_synopsys_dwc2.h

#ifndef USB_HS_PHYC_TUNE_VALUE
#define USB_HS_PHYC_TUNE_VALUE     0x00000F13U
#endif

and use this define in the driver. The value can then be overridden in the board configuration.

Copy link
Member

Choose a reason for hiding this comment

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

We either add it to the configuration structure or we could use something like the STM32CubeF7 HAL driver in drivers/include/usbdev_synopsys_dwc2.h

I'm fine with either solution, I don't think we need to have a field in the config struct for every individual bit in that register though.

@github-actions github-actions bot added the Area: doc Area: Documentation label Oct 12, 2022
}

/* configure the tuning interface of the USB HS PHY */
USB_HS_PHYC->USB_HS_PHYC_TUNE = conf->phy_tune;
Copy link
Contributor Author

@gschorcht gschorcht Oct 12, 2022

Choose a reason for hiding this comment

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

I'm not really sure whether the configured USBPHYC_TUNE (default 0x00000f13) register value has to be ORed or should overwrite the reset value 0x00000004 of the register. Bit2 enables the the Low Full Speed feedback capacitor. tinyUSB ORs this value.

Copy link
Member

Choose a reason for hiding this comment

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

No strong opinion from my side, pick whatever you think is good here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the STM32CubeF7 HAL driver also OR this value, I decided to OR it too. PR is squashed. Let's see whether Murdock is happy.

@bergzand
Copy link
Member

Feel free to squash btw

@gschorcht gschorcht force-pushed the drivers/usbdev_synopsys_dwc2_hs_utmi branch from 886da45 to d77700a Compare October 13, 2022 04:26
@maribu maribu added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 13, 2022
@bergzand bergzand enabled auto-merge October 13, 2022 07:57
@maribu maribu added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 13, 2022
@maribu maribu added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 13, 2022
@dylad dylad added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 13, 2022
@maribu maribu added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 13, 2022
kconfigs/Kconfig.features Outdated Show resolved Hide resolved
kconfigs/Kconfig.features Outdated Show resolved Hide resolved
@gschorcht gschorcht force-pushed the drivers/usbdev_synopsys_dwc2_hs_utmi branch from df6a3ed to f1bc9af Compare October 16, 2022 09:45
@bergzand bergzand merged commit 0fca912 into RIOT-OS:master Oct 16, 2022
@gschorcht gschorcht deleted the drivers/usbdev_synopsys_dwc2_hs_utmi branch October 16, 2022 23:12
@kaspar030 kaspar030 added this to the Release 2023.01 milestone Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: doc Area: Documentation Area: drivers Area: Device drivers Area: Kconfig Area: Kconfig integration CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants