USB CDC host receiving unsolicited data from a device

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

USB CDC host receiving unsolicited data from a device

918 Views
tarikaweimrin
Contributor III

I have 2 KL26Z micros talking to each other, one is the host and the other is a CDC device.  I am using the USB stack 4.1.1 I can use the serial_write and serial_read functionality from the host to send and receive data from the device when I know that the device is sending data.  How do I determine if the device has sent unexpected data that needs to be read and the amount of data sent by the device to read?  Is there a flag set somewhere or a callback that I haven't been able to find yet?


Any help would be appreciated.

Labels (1)
0 Kudos
6 Replies

748 Views
mjbcswitzerland
Specialist V

Hi

A USB device cannot send data without the host allowing it to, by sending an IN packet which it either responds to or sends a NAK back to.

The host defines the bandwidth available and so will normally be sending IN packets on bulk endpoints whenever there is nothing else to send - the device will therefore be able to return data almost all the time in such an arrangement and the host's DATA reception interrupt will inform of its arrival.

If your host is however not sending IN packets when it is not actually expecting to read data the device will not be able to send anything.

Regards

Mark

0 Kudos

748 Views
tarikaweimrin
Contributor III

Is that in addition to sending the SOF tokens continuously?

0 Kudos

748 Views
mjbcswitzerland
Specialist V

Hi

SOF tokens only define the framework (1ms for FS and 125us for HS) timing but don't allow the device to do anything. [Newer Kinetis parts with crystal-less USB (optionally) use this to re-synchronise the local 48MHz oscillator].

The host must then define the bandwidth allocation (interrupt, isochronous, bulk, depending on the types and number of devices connected) and send IN tokens whenever a device may respond with data.

Regards

Mark

0 Kudos

748 Views
tarikaweimrin
Contributor III

Is there any example code doing this?

0 Kudos

748 Views
mjbcswitzerland
Specialist V

Hi

I think that setting

TOKEN = ((IN_PID << 4) | ENDPOINT_in_question);

will cause the host to poll.

Regards

Mark

0 Kudos

748 Views
tarikaweimrin
Contributor III

Makes sense, I will try that. Thanks

0 Kudos