cancel
Showing results for 
Search instead for 
Did you mean: 

Can't read data from device to PC on USB interface 1

DrWidget
Associate II

I've setup a custom USB device with multiple interfaces on custom hardware using a ULPI. The USB code is derived from the code generated by CubeMX.

  • On interface 0 I have endpoint 1 in and out
  • On interface 1 I have endpoint 2 in and out
  • On interface 2 I have endpoint 3 in and out

From the PC, I wrote a very simple program that can send and receive a single packet. I can send and receive data  on interface 0 (ep1). I can also send data from PC to device to on interface 1 (ep2), but I cannot receive data. Interface 2 has not yet been implemented. Transmit and receive buffers are set as follows in usbd_conf.c:

 

HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_HS, 0x200);

HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 0, 0x20);

HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 1, 0x80);

HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 2, 0x80);

HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_HS, 3, 0x80);

 

In my custom device class I open all three pairs of EP's exactly the same way. I'm missing something though. My presumption is that everything will go through the interrupt handler (OTG_HS_IRQHandler). If I toggle a DIO there, it fires off multiple times during enumeration, then every time I read from interface 0. When I read from interface 1, the interrupt doesn't fire. Is there an interrupt configuration that I'm missing a setup on for interface 1? I've been at this for a couple days so any suggestions would be welcome! Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
DrWidget
Associate II

So it turned out the solution was the HAL_PCDEx_SetTxFiFo for the additional endpoints.  In the course of debugging this issue, another aspect of my code broke the USB. Even when you select multiple interfaces in CubeMX, the code gen still creates a set of hard-coded sizes for the FIFO sizes, so this must be set manually.

The other note is that you must take care that the sum of your transmit and receive buffers must not exceed the USB buffer limits on your given device. In my case with highspeed USB I have 4 kB to work with. You need to take the numbers used for the FIFO size x4 to determine the number of bytes used so in my original example I would be using 3712 bytes.  There is also a note in the datasheet that 3 bytes per FIFO must also be set aside, but still haven't confirmed whether that is just 3 bytes, or 12 bytes from the total.

View solution in original post

2 REPLIES 2
DrWidget
Associate II

UPDATE:

One further bit of information, when I do a read from the PC while using a USB packet sniffer, I can see an IN packet go out on the wire, but the device is responding with a NAK packet.  Something appears to be actively rejecting the request... but not sure where that would be.

DrWidget
Associate II

So it turned out the solution was the HAL_PCDEx_SetTxFiFo for the additional endpoints.  In the course of debugging this issue, another aspect of my code broke the USB. Even when you select multiple interfaces in CubeMX, the code gen still creates a set of hard-coded sizes for the FIFO sizes, so this must be set manually.

The other note is that you must take care that the sum of your transmit and receive buffers must not exceed the USB buffer limits on your given device. In my case with highspeed USB I have 4 kB to work with. You need to take the numbers used for the FIFO size x4 to determine the number of bytes used so in my original example I would be using 3712 bytes.  There is also a note in the datasheet that 3 bytes per FIFO must also be set aside, but still haven't confirmed whether that is just 3 bytes, or 12 bytes from the total.