STM32F745 USB endpoint EPENA stuck CDC/MSC
I have an intermittent issue with a USB composite device on STM32F745 where an endpoint is failing to send data back to the PC and then the PC resets the connection.
I've applied the interrupt disabling from
https://community.st.com/s/question/0D50X00009XkhXw/usb-cdc-device-receive-fails-on-transmit and that did improve things somewhat, however it isn't fixed.
My code is derived from ST's example codes.
In normal operation, the MSC is queried by the PC periodically with a "Test Unit Ready" command. The CDC is in full flow at about 150 useful data packets per second.
After a random time period (between a few minutes and multiple hours) the USB send function is unable to add data to the IN FIFO.
This line fails:
if ( ((USBx_INEP(ep)->DIEPCTL & USB_OTG_DIEPCTL_EPENA) == 0)
&& ((USBx_INEP(ep)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) >= len32b) ) {
because EPENA is set.
My code was previously just ignoring this and hoping that the host asked for the data again. However, when this fails on the Test Unit Ready command, the host resets the USB connection after about 30 seconds which disrupts my CDC data.
Also, once that has happened, it continues to reset every 30 seconds because the MSC never works again - the endpoint seems broken. A device reset in the debugger clears it up.
I tried adding code for a short wait and retry (no effect) and also tried to set EPDIS and then check for the DIEPINT_EPDISD but that doesn't appear to ever get set.
In another post ( https://community.st.com/s/question/0D50X00009Xki6G/stm32f429-usb-bug-on-updating-diepctl-register-while-epena-set ) a customer has code that clears the EPENA bit directly - can this work? The datasheet only mentions the core clearing the bit.
What are the causes for the EPENA bit getting "stuck" on? Why isn't setting the DIEPCTL_EPDIS bit clearing it?
Any other ideas?
James
