Skip to content

drivers: usb: udc: stm32: handle endpoint halt properly#95857

Merged
fabiobaltieri merged 1 commit intozephyrproject-rtos:mainfrom
mathieuchopstm:stm32_usb_fix_ep_halt
Sep 18, 2025
Merged

drivers: usb: udc: stm32: handle endpoint halt properly#95857
fabiobaltieri merged 1 commit intozephyrproject-rtos:mainfrom
mathieuchopstm:stm32_usb_fix_ep_halt

Conversation

@mathieuchopstm
Copy link
Copy Markdown
Contributor

@mathieuchopstm mathieuchopstm commented Sep 11, 2025

Cleaned up version of #93796. Handle endpoints in halted state properly by marking endpoints as halted when appropriate, and inhibiting transfers involving halted endpoints.

Partial fix for #91483

etienne-lms
etienne-lms previously approved these changes Sep 11, 2025
Copy link
Copy Markdown
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

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

LGTM

@mathieuchopstm
Copy link
Copy Markdown
Contributor Author

FTR, USB3CV MSC Tests pass without errors on b_u585_iot02a:
image

Build command: west build -b b_u585i_iot02a samples/subsys/usb/mass/ -p sample.usbd.mass_ram_none -DCONFIG_UDC_BUF_POOL_SIZE=8192 - for some reason, the default of UDC_BUF_POOL_SIZE=1024 leads to an OOM (due to something attempting a 4K allocation?!) at some point and the two first tests of the suite failing.

erwango
erwango previously approved these changes Sep 12, 2025
@tmon-nordic
Copy link
Copy Markdown
Contributor

tmon-nordic commented Sep 15, 2025

for some reason, the default of UDC_BUF_POOL_SIZE=1024 leads to an OOM (due to something attempting a 4K allocation?!) at some point and the two first tests of the suite failing

This is the GetDescriptor() for String descriptor index 0 (wLANGID array) that is called with wLength=4096 during the USB3CV MSC Tests.

I think USB device stack should allow passing such requests, given that the maximum real length will fit in memory. However, it is not clear to how to implement the limiting (and it is out of scope here).

jfischer-no
jfischer-no previously approved these changes Sep 15, 2025
Copy link
Copy Markdown
Contributor

@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.

@nandojve Can you please check it?

@jfischer-no jfischer-no requested review from nandojve and removed request for GeorgeCGV September 15, 2025 09:53
@nandojve
Copy link
Copy Markdown
Member

Hi @mathieuchopstm , @jfischer-no ,

The outcome is that it recovers when an error happens in the test 13 and not fail in the 21 (HS mode) .
It seems better but still fail in HS with error 22.

What I can not understand is why it works in FS but fails in HS.

HS

[25391.408533] usbtest 3-11:1.0: TEST 0:  NOP
[25391.418021] usbtest 3-11:1.0: TEST 1:  write 1024 bytes 1000 times
[25393.379971] usbtest 3-11:1.0: TEST 2:  read 1024 bytes 1000 times
[25393.488958] usbtest 3-11:1.0: TEST 3:  write/512 0..1024 bytes 1000 times
[25393.585957] usbtest 3-11:1.0: TEST 4:  read/512 0..1024 bytes 1000 times
[25393.646955] usbtest 3-11:1.0: TEST 5:  write 1000 sglists 32 entries of 1024 bytes
[25399.906939] usbtest 3-11:1.0: TEST 6:  read 1000 sglists 32 entries of 1024 bytes
[25403.242935] usbtest 3-11:1.0: TEST 7:  write/512 1000 sglists 32 entries 0..1024 bytes
[25406.677886] usbtest 3-11:1.0: TEST 8:  read/512 1000 sglists 32 entries 0..1024 bytes
[25408.350849] usbtest 3-11:1.0: TEST 9:  ch9 (subset) control tests, 1000 times
[25434.360962] usbtest 3-11:1.0: TEST 10:  queue 32 control calls, 1000 times
[25558.584941] usbtest 3-11:1.0: TEST 11:  unlink 1000 reads of 1024
[25558.646310] usbtest 3-11:1.0: unlink retry
[25560.758300] usbtest 3-11:1.0: unlink retry
[25561.046287] usbtest 3-11:1.0: unlink retry
[25561.154584] usbtest 3-11:1.0: TEST 12:  unlink 1000 writes of 1024
[25564.022303] usbtest 3-11:1.0: unlink retry
[25565.034293] usbtest 3-11:1.0: unlink retry
[25565.097558] usbtest 3-11:1.0: TEST 13:  set/clear 1000 halts
[25575.207661] usb 3-11: verify_not_halted failed, iterations left 0, status -110 (not 0)
[25575.207674] usbtest 3-11:1.0: halts failed, iterations left 998
[25575.217805] usbtest 3-11:1.0: TEST 14:  1000 ep0out, 1..1024 vary 512
[25591.259390] usbtest 3-11:1.0: TEST 17:  write odd addr 1024 bytes 1000 times core map
[25593.223332] usbtest 3-11:1.0: TEST 18:  read odd addr 1024 bytes 1000 times core map
[25593.332318] usbtest 3-11:1.0: TEST 19:  write odd addr 1024 bytes 1000 times premapped
[25595.319318] usbtest 3-11:1.0: TEST 20:  read odd addr 1024 bytes 1000 times premapped
[25595.428301] usbtest 3-11:1.0: TEST 21:  1000 ep0out odd addr, 1..1024 vary 512
[25611.469177] usbtest 3-11:1.0: TEST 24:  unlink from 1000 queues of 32 1024-byte writes
[25669.326747] usbtest 3-11:1.0: TEST 27: bulk write 31Mbytes
[25675.347653] usbtest 3-11:1.0: TEST 28: bulk read 31Mbytes
[25678.556628] usbtest 3-11:1.0: TEST 29: Clear toggle between bulk writes 1000 times
sudo ./testusb -v 512 -D /dev/bus/usb/003/009
./testusb: /dev/bus/usb/003/009 may see only control tests
high speed	/dev/bus/usb/003/009	0
/dev/bus/usb/003/009 test 0,    0.000008 secs
/dev/bus/usb/003/009 test 1,    1.953210 secs
/dev/bus/usb/003/009 test 2,    0.099948 secs
/dev/bus/usb/003/009 test 3,    0.087758 secs
/dev/bus/usb/003/009 test 4,    0.051697 secs
/dev/bus/usb/003/009 test 5,    6.250692 secs
/dev/bus/usb/003/009 test 6,    3.327175 secs
/dev/bus/usb/003/009 test 7,    3.426127 secs
/dev/bus/usb/003/009 test 8,    1.663377 secs
/dev/bus/usb/003/009 test 9,   25.999829 secs
/dev/bus/usb/003/009 test 10,  124.213991 secs
/dev/bus/usb/003/009 test 11,    2.560604 secs
/dev/bus/usb/003/009 test 12,    3.934088 secs
/dev/bus/usb/003/009 test 13 --> 22 (error 22)
/dev/bus/usb/003/009 test 14,   16.014048 secs
/dev/bus/usb/003/009 test 17,    1.955071 secs
/dev/bus/usb/003/009 test 18,    0.099947 secs
/dev/bus/usb/003/009 test 19,    1.977624 secs
/dev/bus/usb/003/009 test 20,    0.099943 secs
/dev/bus/usb/003/009 test 21,   16.013920 secs
/dev/bus/usb/003/009 test 24,   57.830787 secs
/dev/bus/usb/003/009 test 27,    6.011503 secs
/dev/bus/usb/003/009 test 28,    3.199973 secs
/dev/bus/usb/003/009 test 29,    7.216008 secs

FS

[25847.158784] usbtest 3-11:1.0: TEST 0:  NOP
[25847.166774] usbtest 3-11:1.0: TEST 1:  write 1024 bytes 1000 times
[25848.629749] usbtest 3-11:1.0: TEST 2:  read 1024 bytes 1000 times
[25849.814745] usbtest 3-11:1.0: TEST 3:  write/512 0..1024 bytes 1000 times
[25850.395740] usbtest 3-11:1.0: TEST 4:  read/512 0..1024 bytes 1000 times
[25851.022722] usbtest 3-11:1.0: TEST 5:  write 1000 sglists 32 entries of 1024 bytes
[25897.441392] usbtest 3-11:1.0: TEST 6:  read 1000 sglists 32 entries of 1024 bytes
[25943.846987] usbtest 3-11:1.0: TEST 7:  write/512 1000 sglists 32 entries 0..1024 bytes
[25967.864787] usbtest 3-11:1.0: TEST 8:  read/512 1000 sglists 32 entries 0..1024 bytes
[25991.868582] usbtest 3-11:1.0: TEST 9:  ch9 (subset) control tests, 1000 times
[26017.877412] usbtest 3-11:1.0: TEST 10:  queue 32 control calls, 1000 times
[26139.885409] usbtest 3-11:1.0: TEST 11:  unlink 1000 reads of 1024
[26140.078637] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26140.298644] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26140.714637] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26140.762631] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26141.234641] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26141.698642] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26142.058651] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26142.066633] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26142.310641] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26142.714641] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26143.194644] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26143.410641] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26143.674632] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26144.838640] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26145.022640] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26145.442636] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26146.034644] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26146.234629] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26147.058641] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26147.066643] xhci_hcd 0000:66:00.0: WARN Set TR Deq Ptr cmd failed due to incorrect slot or ep state.
[26147.609318] usbtest 3-11:1.0: TEST 12:  unlink 1000 writes of 1024
[26152.559258] usbtest 3-11:1.0: TEST 13:  set/clear 1000 halts
[26189.567951] usbtest 3-11:1.0: TEST 14:  1000 ep0out, 1..1024 vary 512
[26205.605859] usbtest 3-11:1.0: TEST 17:  write odd addr 1024 bytes 1000 times core map
[26207.068799] usbtest 3-11:1.0: TEST 18:  read odd addr 1024 bytes 1000 times core map
[26208.238789] usbtest 3-11:1.0: TEST 19:  write odd addr 1024 bytes 1000 times premapped
[26209.701786] usbtest 3-11:1.0: TEST 20:  read odd addr 1024 bytes 1000 times premapped
[26210.854767] usbtest 3-11:1.0: TEST 21:  1000 ep0out odd addr, 1..1024 vary 512
[26226.892656] usbtest 3-11:1.0: TEST 24:  unlink from 1000 queues of 32 1024-byte writes
[26284.917166] usbtest 3-11:1.0: TEST 27: bulk write 31Mbytes
[26331.470819] usbtest 3-11:1.0: TEST 28: bulk read 31Mbytes
[26378.023399] usbtest 3-11:1.0: TEST 29: Clear toggle between bulk writes 1000 times
sudo ./testusb -v 512 -D /dev/bus/usb/003/010
./testusb: /dev/bus/usb/003/010 may see only control tests
full speed	/dev/bus/usb/003/010	0
/dev/bus/usb/003/010 test 0,    0.000005 secs
/dev/bus/usb/003/010 test 1,    1.455129 secs
/dev/bus/usb/003/010 test 2,    1.176437 secs
/dev/bus/usb/003/010 test 3,    0.572887 secs
/dev/bus/usb/003/010 test 4,    0.619079 secs
/dev/bus/usb/003/010 test 5,   46.410173 secs
/dev/bus/usb/003/010 test 6,   46.397136 secs
/dev/bus/usb/003/010 test 7,   24.009021 secs
/dev/bus/usb/003/010 test 8,   23.995364 secs
/dev/bus/usb/003/010 test 9,   25.999830 secs
/dev/bus/usb/003/010 test 10,  121.999307 secs
/dev/bus/usb/003/010 test 11,    7.715213 secs
/dev/bus/usb/003/010 test 12,    4.941787 secs
/dev/bus/usb/003/010 test 13,   37.000349 secs
/dev/bus/usb/003/010 test 14,   16.013910 secs
/dev/bus/usb/003/010 test 17,    1.455099 secs
/dev/bus/usb/003/010 test 18,    1.161309 secs
/dev/bus/usb/003/010 test 19,    1.455150 secs
/dev/bus/usb/003/010 test 20,    1.144550 secs
/dev/bus/usb/003/010 test 21,   16.013930 secs
/dev/bus/usb/003/010 test 24,   58.000656 secs
/dev/bus/usb/003/010 test 27,   46.544831 secs
/dev/bus/usb/003/010 test 28,   46.544737 secs
/dev/bus/usb/003/010 test 29,    6.000156 secs

Setup

#94001
* b2ded5eaa18 - (HEAD -> stm/fix_usb_fs_hs_linux_compliance_tests_more_fixes_fixes) drivers: usb: stm32: Fix data out on control ep (16 minutes ago) <BUDKE Gerson Fernando>
* 9c0650abe48 - drivers: usb: stm32: Enable High Speed interface (16 minutes ago) <BUDKE Gerson Fernando>

#95857 (this PR)
* 5816552070b - drivers: usb: udc: stm32: handle endpoint halt properly (17 minutes ago) <Mathieu CHOPLAIN>

#89866
* a5f5c8f213e - drivers: udc_stm32: rework speed selection logic (18 minutes ago) <Martin Gysel>
* c7897853130 - drivers: udc_stm32: select Kconfig option UDC_DRIVER_HAS_HIGH_SPEED_SUPPORT (18 minutes ago) <Martin Gysel>

(main)
* 5bef4a9d626 - drivers: usb: udc: skeleton: handle special case of set_halt() for EP0 (3 hours ago) <Mathieu CHOPLAIN>

@mathieuchopstm
Copy link
Copy Markdown
Contributor Author

mathieuchopstm commented Sep 15, 2025

🤦 pushed to wrong branch... sorry. (note to self: git branch -c does not switch branch)

@nandojve I have only tested on b_u585_iot02a for now (in FS only - no HS on this hw), and indeed testusb does not complete flawlessly on my side either. As a matter of fact, running it twice in a row leads to a double-free (and thus kernel panic - I have CONFIG_ASSERT=y), so clearly the driver is not fully fixed yet.

testusb results

(my dmesg log overflowed so error messages before test 12 may have been missed)

- dmesg logs
+ Zephyr logs

./testusb: /dev/bus/usb/003/017 may see only control tests
full speed	/dev/bus/usb/003/017	0
/dev/bus/usb/003/017 test 0,    0.000005 secs
/dev/bus/usb/003/017 test 1,    1.657647 secs
/dev/bus/usb/003/017 test 2,    1.300067 secs
/dev/bus/usb/003/017 test 3,    0.935144 secs
/dev/bus/usb/003/017 test 4,    0.787059 secs
/dev/bus/usb/003/017 test 5,   48.896797 secs
/dev/bus/usb/003/017 test 6,   39.109974 secs
/dev/bus/usb/003/017 test 7,   25.250139 secs
/dev/bus/usb/003/017 test 8,   20.278973 secs
/dev/bus/usb/003/017 test 9,    1.938179 secs
/dev/bus/usb/003/017 test 10,    6.831558 secs
/dev/bus/usb/003/017 test 11,    8.277230 secs
- unlink retry [many times]
/dev/bus/usb/003/017 test 12,    8.077155 secs
- unlink retry [once]
/dev/bus/usb/003/017 test 13,    7.142753 secs
/dev/bus/usb/003/017 test 14 --> 110 (error 110)
- ctrl_out write failed, code -110, count 0
/dev/bus/usb/003/017 test 15 --> 110 (error 110)
- set altsetting to 0 failed, -110
/dev/bus/usb/003/017 test 16 --> 110 (error 110)
- set altsetting to 0 failed, -110
/dev/bus/usb/003/017 test 17 --> 110 (error 110)
- set altsetting to 0 failed, -110
/dev/bus/usb/003/017 test 18 --> 110 (error 110)
- set altsetting to 0 failed, -110
/dev/bus/usb/003/017 test 19 --> 110 (error 110)
- set altsetting to 0 failed, -110
/dev/bus/usb/003/017 test 20 --> 110 (error 110)
- set altsetting to 0 failed, -110
/dev/bus/usb/003/017 test 21 --> 110 (error 110)
- set altsetting to 0 failed, -110
/dev/bus/usb/003/017 test 22 --> 110 (error 110)
- set altsetting to 0 failed, -110
/dev/bus/usb/003/017 test 23 --> 110 (error 110)
- set altsetting to 0 failed, -110
/dev/bus/usb/003/017 test 24 --> 110 (error 110)
- set altsetting to 0 failed, -110
/dev/bus/usb/003/017 test 25 --> 110 (error 110)
- set altsetting to 0 failed, -110
/dev/bus/usb/003/017 test 26 --> 110 (error 110)
- set altsetting to 0 failed, -110
/dev/bus/usb/003/017 test 27,   48.742084 secs
+ [00:04:26.258,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+ [00:04:26.265,000] <err> usbd_ch9: Buffer for data|status is missing
+ [00:04:26.272,000] <err> usbd_ch9: Malformed setup packet
+ [00:04:26.278,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+ [00:04:26.285,000] <err> usbd_ch9: Buffer for data|status is missing
+ [00:04:26.292,000] <err> usbd_ch9: Malformed setup packet
+ [00:04:26.299,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+ [00:04:26.305,000] <err> usbd_ch9: Buffer for data|status is missing
+ [00:04:26.312,000] <err> usbd_ch9: Malformed setup packet
/dev/bus/usb/003/017 test 28,   38.911322 secs
+ [00:05:14.318,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+ [00:05:14.325,000] <err> usbd_ch9: Buffer for data|status is missing
+ [00:05:14.332,000] <err> usbd_ch9: Malformed setup packet
+ [00:05:14.338,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+ [00:05:14.345,000] <err> usbd_ch9: Buffer for data|status is missing
+ [00:05:14.352,000] <err> usbd_ch9: Malformed setup packet
+ [00:05:14.359,000] <err> udc: Failed to allocate net_buf 0, ep 0x80
+ [00:05:14.365,000] <err> usbd_ch9: Buffer for data|status is missing
+ [00:05:14.372,000] <err> usbd_ch9: Malformed setup packet
/dev/bus/usb/003/017 test 29 --> 32 (error 32)
- ep 01 couldn't clear halt, -32
- toggle sync failed, iterations left 999

On second run, during test 13 or 14:

ASSERTION FAIL [buf->ref] @ WEST_TOPDIR/zephyr/lib/net_buf/buf.c:450
        buf 0x20007b28 double free
[00:08:29.709,000] <err> os: r0/a1:  0x00000004  r1/a2:  0x000001c2  r2/a3:  0x00000000
[00:08:29.717,000] <err> os: r3/a4:  0x00000004 r12/ip:  0x00000000 r14/lr:  0x08002abb
[00:08:29.726,000] <err> os:  xpsr:  0x01000000
[00:08:29.731,000] <err> os: Faulting instruction address (r15/pc): 0x0800bb42
[00:08:29.739,000] <err> os: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0
[00:08:29.747,000] <err> os: Current thread: 0x20000478 (unknown)
[00:08:29.754,000] <err> os: Halting system

We'd like to integrate (more or less) small fixes one by one rather than try to fix everything at once, so hopefully this is fine.

@mathieuchopstm
Copy link
Copy Markdown
Contributor Author

FTR, there seems to be an issue on the HAL side as it declares USB_OTG_FS_MAX_PACKET_SIZE = 64 when I find no reason for such restriction in HW.

If you try to run the testusb sample on b_u585i_iot02a (or anything with st,stm32-otgfs-usb) on your side, you'll have to hack the driver by replacing:

#define EP_MPS USB_OTG_FS_MAX_PACKET_SIZE

with #define EP_MPS 512

@nandojve
Copy link
Copy Markdown
Member

Hi @mathieuchopstm ,

#define EP_MPS 512

As per USB 2.0 specs the max endpoint is 1024 HS and 1023 FS in the Isochronous mode. If the interface is a high speed and high bandwidth endpoint it can specifies whether it requires two or three transactions per microframe which can led to use 3072 bytes max or 2|3 times 1024.

This means that the EP max size depends on speed, ep type and max allocated ep interfaces, last one is about how many memory it is available - so good compromise. This rules should be added later in the USB Next I think because it is in USB spec.

Besides, this patch still don't pass HS /dev/bus/usb/003/009 test 13 --> 22 (error 22).

@erwango
Copy link
Copy Markdown
Member

erwango commented Sep 17, 2025

@nandojve Even if some test failures remain, do you think this should block the PR ?
IMO, this goes into the right direction and we need to start at some point.

Edit: For correctness, maybe we should remove Fixes https://github.com/zephyrproject-rtos/zephyr/issues/91483 and update #91483 status once it is merged.

@nandojve
Copy link
Copy Markdown
Member

Hi @erwango ,

@nandojve Even if some test failures remain, do you think this should block the PR ?
IMO, this goes into the right direction and we need to start at some point.

I have the same impression. The PR already improved the situation and I don't want to block it. This is why I report the details about EP size and latest test status.

Edit: For correctness, maybe we should remove Fixes #91483 and update #91483 status once it is merged

Yes, I think it makes sense to remove the linked issue till a complete fix is made.

@mathieuchopstm
Copy link
Copy Markdown
Contributor Author

Hi @mathieuchopstm ,

#define EP_MPS 512

As per USB 2.0 specs the max endpoint is 1024 HS and 1023 FS in the Isochronous mode. If the interface is a high speed and high bandwidth endpoint it can specifies whether it requires two or three transactions per microframe which can led to use 3072 bytes max or 2|3 times 1024.

Definitely, this is not a correct fix - but it allows the testusb to function somewhat correctly. This is why I said:

you'll have to hack the driver by replacing:

A more appropriate fix is upcoming (although I did not take the multi-transactions into account... I'll make sure to pay attention to it)


For the issue, I seem unable to unlink it from this PR. I'll re-open it manually if merging closes it.

erwango
erwango previously approved these changes Sep 17, 2025
nandojve
nandojve previously approved these changes Sep 17, 2025
Comment on lines +849 to +850
* Hardware will clear halt bit of EP0 automatically such
* that software never sees control endpoints as halted.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think that is not quite correct, and I suggest removing it. For example, if the controller is DWC2, then the controller writes received setup packet to the FIFO regardless of NAK, STALL, or available FIFO size. It is up to the driver, then, to handle it properly, see dwc2_handle_evt_setup() in udc_dwc2.c.

Copy link
Copy Markdown
Member

@erwango erwango Sep 17, 2025

Choose a reason for hiding this comment

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

@jfischer-no Don't hesitate to NACK if you really mean to. Otherwise I take it as a non blocking comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was referring to the following sentence from STM32 RefMan (for SNPS DWC2 IP):
image


The ST USB IP has a similar behavior:
image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Simplified the comment to merely state we ignore control EP, without getting into details. PTAL.

Comment on lines +928 to +931
/*
* Endpoint is currently halted and should not
* transmit any data until host clears halt bit.
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment is redundant, similar is stated in the logging message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed.

*/
LOG_DBG("skip enqueue for halted ep 0x%02x", epcfg->addr);
} else {
/* Endpoint not halted: we can transmit */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Redundant comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed.

Copy link
Copy Markdown
Contributor

@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.

I think it is better to fix #95857 (comment)

Handle endpoints in halted state properly by marking endpoints as halted
when appropriate, and inhibiting transfers involving halted endpoints.

Co-authored-by: IBEN EL HADJ MESSAOUD Marwa <marwa.ibenelhadjmessaoud-ext@st.com>
Signed-off-by: Mathieu CHOPLAIN <mathieu.choplain-ext@st.com>
@nandojve nandojve requested a review from erwango September 17, 2025 13:43
@sonarqubecloud
Copy link
Copy Markdown

@fabiobaltieri fabiobaltieri merged commit 3ae98de into zephyrproject-rtos:main Sep 18, 2025
26 checks passed
@mathieuchopstm mathieuchopstm deleted the stm32_usb_fix_ep_halt branch September 18, 2025 09:12
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.

8 participants