USB_DeviceCancel makes endpoint unusable

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

USB_DeviceCancel makes endpoint unusable

1,026 Views
tomasvanek
Contributor III

I'm creating  an K22 application working as an USB FS device with vendor class bulk in. I use KSDK 2.2 with usb 1.6.3

The application needs to cancel running long transfer on bulk in endpoint. If it calls USB_DeviceCancel, pending transfer is canceled. Unfortunately the endpoint gets into not usable state, following calls of USB_DeviceSendRequest do not send any data to host until USB is reset and configured again.

It looks like khci device driver loose sync between endpointState bdtOdd and USB peripheral state after USB_DeviceCancel.

Can anybody point me to an working example of canceling USB transfer?

0 Kudos
3 Replies

712 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Tomas Vanek

Could you share the code that you are using, I would like to see in more details your process. In my understanding of your case, your endpoint is stall by the host; when device doesn't respond to the host, host stall the endpoint and the host have to Unstall these endpoints. This is why you have to make a USB reset to can recover your endpoint. You as device cannot cancel a transfer without inform the host, device has not that kind of control in the transfer, host need to send a request of cancelling the transfer.

I recommend you to check the example code of usb_device_msc, more specific, usb_device_msc.c file, it uses in different times USB_DeviceCancel function, it could help you to understand the usage of this API.

Hope this helps.
Have a great day,
Jorge Alcala

0 Kudos

711 Views
tomasvanek
Contributor III

Thanks for reply, Jorge.

Originally there was no endpoint stall control in my app. The MCU/USB device acts like a data acquisition frontend for a libusb host app. The host app sends a vendor class request on control ep to start data acquisition and when it decides it has enough data, it sends other vendor class request to stop the data flow on bulk in ep. In this moment device side needs to cancel pending transfer and explicitly calls USB_DeviceCancel(). It breaks future transfers on bulk in.

I redesigned the host side to send REQUEST_SET_FEATURE FEATURE_ENDPOINT_HALT for bulk in ep to stop the data and unstall the ep afterwards. The device side does need to call USB_DeviceCancel() and everything works as expected.

0 Kudos

711 Views
michal_vodicka
Contributor I

I have the same problem as Tomas but unfortunately can't resolve it the same way. I'm trying to solve a situation when host app is communicating with the device and crashes when device is sending response via bulk-in endpoint. The bulk-in endpoint has pending transfer which crashed host app didn't read. The app is restarted and it sends "start sesssion" command via control endpoint to the device. The device needs to reset the session and in turn cancels pending transfer from previous session using USB_DeviceCancel(). Transfer is cancelled and buffer correctly returned to caller but since then the endpoint doesn't work. USB_DeviceSendRequest() returns kStatus_USB_Success but the transfer is never completed and no data are read by host.

I guess USB_DeviceCancel() breaks the endpoint state somewhat. Can it be fixed? What can I do to recover endpoint state in the meantime? I'd really prefer to NOT make USB reset. I tried to unstall endpoint and it doesn't help.

0 Kudos