USB data0/1 toggling problem with STM32 Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
kayvenm
Posts: 2
Joined: Sun Mar 25, 2018 9:13 pm

USB data0/1 toggling problem with STM32  Topic is solved

Postby kayvenm » Mon Mar 26, 2018 1:29 am

Hey there, I'm experiencing an issue with USB using an stm32f103c8 with regards to data0/1 toggling.
When a SetConfiguration operation is issued, data toggling should be reset to data0 (as stipulated in 9.1.1.5 section of the USB specs 2.0), which is currently not the case, at least for the stm32 USB driver.
The fix itself seems rather easy but the problem I'm having is that ChibiOS is checking the new configuration value against the actual one and ignoring it if there is no change.
However, on the host side the data toggling is reset regardless, which leaves the device and the host out of sync
Simply removing the check in the default_handler function so the operation is propagated to the event handler which should call the init endpoint function works but has the side effect of resetting the configuration too, which may have other unforeseen consequences...

Here's the fix specifically for the stm32, ChibiOS v 16.1.0 :
--- ChibiOS/os/hal/ports/STM32/LLD/USBv1/usb_lld.c.org 2017-10-19 18:20:43.000000000 -0400
+++ ChibiOS/os/hal/ports/STM32/LLD/USBv1/usb_lld.c 2018-03-25 15:33:00.858205631 -0400
@@ -645,14 +645,6 @@
#endif
}

+ if (STM32_USB->EPR[ep] & EPR_DTOG_RX) {
+ epr |= EPR_DTOG_RX;
+ }
+
+ if (STM32_USB->EPR[ep] & EPR_DTOG_TX) {
+ epr |= EPR_DTOG_TX;
+ }
+
/* EPxR register setup.*/
EPR_SET(ep, epr | ep);
EPR_TOGGLE(ep, epr);

For the ChibiOS part, I'm not sure which way this should be handled...

Thanks,

Kayven

User avatar
Giovanni
Site Admin
Posts: 11156
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 392 times
Been thanked: 323 times
Contact:

Re: USB data0/1 toggling problem with STM32

Postby Giovanni » Mon Mar 26, 2018 7:51 am

Hi,

Are you using isochronous endpoints?

Giovanni

kayvenm
Posts: 2
Joined: Sun Mar 25, 2018 9:13 pm

Re: USB data0/1 toggling problem with STM32

Postby kayvenm » Mon Mar 26, 2018 2:55 pm

Oops, that's a very important point that I forgot to mention. No, I'm using bulk endpoints.

User avatar
Giovanni
Site Admin
Posts: 11156
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 392 times
Been thanked: 323 times
Contact:

Re: USB data0/1 toggling problem with STM32

Postby Giovanni » Fri Apr 13, 2018 10:11 am

I am going to apply that patch during weekend, is there a way to test if everything works as expected?

Giovanni

User avatar
Giovanni
Site Admin
Posts: 11156
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 392 times
Been thanked: 323 times
Contact:

Re: USB data0/1 toggling problem with STM32

Postby Giovanni » Sun Apr 15, 2018 9:57 am

Hi,

I applied the patch and removed the check from hal_usb.c. There is an option to restore the old behavior in case of problems but I don't think that check was really required.

Feedback on this change would be appreciated, I will back-port it to 18.2 and 17.6 later.

There are two opened tickets about this: 938 and 939.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 4 guests