This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52840 USB Cancel IN Transfer

I am working on the Mbed-OS HAL implementation for the nRF52840 USB device.

I have it almost passing all the automated tests. One where it fails is when the Mbed test suite attempts to halt an endpoint.

Essentially the test works like this:

  1. OUT xfer - write a random payload to device endpoint
  2. IN xfer - read back payload
  3. Make sure data written and data read are the same
  4. ...continue to loop...
  5. OUT xfer - write a random payload to device endpoint
  6. HALT IN endpoint
  7. IN xfer - endpoint should reply STALL
  8. CLEAR HALT on IN endpoint
  9. OUT xfer - write a new random payload to device endpoint
  10. IN xfer - read back payload
  11. Make sure the new random payload and the data read are the same

The failure occurs because the Mbed stack immediately loads the payload received during the OUT stage into EasyDMA and begins the transfer for the corresponding IN endpoint. Then the endpoint is halted, it replies STALL as expected. But when the HALT is cleared, the hardware is still prepared to ACK the next IN transfer that begins on that endpoint. It will then respond with the old payload -- causing the test to fail.

This happens more often than not, but sometimes the test does pass.

I have attached a screenshot of the captured USB traffic during this failure.

Is there a way to clear the USB hardware readiness state for an IN endpoint after an EasyDMA transfer has been completed on it? I have tried disabling and reenabling the endpoint and the issue still occurs. It seems as though the USB hardware should allow this kind of operation...

Parents Reply
  • Ah! Mbed is currently using SDK14.2 and I only pulled in changes from 15.2 that were related to errata! I will go through the SDK15.2 driver and pull in other relevant changes... Mbed will eventually be transitioning to SDK15+ but it hasn't happened yet.

    I figured it would be some sort of undocumented register manipulation.

    Thank you masz and Einar! That should be exactly what I'm looking for. Hopefully it fixes this issue

Children
Related