apache / apache/nuttx

stm32_otgfsdev not working on stm32f411-minimum

Open
#8,968 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
4k
Forks
1.7k
Avg merge
1d 17h
Merged PRs (30d)
237

Description

## Summary
I can't get USB OTG to work in device mode on WeAct BlackPill STM32F411CEU6 rev 3.1 in CDC/ACM, MSC and COMPOSITE configurations.
## Impact
Possibly all stm32f4-based boards and dwc2 IP users without VBUS_SENSE pad routed.
## Description
As I was bringing up some more configs for stm32f411-minimum, I stumbled upon non-working USBDEV. USBHOST won't work because I didn't bridge VBUS with onboard 5V pin yet, and I don't need USBHOST on this board.

I see several issues in stm32_otgfsdev driver code:
1. VBUSASEN/VBUSBSEN bits are written unconditionally. Does NOVBUSSENS actually override them in this IP core version?
```patch
diff --git a/arch/arm/src/stm32/stm32_otgfsdev.c b/arch/arm/src/stm32/stm32_otgfsdev.c
index a0a9ecb70..7bf89426c 100644
--- a/arch/arm/src/stm32/stm32_otgfsdev.c
+++ b/arch/arm/src/stm32/stm32_otgfsdev.c
@@ -5362,9 +5362,11 @@ static void stm32_hwinitialize(struct stm32_usbdev_s *priv)
* Sense when Set
*/

- regval = (OTGFS_GCCFG_PWRDWN | OTGFS_GCCFG_VBUSASEN |
- OTGFS_GCCFG_VBUSBSEN);
-# ifndef CONFIG_USBDEV_VBUSSENSING
+ regval = OTGFS_GCCFG_PWRDWN;
+
+# ifdef CONFIG_USBDEV_VBUSSENSING
+ regval |= OTGFS_GCCFG_VBUSBSEN;
+# else
regval |= OTGFS_GCCFG_NOVBUSSENS;
# endif
# ifdef CONFIG_STM32_OTGFS_SOFOUTPUT
```

2. CONFIG_STM32_USBDEV_REGDEBUG option is unreachable. I added it to Kconfig myself to achieve the following trace:

```patch
diff --git a/arch/arm/src/stm32/Kconfig b/arch/arm/src/stm32/Kconfig
index 214a31ef3..7094ea2a6 100644
--- a/arch/arm/src/stm32/Kconfig
+++ b/arch/arm/src/stm32/Kconfig
@@ -11088,6 +11088,15 @@ config STM32_USBFS_REGDEBUG

endmenu

+menu "USB OTG Device Debug Configuration"
+
+config STM32_USBDEV_REGDEBUG
+ bool "Register-Level Debug for OTG in Device mode"
+ default n
+ depends on USBDEV && DEBUG_USB_INFO
+
+endmenu
+
menu "OTG Configuration"
depends on STM32_OTGFS

```

I input sercon, msconn, conn and disconn. The latter triggered an assert because my Gentoo Host cannot enumerate this device.

```
ern :info : [ +18.810180] usb 1-8: new full-speed USB device number 20 using xhci_hcd
kern :err : [ +0.204052] usb 1-8: device descriptor read/64, error -71
kern :err : [ +0.280011] usb 1-8: device descriptor read/64, error -71
kern :info : [ +0.281943] usb 1-8: new full-speed USB device number 21 using xhci_hcd
kern :err : [ +0.205060] usb 1-8: device descriptor read/64, error -71
kern :err : [ +0.280995] usb 1-8: device descriptor read/64, error -71
kern :info : [ +0.106046] usb usb1-port8: attempt power cycle
kern :info : [Apr 5 11:16] usb 1-8: new full-speed USB device number 22 using xhci_hcd
kern :warn : [ +0.026800] usb 1-8: Device not responding to setup address.
kern :warn : [ +0.236003] usb 1-8: Device not responding to setup address.
kern :err : [ +0.205205] usb 1-8: device not accepting address 22, error -71
kern :info : [ +0.179008] usb 1-8: new full-speed USB device number 23 using xhci_hcd
kern :warn : [ +0.026811] usb 1-8: Device not responding to setup address.
kern :warn : [ +0.237983] usb 1-8: Device not responding to setup address.
kern :err : [ +0.204205] usb 1-8: device not accepting address 23, error -71
kern :err : [ +0.004012] usb usb1-port8: unable to enumerate USB device
```

Wireshark usbmon0 traces later. STM32 DfuSe USB BootROM works.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.