Hi,
I'm trying to send some data from my usb device to the host by a virtual com port CDC. Is it the only solution to write these data to the endpoint(in) in the SOF ISR? Sending data to the usb device from the host is working.
#if USB_SOF_EVENT void USB_SOF_Event (void) { USB_WriteEP( USB_ENDPOINT_IN(2), &TestData[0], 64 ); // send 64 bytes data }
Has someone a small example (using two CDCs)? With the code above, the SOF interrupts occurs only 4x times after enabling the com port on the host. After that no further SOF will be generated. Using Readfile() returns true - but there's definitely no traffic on the usb bus.
best regards Jan
Usually, your firmware doesn't need to be aware of the double buffer on the endpoint.
However, if you want to use the double buffer more effectively, fill the EP buffer using USB_WriteEP() until FE bit (Select Endpoint command) raises, at the start of block transfer. In this way, two packets are put to the double buffer, sequentially. Third and later packets are filled in the Endpoint Callback, USB_EndPointN(), usbuser.c, one packet by one.
512 bytes transfer on CDC bulk IN EP should be terminated by ZLP (Zero-Length Packet). CDC bulk IN transfer requires ZLP termination when the transfer size is just the multiple of wMaxPacketSize of the EP (64 bytes). On the PC side, host controller doesn't pass received data to the class driver, until it sees short packet (including ZLP).
If your PC application uses SerialPort class - DataReceived event, or MSCOMM - OnComm event, you may see significant delay on the PC class driver (usbser.sys). An extra ZLP after each transfer may speed up the process on the class driver.
Tsuneo