cancel
Showing results for 
Search instead for 
Did you mean: 

USB Device (MSC): how to wait for data ?

dzuikov
Associate II
Posted on March 06, 2012 at 05:20

I'm trying  to implement USB device that emulates mass storage on USB FS, however, the data source  is approx. 10 times slower than USB FS transmit rate.

I tried to wait in Mass Storage read callback for data, but it makes everything hang.

In USBD example there is a wait loop in a handler, but if I try to wait more than ~ 3 msec

it does not work.

The external host reads greedy, so it  necessary  to limit the read speed somehow. How to do it better?  

2 REPLIES 2
hpipon957
Associate III
Posted on March 07, 2012 at 01:25

Hi

If you don't prepare IN data the USB-controller will NAK the host and so there are no difficulties in that direction.

In the other direction the USB controller will also NAK the host once its Rx FIFO gets full (assuming STM32F4xx). It is also possible to set the NAK bit in the endpoint's control register so that the USB controller NAKs even if it has space in its input FIFO.

NAKing the host will control data flow speed.

Regards

Mark

dzuikov
Associate II
Posted on March 07, 2012 at 08:04

Thanks!

I use MSC class driver,  it seem there is no direct way to send NAK using MSC driver --- it calls read callback from the interrupt there is no possibility to set the NAK directly.

I've tried to hack scsi layer to use 

DCD_SetEPStatus(cdev, MSC_IN_EP, USB_OTG_EP_TX_NAK);  

when there is no data ready, but seems that it's does not solve the problem completely --- it sends NAK after the bad packet and it makes host to receive an invalid packet.

Is there any proper way to use MSC class driver or I have to implement my own one?