Project

General

Profile

Bug #4329

IN endpoint gets stuck during USB suspend

Added by laforge 2 months ago. Updated 2 months ago.

Status:
Resolved
Priority:
Urgent
Assignee:
Category:
-
Target version:
-
Start date:
12/15/2019
Due date:
% Done:

100%


Description

Despite all my efforts to fix #4251, I still coulf find situations where the number of alloccated buffers would grow. Even more so, after stopping the simtrace2-remsim-client program for some time and later re-starting it, the pending transfers from before would not get delivered.

It took me many hours of debugging. What appears to happen is the following sequence of events:
  • the firmware writes the first entry of the IN endpoint transmit queue to the USB device peripheral (UDP) of the SAM3S
  • the host is currently not scheduling any IN transfers as the libusb-using application is stopped and hence there are no URBs for that IN endpoint
  • the host application is restarted at some point (and obviously sends IN tokens again)
  • the pending transfer never completes, which in turn blocks all the further entries of the endpoint transmit queue.
I guess I finally uncovered the mystery: It is related to the USB suspend/resume procedure. Suspend / Resume handling is (Surprisingly!) implemented in the in-firmware Atmel USBD driver, but only in a weird way:
  • it actually deactivates the USB transceiver and the peripheral clock to the USB device
  • it doesn't call any pending callbacks for the ongoing transfers (not even calling them with state=error)
  • it doesn't block any further calls to the USB peripheral, such as USBD_Write() calls that will happily [think they] modify the registers of the USB peripheral

The main problem seems to center around the call to UDP_DisablePeripheralClock() from USBD_HAL_Suspend(). If I comment-out that call, IN transfers continue happily after the USB Resume.


Related issues

Related to SIMtrace 2 - Bug #4251: simtrace2 firmware can get OOM / talloc unable to allocate buffer for APDUResolved11/07/2019

Related to SIMtrace 2 - Bug #4335: Unexpected/malformed data from SIM applet causes simtrace2-sniff to stop until simtrace2 board is resetNew12/17/2019

History

#1 Updated by laforge 2 months ago

  • Related to Bug #4251: simtrace2 firmware can get OOM / talloc unable to allocate buffer for APDU added

#2 Updated by laforge 2 months ago

  • % Done changed from 30 to 80

#3 Updated by laforge 2 months ago

  • Status changed from In Progress to Resolved
  • % Done changed from 80 to 100

patch merged.

#4 Updated by laforge 2 months ago

  • Related to Bug #4335: Unexpected/malformed data from SIM applet causes simtrace2-sniff to stop until simtrace2 board is reset added

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 48.8 MB)