Skip to content

Conversation

mathieuchopstm
Copy link
Contributor

@mathieuchopstm mathieuchopstm commented Sep 15, 2025

Rework how the STM32 USB driver determines the PHY type and operating speed. This approach is more solid, based on the phys property and compatible on the node itself, rather than looking at which nodes are enabled and hoping for the best. PCD_PHY_xxx and PCD_SPEED_xxx macros, which should be more portable, are also used now in place of the LL USB macros.

Commit 7ff59b5 is cherry-picked from #89866; it is not strictly related to PR's contents, but HS does not work without it. Since this PR supersedes #89866, the commit could be merged as part of it; however, I don't mind #89866 being modified to only include this commit or a separate PR being opened...

This PR also partially supersedes #86100 (only a few cosmetic(?) changes are missing here).

@mathieuchopstm mathieuchopstm force-pushed the stm32_usb_phy_speed_cleanup branch from b78b0c4 to e04d03d Compare September 16, 2025 14:07
@mathieuchopstm mathieuchopstm marked this pull request as ready for review September 16, 2025 14:07
@mathieuchopstm
Copy link
Contributor Author

Tested OK:

  • samples/subsys/usb/legacy/cdc_acm
    • nucleo_l552ze_q (ST USB, FS)
    • b_u585i_iot02a (otgfs, FS)
    • nucleo_u5a5zj_q (otghs, HS only)
  • samples/subsys/usb/testusb
    • nucleo_l552ze_q
    • b_u585i_iot02a
    • nucleo_u5a5zj_q (both FS & HS)
testusb results

For all result logs:

testusb output
- dmesg output
+ Zephyr console output

nucleo_l552ze_q (ST USB, full-speed)

./testusb: /dev/bus/usb/003/054 may see only control tests
full speed	/dev/bus/usb/003/054	0
-[108265.467441] usbtest 3-5.1:1.0: TEST 0:  NOP
/dev/bus/usb/003/054 test 0,    0.000005 secs
-[108265.468344] usbtest 3-5.1:1.0: TEST 1:  write 1024 bytes 1000 times
/dev/bus/usb/003/054 test 1,    1.700393 secs
-[108267.169703] usbtest 3-5.1:1.0: TEST 2:  read 1024 bytes 1000 times
/dev/bus/usb/003/054 test 2,    1.340087 secs
-[108268.510793] usbtest 3-5.1:1.0: TEST 3:  write/512 0..1024 bytes 1000 times
/dev/bus/usb/003/054 test 3,    0.857838 secs
-[108269.369833] usbtest 3-5.1:1.0: TEST 4:  read/512 0..1024 bytes 1000 times
/dev/bus/usb/003/054 test 4,    0.718781 secs
-[108270.089760] usbtest 3-5.1:1.0: TEST 5:  write 1000 sglists 32 entries of 1024 bytes
/dev/bus/usb/003/054 test 5,   49.432600 secs
-[108319.523645] usbtest 3-5.1:1.0: TEST 6:  read 1000 sglists 32 entries of 1024 bytes
/dev/bus/usb/003/054 test 6,   41.355880 secs
-[108360.880772] usbtest 3-5.1:1.0: TEST 7:  write/512 1000 sglists 32 entries 0..1024 bytes
/dev/bus/usb/003/054 test 7,   25.589572 secs
-[108386.471525] usbtest 3-5.1:1.0: TEST 8:  read/512 1000 sglists 32 entries 0..1024 bytes
/dev/bus/usb/003/054 test 8,   21.426146 secs
-[108407.898842] usbtest 3-5.1:1.0: TEST 9:  ch9 (subset) control tests, 1000 times
/dev/bus/usb/003/054 test 9,    1.944577 secs
-[108409.844422] usbtest 3-5.1:1.0: TEST 10:  queue 32 control calls, 1000 times
/dev/bus/usb/003/054 test 10,    6.821551 secs
-[108416.667107] usbtest 3-5.1:1.0: TEST 11:  unlink 1000 reads of 1024
-[108416.678789] usbtest 3-5.1:1.0: unlink retry             <---- this is repeated many times
/dev/bus/usb/003/054 test 11,    8.108794 secs
-[108424.777158] usbtest 3-5.1:1.0: TEST 12:  unlink 1000 writes of 1024
-[108424.900437] usbtest 3-5.1:1.0: unlink retry             <---- this is repeated many times
/dev/bus/usb/003/054 test 12,    7.672840 secs
-[108432.451190] usbtest 3-5.1:1.0: TEST 13:  set/clear 1000 halts
-[108442.703917] usb 3-5.1: verify_not_halted failed, iterations left 0, status -110 (not 0)
-[108442.703962] usbtest 3-5.1:1.0: halts failed, iterations left 999
/dev/bus/usb/003/054 test 13 --> 22 (error 22)
-[108442.705366] usbtest 3-5.1:1.0: TEST 14:  1000 ep0out, 1..1024 vary 512
+[00:01:10.082,000] <err> udc_stm32: UDC Message queue overrun
+[00:01:10.088,000] <err> udc_stm32: UDC Message queue overrun
+[00:01:10.094,000] <err> udc_stm32: UDC Message queue overrun
+[00:01:10.101,000] <err> udc_stm32: UDC Message queue overrun
+0[00:01:10.107,000] <err> udc_stm32: UDC Message queue overrun
+[00:01:10.114,000] <err> udc_stm32: UDC Message queue overrun
+[00:01:10.120,000] <err> udc_stm32: UDC Message queue overrun
+74,000] <err> udc_stm32: ep 0x00 queue is empty
+[00:01:10.132,000] <err> udc_stm32: ep 0x00 queue is empty
+[00:01:10.138,000] <err> udc_stm32: ep 0x00 queue is empty
+[00:01:10.144,000] <err> udc_stm32: ep 0x00 queue is empty
+[00:01:10.150,000] <err> udc_stm32: ep 0x00 queue is empty
+[00:01:10.156,000] <err> udc_stm32: ep 0x00 queue is empty
+[00:01:10.163,000] <err> udc_stm32: ep 0x00 queue is empty
+[00:01:10.169,000] <err> udc_stm32: ep 0x00 queue is empty
+[00:01:10.175,000] <err> udc_stm32: ep 0x00 queue is empty
-[108447.824158] usbtest 3-5.1:1.0: ctrl_out read failed, code -110, count 0
/dev/bus/usb/003/054 test 14 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/054 test 15 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/054 test 16 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/054 test 17 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/054 test 18 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/054 test 19 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/054 test 20 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/054 test 21 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/054 test 22 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/054 test 23 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/054 test 24 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/054 test 25 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/054 test 26 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: TEST 27: bulk write 31Mbytes
+[00:xx:00.xxx,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:xx:00.xxx,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:xx:00.xxx,000] <err> usbd_ch9: Malformed setup packet
+[00:xx:00.xxx,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:xx:00.xxx,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:xx:00.xxx,000] <err> usbd_ch9: Malformed setup packet
+[00:xx:00.xxx,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:xx:00.xxx,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:xx:00.xxx,000] <err> usbd_ch9: Malformed setup packet
/dev/bus/usb/003/054 test 27,   48.889804 secs
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: TEST 28: bulk read 31Mbytes
+[00:xx:00.xxx,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:xx:00.xxx,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:xx:00.xxx,000] <err> usbd_ch9: Malformed setup packet
+[00:xx:00.xxx,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:xx:00.xxx,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:xx:00.xxx,000] <err> usbd_ch9: Malformed setup packet
+[00:xx:00.xxx,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:xx:00.xxx,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:xx:00.xxx,000] <err> usbd_ch9: Malformed setup packet
/dev/bus/usb/003/054 test 28,   41.245456 secs
-[109298.271437] usbtest 3-5.1:1.0: TEST 29: Clear toggle between bulk writes 1000 times
+[00:05:36.938,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:05:36.945,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:05:36.952,000] <err> usbd_ch9: Malformed setup packet
+[00:05:36.958,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:05:36.965,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:05:36.972,000] <err> usbd_ch9: Malformed setup packet
+[00:05:36.978,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:05:36.985,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:05:36.992,000] <err> usbd_ch9: Malformed setup packet
+[00:05:36.999,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:05:37.005,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:05:37.012,000] <err> usbd_ch9: Malformed setup packet
-[109298.291624] usbtest 3-5.1:1.0: ep 01 couldn't clear halt, -32
-[109298.291632] usbtest 3-5.1:1.0: toggle sync failed, iterations left 999
/dev/bus/usb/003/054 test 29 --> 32 (error 32)

b_u585i_iot02a (otgfs, full-speed)

./testusb: /dev/bus/usb/003/047 may see only control tests
full speed	/dev/bus/usb/003/047	0
-[105937.077947] usbtest 3-5.1:1.0: TEST 0:  NOP
/dev/bus/usb/003/047 test 0,    0.000003 secs
-[105937.078798] usbtest 3-5.1:1.0: TEST 1:  write 1024 bytes 1000 times
/dev/bus/usb/003/047 test 1,    1.634248 secs
-[105938.714010] usbtest 3-5.1:1.0: TEST 2:  read 1024 bytes 1000 times
/dev/bus/usb/003/047 test 2,    1.290493 secs
-[105940.005559] usbtest 3-5.1:1.0: TEST 3:  write/512 0..1024 bytes 1000 times
/dev/bus/usb/003/047 test 3,    0.860289 secs
-[105940.866775] usbtest 3-5.1:1.0: TEST 4:  read/512 0..1024 bytes 1000 times
/dev/bus/usb/003/047 test 4,    0.728755 secs
-[105941.596536] usbtest 3-5.1:1.0: TEST 5:  write 1000 sglists 32 entries of 1024 bytes
/dev/bus/usb/003/047 test 5,   48.984239 secs
-[105990.581984] usbtest 3-5.1:1.0: TEST 6:  read 1000 sglists 32 entries of 1024 bytes
/dev/bus/usb/003/047 test 6,   39.052892 secs
-[106029.636363] usbtest 3-5.1:1.0: TEST 7:  write/512 1000 sglists 32 entries 0..1024 bytes
/dev/bus/usb/003/047 test 7,   25.327574 secs
-[106054.965050] usbtest 3-5.1:1.0: TEST 8:  read/512 1000 sglists 32 entries 0..1024 bytes
/dev/bus/usb/003/047 test 8,   20.268981 secs
-[106075.234990] usbtest 3-5.1:1.0: TEST 9:  ch9 (subset) control tests, 1000 times
/dev/bus/usb/003/047 test 9,    1.757893 secs
-[106076.993789] usbtest 3-5.1:1.0: TEST 10:  queue 32 control calls, 1000 times
/dev/bus/usb/003/047 test 10,    6.681589 secs
-[106083.676377] usbtest 3-5.1:1.0: TEST 11:  unlink 1000 reads of 1024
-[106084.754246] usbtest 3-5.1:1.0: unlink retry
/dev/bus/usb/003/047 test 11,    8.051909 secs
-[106091.729301] usbtest 3-5.1:1.0: TEST 12:  unlink 1000 writes of 1024
-[106095.770477] usbtest 3-5.1:1.0: unlink retry             <---- repeated many times
/dev/bus/usb/003/047 test 12,    8.043141 secs
- [106099.773512] usbtest 3-5.1:1.0: TEST 13:  set/clear 1000 halts
/dev/bus/usb/003/047 test 13,    7.129598 secs
-[106106.904154] usbtest 3-5.1:1.0: TEST 14:  1000 ep0out, 1..1024 vary 512
-[106112.068645] usbtest 3-5.1:1.0: ctrl_out write failed, code -110, count 0
/dev/bus/usb/003/047 test 14 --> 110 (error 110)
-[106117.189157] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/047 test 15 --> 110 (error 110)
[106122.309363] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/047 test 16 --> 110 (error 110)
-[106127.429512] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/047 test 17 --> 110 (error 110)
-[106132.549499] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/047 test 18 --> 110 (error 110)
-[106137.669388] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/047 test 19 --> 110 (error 110)
-[106142.789532] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/047 test 20 --> 110 (error 110)
-[106147.909469] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/047 test 21 --> 110 (error 110)
-[106153.029323] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/047 test 22 --> 110 (error 110)
-[106158.149583] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/047 test 23 --> 110 (error 110)
-[106163.269702] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/047 test 24 --> 110 (error 110)
-[106168.389896] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/047 test 25 --> 110 (error 110)
-[106173.509669] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/047 test 26 --> 110 (error 110)
-[106173.570950] usbtest 3-5.1:1.0: TEST 27: bulk write 31Mbytes
+[00:04:06.658,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:04:06.665,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:04:06.672,000] <err> usbd_ch9: Malformed setup packet
+[00:04:06.678,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:04:06.685,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:04:06.692,000] <err> usbd_ch9: Malformed setup packet
+[00:04:06.698,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:04:06.705,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:04:06.712,000] <err> usbd_ch9: Malformed setup packet
/dev/bus/usb/003/047 test 27,   48.541857 secs
-[106222.174459] usbtest 3-5.1:1.0: TEST 28: bulk read 31Mbytes
+[00:04:55.234,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:04:55.241,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:04:55.248,000] <err> usbd_ch9: Malformed setup packet
+[00:04:55.254,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:04:55.261,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:04:55.268,000] <err> usbd_ch9: Malformed setup packet
+[00:04:55.274,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:04:55.281,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:04:55.288,000] <err> usbd_ch9: Malformed setup packet
/dev/bus/usb/003/047 test 28,   38.903385 secs
-[106261.139330] usbtest 3-5.1:1.0: TEST 29: Clear toggle between bulk writes 1000 times
+[00:05:34.177,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:05:34.184,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:05:34.191,000] <err> usbd_ch9: Malformed setup packet
+[00:05:34.197,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:05:34.204,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:05:34.211,000] <err> usbd_ch9: Malformed setup packet
+[00:05:34.217,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:05:34.224,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:05:34.231,000] <err> usbd_ch9: Malformed setup packet
+[00:05:34.238,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:05:34.244,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:05:34.251,000] <err> usbd_ch9: Malformed setup packet
-[106261.159504] usbtest 3-5.1:1.0: ep 01 couldn't clear halt, -32
-[106261.159525] usbtest 3-5.1:1.0: toggle sync failed, iterations left 999
/dev/bus/usb/003/047 test 29 --> 32 (error 32)

nucleo_u5a5zj_q (otghs, high-speed)

./testusb: /dev/bus/usb/003/049 may see only control tests
high speed	/dev/bus/usb/003/049	0
-[106557.036683] usbtest 3-5.1:1.0: TEST 0:  NOP
/dev/bus/usb/003/049 test 0,    0.000004 secs
-[106557.037422] usbtest 3-5.1:1.0: TEST 1:  write 1024 bytes 1000 times
/dev/bus/usb/003/049 test 1,    0.238185 secs
-[106557.276530] usbtest 3-5.1:1.0: TEST 2:  read 1024 bytes 1000 times
/dev/bus/usb/003/049 test 2,    0.132896 secs
-[106557.410360] usbtest 3-5.1:1.0: TEST 3:  write/512 0..1024 bytes 1000 times
/dev/bus/usb/003/049 test 3,    0.125034 secs
-[106557.536218] usbtest 3-5.1:1.0: TEST 4:  read/512 0..1024 bytes 1000 times
/dev/bus/usb/003/049 test 4,    0.068923 secs
-[106557.605983] usbtest 3-5.1:1.0: TEST 5:  write 1000 sglists 32 entries of 1024 bytes
/dev/bus/usb/003/049 test 5,    6.256995 secs
-[106563.863993] usbtest 3-5.1:1.0: TEST 6:  read 1000 sglists 32 entries of 1024 bytes
/dev/bus/usb/003/049 test 6,    4.687823 secs
-[106568.552696] usbtest 3-5.1:1.0: TEST 7:  write/512 1000 sglists 32 entries 0..1024 bytes
/dev/bus/usb/003/049 test 7,    3.287116 secs
-[106571.840769] usbtest 3-5.1:1.0: TEST 8:  read/512 1000 sglists 32 entries 0..1024 bytes
/dev/bus/usb/003/049 test 8,    2.571896 secs
-[106574.413692] usbtest 3-5.1:1.0: TEST 9:  ch9 (subset) control tests, 1000 times
/dev/bus/usb/003/049 test 9,    0.845690 secs
-[106575.260287] usbtest 3-5.1:1.0: TEST 10:  queue 32 control calls, 1000 times
/dev/bus/usb/003/049 test 10,    4.030215 secs
-[106579.291483] usbtest 3-5.1:1.0: TEST 11:  unlink 1000 reads of 1024
-[106579.538683] usbtest 3-5.1:1.0: unlink retry             <---- this is repeated many times
/dev/bus/usb/003/049 test 11,    4.139378 secs
-[106583.431782] usbtest 3-5.1:1.0: TEST 12:  unlink 1000 writes of 1024
-[106584.540797] usbtest 3-5.1:1.0: unlink retry
-[106584.710800] usbtest 3-5.1:1.0: unlink retry
-[106584.862800] usbtest 3-5.1:1.0: unlink retry
-[106585.002797] usbtest 3-5.1:1.0: unlink retry
-[106585.066797] usbtest 3-5.1:1.0: unlink retry
-[106585.146800] usbtest 3-5.1:1.0: unlink retry
-[106585.210797] usbtest 3-5.1:1.0: unlink retry
-[106585.310797] usbtest 3-5.1:1.0: unlink retry
-[106585.426797] usbtest 3-5.1:1.0: unlink retry
-[106586.090800] usbtest 3-5.1:1.0: unlink retry
-[106586.098736] usbtest 3-5.1:1.0: unlink retry
-[106586.630826] usbtest 3-5.1:1.0: unlink retry
-[106587.226807] usbtest 3-5.1:1.0: unlink retry
-[106587.392827] usbtest 3-5.1:1.0: unlink retry          
/dev/bus/usb/003/049 test 12,    4.043143 secs
-[106587.475927] usbtest 3-5.1:1.0: TEST 13:  set/clear 1000 halts
-[106597.957008] usb 3-5.1: verify_not_halted failed, iterations left 0, status -110 (not 0)
-[106597.957017] usbtest 3-5.1:1.0: halts failed, iterations left 998
/dev/bus/usb/003/049 test 13 --> 22 (error 22)
-[106597.957911] usbtest 3-5.1:1.0: TEST 14:  1000 ep0out, 1..1024 vary 512
-[106603.077090] usbtest 3-5.1:1.0: ctrl_out write failed, code -110, count 0
/dev/bus/usb/003/049 test 14 --> 110 (error 110)
-[106608.197783] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/049 test 15 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/049 test 16 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/049 test 17 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/049 test 18 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/049 test 19 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/049 test 20 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/049 test 21 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/049 test 22 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/049 test 23 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/049 test 24 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/049 test 25 --> 110 (error 110)
-[xxxxxx.xxxxxx] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/049 test 26 --> 110 (error 110)
-[106664.578903] usbtest 3-5.1:1.0: TEST 27: bulk write 31Mbytes
+[00:02:00.808,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:02:00.815,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:02:00.822,000] <err> usbd_ch9: Malformed setup packet
+[00:02:00.828,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:02:00.835,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:02:00.842,000] <err> usbd_ch9: Malformed setup packet
+[00:02:00.848,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:02:00.855,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:02:00.862,000] <err> usbd_ch9: Malformed setup packet
/dev/bus/usb/003/049 test 27,    6.083958 secs
-[106670.724010] usbtest 3-5.1:1.0: TEST 28: bulk read 31Mbytes
+[00:02:06.953,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:02:06.960,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:02:06.967,000] <err> usbd_ch9: Malformed setup packet
+[00:02:06.973,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:02:06.980,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:02:06.987,000] <err> usbd_ch9: Malformed setup packet
+[00:02:06.993,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:02:07.000,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:02:07.007,000] <err> usbd_ch9: Malformed setup packet
/dev/bus/usb/003/049 test 28,    4.313595 secs
-[106675.098714] usbtest 3-5.1:1.0: TEST 29: Clear toggle between bulk writes 1000 times
-[106675.118806] usbtest 3-5.1:1.0: ep 01 couldn't clear halt, -32
-[106675.118815] usbtest 3-5.1:1.0: toggle sync failed, iterations left 999
+[00:02:11.328,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:02:11.334,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:02:11.342,000] <err> usbd_ch9: Malformed setup packet
+[00:02:11.348,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:02:11.355,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:02:11.362,000] <err> usbd_ch9: Malformed setup packet
+[00:02:11.368,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:02:11.375,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:02:11.382,000] <err> usbd_ch9: Malformed setup packet
+[00:02:11.388,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:02:11.395,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:02:11.402,000] <err> usbd_ch9: Malformed setup packet
/dev/bus/usb/003/049 test 29 --> 32 (error 32)

nucleo_u5a5zj_q (otghs, full-speed over HS PHY via maximum-speed = "full-speed")

full speed	/dev/bus/usb/003/050	0
-[107121.478380] usbtest 3-5.1:1.0: TEST 0:  NOP
/dev/bus/usb/003/050 test 0,    0.000004 secs
-[107121.479227] usbtest 3-5.1:1.0: TEST 1:  write 1024 bytes 1000 times
/dev/bus/usb/003/050 test 1,    1.628300 secs
-[107123.108468] usbtest 3-5.1:1.0: TEST 2:  read 1024 bytes 1000 times
/dev/bus/usb/003/050 test 2,    1.299370 secs
-[107124.408859] usbtest 3-5.1:1.0: TEST 3:  write/512 0..1024 bytes 1000 times
/dev/bus/usb/003/050 test 3,    0.848321 secs
-[107125.258233] usbtest 3-5.1:1.0: TEST 4:  read/512 0..1024 bytes 1000 times
/dev/bus/usb/003/050 test 4,    0.742226 secs
-[107126.001494] usbtest 3-5.1:1.0: TEST 5:  write 1000 sglists 32 entries of 1024 bytes
/dev/bus/usb/003/050 test 5,   48.762896 secs
-[107174.766059] usbtest 3-5.1:1.0: TEST 6:  read 1000 sglists 32 entries of 1024 bytes
/dev/bus/usb/003/050 test 6,   38.868245 secs
-[107213.635512] usbtest 3-5.1:1.0: TEST 7:  write/512 1000 sglists 32 entries 0..1024 bytes
/dev/bus/usb/003/050 test 7,   25.298610 secs
-[107238.935127] usbtest 3-5.1:1.0: TEST 8:  read/512 1000 sglists 32 entries 0..1024 bytes
/dev/bus/usb/003/050 test 8,   20.182209 secs
-[107259.118604] usbtest 3-5.1:1.0: TEST 9:  ch9 (subset) control tests, 1000 times
/dev/bus/usb/003/050 test 9,    1.643715 secs
-[107260.763254] usbtest 3-5.1:1.0: TEST 10:  queue 32 control calls, 1000 times
/dev/bus/usb/003/050 test 10,    6.108007 secs
-[107266.872201] usbtest 3-5.1:1.0: TEST 11:  unlink 1000 reads of 1024
/dev/bus/usb/003/050 test 11,    7.999943 secs
-[107274.873131] usbtest 3-5.1:1.0: TEST 12:  unlink 1000 writes of 1024
-[107278.026179] usbtest 3-5.1:1.0: unlink retry           <---- this is repeated many times
/dev/bus/usb/003/050 test 12,    7.925118 secs
-[107282.799448] usbtest 3-5.1:1.0: TEST 13:  set/clear 1000 halts
/dev/bus/usb/003/050 test 13,    7.011495 secs
-[107289.811968] usbtest 3-5.1:1.0: TEST 14:  1000 ep0out, 1..1024 vary 512
-[107295.306505] usbtest 3-5.1:1.0: ctrl_out write failed, code -110, count 0
/dev/bus/usb/003/050 test 14 --> 110 (error 110)
-[107300.427210] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/050 test 15 --> 110 (error 110)
-[107305.547325] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/050 test 16 --> 110 (error 110)
-[107310.668246] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/050 test 17 --> 110 (error 110)
-[107315.787120] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/050 test 18 --> 110 (error 110)
-[107320.907481] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/050 test 19 --> 110 (error 110)
-[107326.027210] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/050 test 20 --> 110 (error 110)
-[107331.147132] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/050 test 21 --> 110 (error 110)
-[107336.267537] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/050 test 22 --> 110 (error 110)
-[107341.387322] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/050 test 23 --> 110 (error 110)
-[107346.507400] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/050 test 24 --> 110 (error 110)
-[107351.627589] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/050 test 25 --> 110 (error 110)
-[107356.748704] usbtest 3-5.1:1.0: set altsetting to 0 failed, -110
/dev/bus/usb/003/050 test 26 --> 110 (error 110)
-[107356.809756] usbtest 3-5.1:1.0: TEST 27: bulk write 31Mbytes
+[00:04:11.467,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:04:11.474,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:04:11.481,000] <err> usbd_ch9: Malformed setup packet
+[00:04:11.487,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:04:11.494,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:04:11.501,000] <err> usbd_ch9: Malformed setup packet
+[00:04:11.507,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:04:11.514,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:04:11.521,000] <err> usbd_ch9: Malformed setup packet
/dev/bus/usb/003/050 test 27,   48.364380 secs
-[107405.235710] usbtest 3-5.1:1.0: TEST 28: bulk read 31Mbytes
+[00:04:59.892,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:04:59.899,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:04:59.906,000] <err> usbd_ch9: Malformed setup packet
+[00:04:59.912,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:04:59.919,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:04:59.926,000] <err> usbd_ch9: Malformed setup packet
+[00:04:59.933,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:04:59.939,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:04:59.946,000] <err> usbd_ch9: Malformed setup packet
/dev/bus/usb/003/050 test 28,   38.719017 secs
-[107444.016135] usbtest 3-5.1:1.0: TEST 29: Clear toggle between bulk writes 1000 times
-[107444.036286] usbtest 3-5.1:1.0: ep 01 couldn't clear halt, -32
-[107444.036296] usbtest 3-5.1:1.0: toggle sync failed, iterations left 999
+[00:05:38.672,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:05:38.679,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:05:38.686,000] <err> usbd_ch9: Malformed setup packet
+[00:05:38.693,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:05:38.699,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:05:38.706,000] <err> usbd_ch9: Malformed setup packet
+[00:05:38.713,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:05:38.720,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:05:38.727,000] <err> usbd_ch9: Malformed setup packet
+[00:05:38.733,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+[00:05:38.740,000] <err> usbd_ch9: Buffer for data|status is missing
+[00:05:38.747,000] <err> usbd_ch9: Malformed setup packet
/dev/bus/usb/003/050 test 29 --> 32 (error 32)

NOTE: to get testusb working, the following temporary patch must be applied on top of the UDC driver

diff --git a/drivers/usb/udc/udc_stm32.c b/drivers/usb/udc/udc_stm32.c
index 9840ac28406..f8ca49bb56f 100644
--- a/drivers/usb/udc/udc_stm32.c
+++ b/drivers/usb/udc/udc_stm32.c
@@ -1065,15 +1065,15 @@ static const struct udc_api udc_stm32_api = {
 
 #if defined(USB) || defined(USB_DRD_FS)
 #define EP0_MPS 64U
-#define EP_MPS 64U
+#define EP_MPS 512U
 #define USB_BTABLE_SIZE  (8 * USB_NUM_BIDIR_ENDPOINTS)
 #define USB_RAM_SIZE   DT_INST_PROP(0, ram_size)
 #else /* USB_OTG_FS */
 #define EP0_MPS USB_OTG_MAX_EP0_SIZE
 #if DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otghs)
-#define EP_MPS USB_OTG_HS_MAX_PACKET_SIZE
+#define EP_MPS 512 /* USB_OTG_HS_MAX_PACKET_SIZE */
 #elif DT_HAS_COMPAT_STATUS_OKAY(st_stm32_otgfs) || DT_HAS_COMPAT_STATUS_OKAY(st_stm32_usb)
-#define EP_MPS USB_OTG_FS_MAX_PACKET_SIZE
+#define EP_MPS 512 /* USB_OTG_FS_MAX_PACKET_SIZE */
 #endif
 #define USB_RAM_SIZE   DT_INST_PROP(0, ram_size)
 #define USB_BTABLE_SIZE 0

@mathieuchopstm
Copy link
Contributor Author

cc @bearsh

@mathieuchopstm mathieuchopstm force-pushed the stm32_usb_phy_speed_cleanup branch from e04d03d to 684e722 Compare September 16, 2025 14:46
Comment on lines 123 to 127
* For HS-capable instances, this may be one of:
* - PCD_SPEED_HIGH: High-Speed mode
* - PCD_SPEED_HIGH_IN_FULL: Full-Speed mode on HS instance
*
* PCD_SPEED_FULL is returned for instances that are not HS-capable.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the record, the HAL never specifies if PCD_SPEED_HIGH_IN_FULL corresponds to "OTG_HS in FS Mode" or "OTG_HS connected to HS PHY in FS Mode".

In practice, the HAL doesn't care about this value if embedded FS PHY is selected; PCD_SPEED_HIGH_IN_FULL is fine even if the HAL really expected PCD_SPEED_FULL (as a matter of fact, the only thing we need to get right is PCD_SPEED_HIGH - any other value will select FS mode...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Verified by running testusb on Nucleo-F207ZG (OTG_HS, embedded FS PHY)

@bearsh
Copy link
Contributor

bearsh commented Sep 17, 2025

I hope I'll be able to test it later this week on my U5 based hardware...

@mathieuchopstm
Copy link
Contributor Author

With cherry-picked 68b57ea from #94001, I seem to get similar results as @nandojve : all testusb tests pass in FS mode, and all but test 13 pass in HS mode.

@mathieuchopstm mathieuchopstm force-pushed the stm32_usb_phy_speed_cleanup branch from 684e722 to 1a14623 Compare September 18, 2025 09:16
@mathieuchopstm
Copy link
Contributor Author

Rebased after merge of #95857

@henrikbrixandersen
Copy link
Member

Architecture WG, 2025-09-25:

  • Consensus is to move forward with this PR first, @mathieuchopstm to address the review comments from @jfischer-no; @jfischer-no to respond to already posted questions from @mathieuchopstm
  • After this PR is merged, the next step will be to have another look at drivers: usb: stm32: Fix USB FS/HS linux compliance tests #94001 from @nandojve
  • Other PRs provided by the community attempting to solve the same issue(s) in the STM32 UDC shim driver shall be closed by ST with a thank you note and a reference to the PR(s) superseding them.
  • Future plans for the STM32 UDC shim driver (reworking the compatibles to better describe the underlying controller, splitting the PHY code into a dedicated USB PHY driver, moving towards using the native DWC2 driver where possible) should be kept separate to this PR, ideally in a "meta" issue detailing/discussing these plans.

@mathieuchopstm mathieuchopstm force-pushed the stm32_usb_phy_speed_cleanup branch from 1a14623 to bfa0aef Compare September 26, 2025 15:51
@mathieuchopstm
Copy link
Contributor Author

v2: should address all comments from @jfischer-no + things discussed in ArchWG.

@mathieuchopstm
Copy link
Contributor Author

mathieuchopstm commented Sep 26, 2025

FTR this has been tested to build, run and pass MSC tests on:

  • stm32h747i_disco//m7 (HS/FS) +
  • stm32n6570_dk (HS/FS) +
  • nucleo_u5a5zj_q (HS/FS)
  • b_u585i_iot02a (FS only)
  • nucleo_l552ze_q (FS only)

+ indicates tests did not fully complete due to an error LBA 0 is out of range which I assume to be unrelated to the USB driver itself but haven't investigated yet.

This has also been tested to build, run and (partially) pass the testusb suite on:

stm32h747i_disco
high speed	/dev/bus/usb/003/028	0
running all tests except:
  24
/dev/bus/usb/003/028 test 0,    0.000008 secs
/dev/bus/usb/003/028 test 1,    0.118663 secs
/dev/bus/usb/003/028 test 2,    0.081996 secs
/dev/bus/usb/003/028 test 3,    0.070672 secs
/dev/bus/usb/003/028 test 4,    0.047532 secs
/dev/bus/usb/003/028 test 5,    3.849461 secs
/dev/bus/usb/003/028 test 6,    2.737042 secs
/dev/bus/usb/003/028 test 7,    2.068681 secs
/dev/bus/usb/003/028 test 8,    1.500390 secs
/dev/bus/usb/003/028 test 9,    0.636761 secs
/dev/bus/usb/003/028 test 10,    2.735815 secs
/dev/bus/usb/003/028 test 11,    4.285267 secs
/dev/bus/usb/003/028 test 12,    4.355027 secs
/dev/bus/usb/003/028 test 13 --> 22 (error 22)
/dev/bus/usb/003/028 test 14,    0.434693 secs
/dev/bus/usb/003/028 test 17,    0.128242 secs
/dev/bus/usb/003/028 test 18,    0.083545 secs
/dev/bus/usb/003/028 test 19,    0.122223 secs
/dev/bus/usb/003/028 test 20,    0.082363 secs
/dev/bus/usb/003/028 test 21,    0.418546 secs
/dev/bus/usb/003/028 test 27,    3.569032 secs
/dev/bus/usb/003/028 test 28,    2.557972 secs
/dev/bus/usb/003/028 test 29,    0.336320 secs

./testusb: /dev/bus/usb/003/027 may see only control tests
full speed	/dev/bus/usb/003/027	0
running all tests except:
  24
/dev/bus/usb/003/027 test 0,    0.000005 secs
/dev/bus/usb/003/027 test 1,    1.562587 secs
/dev/bus/usb/003/027 test 2,    1.265737 secs
/dev/bus/usb/003/027 test 3,    0.842807 secs
/dev/bus/usb/003/027 test 4,    0.689045 secs
/dev/bus/usb/003/027 test 5,   45.863472 secs
/dev/bus/usb/003/027 test 6,   38.310417 secs
/dev/bus/usb/003/027 test 7,   23.770352 secs
/dev/bus/usb/003/027 test 8,   19.876130 secs
/dev/bus/usb/003/027 test 9,    1.538184 secs
/dev/bus/usb/003/027 test 10,    5.167046 secs
/dev/bus/usb/003/027 test 11,    8.090251 secs
/dev/bus/usb/003/027 test 12,    8.274762 secs
/dev/bus/usb/003/027 test 13,    6.565813 secs
/dev/bus/usb/003/027 test 14,    1.242223 secs
/dev/bus/usb/003/027 test 17,    1.644698 secs
/dev/bus/usb/003/027 test 18,    1.304723 secs
/dev/bus/usb/003/027 test 19,    1.618403 secs
/dev/bus/usb/003/027 test 20,    1.365166 secs
/dev/bus/usb/003/027 test 21,    1.236297 secs
/dev/bus/usb/003/027 test 27,   45.502138 secs
/dev/bus/usb/003/027 test 28,   38.189191 secs
/dev/bus/usb/003/027 test 29,    0.739592 secs
stm32n6570_dk
./testusb: /dev/bus/usb/003/044 may see only control tests
high speed	/dev/bus/usb/003/044	0
running all tests except:
  24
/dev/bus/usb/003/044 test 0,    0.000004 secs
/dev/bus/usb/003/044 test 1,    0.288885 secs
/dev/bus/usb/003/044 test 2,    0.170454 secs
/dev/bus/usb/003/044 test 3,    0.147766 secs
/dev/bus/usb/003/044 test 4,    0.098457 secs
/dev/bus/usb/003/044 test 5,    7.781491 secs
/dev/bus/usb/003/044 test 6,    5.414733 secs
/dev/bus/usb/003/044 test 7,    4.149743 secs
/dev/bus/usb/003/044 test 8,    2.908910 secs
/dev/bus/usb/003/044 test 9,    0.869777 secs
/dev/bus/usb/003/044 test 10,    4.476179 secs
/dev/bus/usb/003/044 test 11,    4.125238 secs
/dev/bus/usb/003/044 test 12,    4.131219 secs
/dev/bus/usb/003/044 test 13 --> 22 (error 22)
/dev/bus/usb/003/044 test 14,    0.886935 secs
/dev/bus/usb/003/044 test 17,    0.251304 secs
/dev/bus/usb/003/044 test 18,    0.168591 secs
/dev/bus/usb/003/044 test 19,    0.276668 secs
/dev/bus/usb/003/044 test 20,    0.170385 secs
/dev/bus/usb/003/044 test 21,    0.873445 secs
/dev/bus/usb/003/044 test 27,    7.903154 secs
/dev/bus/usb/003/044 test 28,    5.334246 secs
/dev/bus/usb/003/044 test 29,    0.635692 secs


./testusb: /dev/bus/usb/003/042 may see only control tests
full speed	/dev/bus/usb/003/042	0
running all tests except:
  24
/dev/bus/usb/003/042 test 0,    0.000004 secs
/dev/bus/usb/003/042 test 1,    1.660040 secs
/dev/bus/usb/003/042 test 2,    1.361478 secs
/dev/bus/usb/003/042 test 3,    0.831831 secs
/dev/bus/usb/003/042 test 4,    0.697227 secs
/dev/bus/usb/003/042 test 5,   48.950212 secs
/dev/bus/usb/003/042 test 6,   40.211155 secs
/dev/bus/usb/003/042 test 7,   25.363523 secs
/dev/bus/usb/003/042 test 8,   20.816712 secs
/dev/bus/usb/003/042 test 9,    1.938787 secs
/dev/bus/usb/003/042 test 10,    6.563445 secs
/dev/bus/usb/003/042 test 11,    8.397765 secs
/dev/bus/usb/003/042 test 12,    8.396765 secs
/dev/bus/usb/003/042 test 13,    7.058669 secs
/dev/bus/usb/003/042 test 14,    1.386168 secs
/dev/bus/usb/003/042 test 17,    1.675276 secs
/dev/bus/usb/003/042 test 18,    1.297302 secs
/dev/bus/usb/003/042 test 19,    1.701822 secs
/dev/bus/usb/003/042 test 20,    1.338223 secs
/dev/bus/usb/003/042 test 21,    1.436209 secs
/dev/bus/usb/003/042 test 27,   48.615147 secs
/dev/bus/usb/003/042 test 28,   40.204041 secs
/dev/bus/usb/003/042 test 29,    0.820423 secs

nucleo_u5a5zj_q
./testusb: /dev/bus/usb/003/033 may see only control tests
high speed	/dev/bus/usb/003/033	0
running all tests except:
  24
/dev/bus/usb/003/033 test 0,    0.000005 secs
/dev/bus/usb/003/033 test 1,    0.188043 secs
/dev/bus/usb/003/033 test 2,    0.127600 secs
/dev/bus/usb/003/033 test 3,    0.114125 secs
/dev/bus/usb/003/033 test 4,    0.078711 secs
/dev/bus/usb/003/033 test 5,    5.912304 secs
/dev/bus/usb/003/033 test 6,    4.147882 secs
/dev/bus/usb/003/033 test 7,    3.082826 secs
/dev/bus/usb/003/033 test 8,    2.161264 secs
/dev/bus/usb/003/033 test 9,    0.761411 secs
/dev/bus/usb/003/033 test 10,    3.508571 secs
/dev/bus/usb/003/033 test 11,    4.230931 secs
/dev/bus/usb/003/033 test 12,    4.253299 secs
/dev/bus/usb/003/033 test 13 --> 22 (error 22)
/dev/bus/usb/003/033 test 14,    0.598586 secs
/dev/bus/usb/003/033 test 17,    0.204991 secs
/dev/bus/usb/003/033 test 18,    0.127607 secs
/dev/bus/usb/003/033 test 19,    0.231749 secs
/dev/bus/usb/003/033 test 20,    0.125884 secs
/dev/bus/usb/003/033 test 21,    0.665370 secs
/dev/bus/usb/003/033 test 27,    5.707861 secs
/dev/bus/usb/003/033 test 28,    4.015755 secs
/dev/bus/usb/003/033 test 29,    0.478752 secs

./testusb: /dev/bus/usb/003/021 may see only control tests
full speed	/dev/bus/usb/003/021	0
running all tests except:
  24
/dev/bus/usb/003/021 test 0,    0.000005 secs
/dev/bus/usb/003/021 test 1,    1.603459 secs
/dev/bus/usb/003/021 test 2,    1.267721 secs
/dev/bus/usb/003/021 test 3,    0.875368 secs
/dev/bus/usb/003/021 test 4,    0.717084 secs
/dev/bus/usb/003/021 test 5,   48.571332 secs
/dev/bus/usb/003/021 test 6,   38.685712 secs
/dev/bus/usb/003/021 test 7,   24.885490 secs
/dev/bus/usb/003/021 test 8,   20.070574 secs
/dev/bus/usb/003/021 test 9,    1.742666 secs
/dev/bus/usb/003/021 test 10,    6.019046 secs
/dev/bus/usb/003/021 test 11,    8.028247 secs
/dev/bus/usb/003/021 test 12,    8.067252 secs
/dev/bus/usb/003/021 test 13,    6.879071 secs
/dev/bus/usb/003/021 test 14,    1.290593 secs
/dev/bus/usb/003/021 test 17,    1.650732 secs
/dev/bus/usb/003/021 test 18,    1.337212 secs
/dev/bus/usb/003/021 test 19,    1.645422 secs
/dev/bus/usb/003/021 test 20,    1.373775 secs
/dev/bus/usb/003/021 test 21,    1.329887 secs
/dev/bus/usb/003/021 test 27,   48.050241 secs
/dev/bus/usb/003/021 test 28,   38.454549 secs
/dev/bus/usb/003/021 test 29,    0.749845 secs
b_u5858i_iot02a./testusb: /dev/bus/usb/003/025 may see only control tests full speed /dev/bus/usb/003/025 0 running all tests except: 24 /dev/bus/usb/003/025 test 0, 0.000006 secs /dev/bus/usb/003/025 test 1, 1.674028 secs /dev/bus/usb/003/025 test 2, 1.393876 secs /dev/bus/usb/003/025 test 3, 0.893320 secs /dev/bus/usb/003/025 test 4, 0.773165 secs /dev/bus/usb/003/025 test 5, 48.628452 secs /dev/bus/usb/003/025 test 6, 38.770267 secs /dev/bus/usb/003/025 test 7, 24.762007 secs /dev/bus/usb/003/025 test 8, 20.048083 secs /dev/bus/usb/003/025 test 9, 1.881399 secs /dev/bus/usb/003/025 test 10, 6.359480 secs /dev/bus/usb/003/025 test 11, 8.557596 secs /dev/bus/usb/003/025 test 12, 8.380726 secs /dev/bus/usb/003/025 test 13, 6.976686 secs /dev/bus/usb/003/025 test 14, 1.245724 secs /dev/bus/usb/003/025 test 17, 1.570320 secs /dev/bus/usb/003/025 test 18, 1.315128 secs /dev/bus/usb/003/025 test 19, 1.594762 secs /dev/bus/usb/003/025 test 20, 1.304126 secs /dev/bus/usb/003/025 test 21, 1.321407 secs /dev/bus/usb/003/025 test 27, 48.134062 secs /dev/bus/usb/003/025 test 28, 38.436136 secs /dev/bus/usb/003/025 test 29, 0.755952 secs
nucleo_l552ze_q
./testusb: /dev/bus/usb/003/021 may see only control tests
full speed	/dev/bus/usb/003/021	0
running all tests except:
  24
/dev/bus/usb/003/021 test 0,    0.000005 secs
/dev/bus/usb/003/021 test 1,    1.603459 secs
/dev/bus/usb/003/021 test 2,    1.267721 secs
/dev/bus/usb/003/021 test 3,    0.875368 secs
/dev/bus/usb/003/021 test 4,    0.717084 secs
/dev/bus/usb/003/021 test 5,   48.571332 secs
/dev/bus/usb/003/021 test 6,   38.685712 secs
/dev/bus/usb/003/021 test 7,   24.885490 secs
/dev/bus/usb/003/021 test 8,   20.070574 secs
/dev/bus/usb/003/021 test 9,    1.742666 secs
/dev/bus/usb/003/021 test 10,    6.019046 secs
/dev/bus/usb/003/021 test 11,    8.028247 secs
/dev/bus/usb/003/021 test 12,    8.067252 secs
/dev/bus/usb/003/021 test 13,    6.879071 secs
/dev/bus/usb/003/021 test 14,    1.290593 secs
/dev/bus/usb/003/021 test 17,    1.650732 secs
/dev/bus/usb/003/021 test 18,    1.337212 secs
/dev/bus/usb/003/021 test 19,    1.645422 secs
/dev/bus/usb/003/021 test 20,    1.373775 secs
/dev/bus/usb/003/021 test 21,    1.329887 secs
/dev/bus/usb/003/021 test 27,   48.050241 secs
/dev/bus/usb/003/021 test 28,   38.454549 secs
/dev/bus/usb/003/021 test 29,    0.749845 secs

Note that test 24 unlink URBs from a bulk-OUT queue was excluded from campaign as a workaround because it sometimes hangs in kernel mode; this makes the testusb task unkillable and kinda breaks the USB subsystem (among other issues) and effectively mandates that the test PC be rebooted - as such, it should be treated as failing.

Also note that the hack mentioned previously (increase max EP size by modifying driver) was applied here as well.

…UPPORT

The driver supports high-speed capable controllers. Select
the appropriate Kconfig options to ensure that the stack does
not optimize away high-speed support.

Signed-off-by: Martin Gysel <me@bearsh.org>
@mathieuchopstm mathieuchopstm force-pushed the stm32_usb_phy_speed_cleanup branch from bfa0aef to 9eb058a Compare September 29, 2025 07:55
@mathieuchopstm
Copy link
Contributor Author

@jfischer-no PTAL whenever possible 🙂

}
#elif defined(CONFIG_SOC_SERIES_STM32U5X)
/* Sequence to enable the power of the OTG HS on a stm32U5 serie : Enable VDDUSB */
__ASSERT_NO_MSG(LL_AHB3_GRP1_IsEnabledClock(LL_AHB3_GRP1_PERIPH_PWR));
Copy link
Contributor

Choose a reason for hiding this comment

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

It does not look correct. LL_AHB3_GRP1_IsEnabledClock(LL_AHB3_GRP1_PERIPH_PWR)); has no effect when asserts are disabled, is that intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a functional change from existing code but in practice, the existing code is useless as the PWR clock is enabled unconditionally by SoC layer:

/* Enable PWR */
LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_PWR);

I just kept the assert to help debugging in case for some reason the clock is disabled in another place, but from testing the old !pwr_clk code path was never reached. I'm fine with keeping the old code but (imo) it just makes the function unnecessarily larger.

(FTR, we are also planning to rework how global clocks such as these are handled)

*/
#if !defined(PCD_SPEED_HIGH)
#define PCD_SPEED_HIGH (PCD_SPEED_FULL + 1)
#define PCD_SPEED_HIGH_IN_FULL (PCD_SPEED_HIGH + 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe an unexpected value would be better, like UINT32_MAX? (non blocking)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't really matter, it's impossible for these values to be assigned if the if !defined() check succeeded. (they are only needed for e.g. the check in udc_stm32_device_speed to compile)

k_sleep(K_MSEC(100));
}
#elif defined(CONFIG_SOC_SERIES_STM32U5X)
/* Sequence to enable the power of the OTG HS on a stm32U5 serie : Enable VDDUSB */
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe an inline comment to explain that PWR is always enable at SoC eraly inits?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I plan to clean this up when reworking this whole topic globally, so not necessary IMO.

Rework the STM32 USB UDC driver to use HAL PCD macros for speed selection,
as should have always been done since that is the library used by the shim
driver. Also dummy definitions to ensure cross-series compatibility
without many #if blocks in the driver.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Rework how the driver performs PWR configuration and initializes HS PHYs.

Originally, the initialization logic was split in half without any real
logic. There were also attempts to share some logic but this resulted in
code that was difficult to understand.

Initialize PWR and PHY in well separated steps, and use explicit series
and PHY type checks in each part to ensure the logic is easy to understand.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
…ation

Rework how the STM32 UDC driver determines the PHY used by a given instance
and the speed at which the instance is able to and allowed to operate.

The PHY determination now uses the 'phys' property instead of looking at
whether nodes with a specific compatible were enabled. Similarly, the speed
determination takes into account the 'maximum-speed' property, along with
the selected PHY's and the instance's capabilities.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: USB Universal Serial Bus platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants