cancel
Showing results for 
Search instead for 
Did you mean: 

Strange USB behavior - getting 3 bytes of data I didn't send.

BStic.2
Senior

So, when I first connect to my USB implementation and send the first 3 bytes to the command/control interface I get 3 zeros. It is not what I sent and interestingly enough I do get the bytes I sent the first time on the next 3 bytes. I have no idea what is causing this behavior and I have verified with a USB sniffer that the zeros are not being sent over the wire. This is very consistent and I have no idea whats happening. Any ideas?

1 ACCEPTED SOLUTION

Accepted Solutions

Never mind, I think I found my problem. I was not waiting for EP0_RxReady. I assumed the data was transferred when I called USBD_CtlPrepareRx.

View solution in original post

6 REPLIES 6

What is "my USB implementation", how do you "first connect" to it, and where do you get the 3 zeros?

JW

I created my own USB descriptor as ST does not provide an HCI/Wireless interface for USB as I want to pass HCI commands from my tool to the BLE stack. This is using the Nucleo-64 (STM32WB55) demo board. I started with the HID project and updated the descriptor and endpoints to be HCI. My tool expects a BLE - USB dongle and it successfully enumerates and connects using libUSB. It first sends 3 bytes on the control endpoint (0x03 0x0C 0x00) - which is an HCI reset command. I get an interrupt and my USBD_HCI_Setup function fires informing me I received 3 bytes on that interface. The bytes are 0x00 0x00 0x00 - not what I am expecting. If I send another 3 bytes I get the first 3 bytes I sent (0x03 0x0C 0x00). Things always seem to be shifted by 3 bytes. Any ideas?

Never mind, I think I found my problem. I was not waiting for EP0_RxReady. I assumed the data was transferred when I called USBD_CtlPrepareRx.

Just a wild guess:

> USBD_HCI_Setup function fires informing me

>I received 3 bytes on that interface.

What if this function for before data are copied into some intermediate buffer, or before they arrive at all?

JW

Sorry, I posted a response just as you sent another reply. My unfamiliarity with USB led me to assume that data was being transferred in the Setup function, but apparently its not available until the EP0_RxReady interrupt fires. I will shift things around to bring in the data in that ISR, rather than the Setup function. Thanks for being a sounding board for this.

Thanks for coming back with the solution.

Please select your post as Best so that thread is marked as solved.

JW