0
\$\begingroup\$

I am working with USB HID in stm32f072. On Get_Report Request I have to send data to Host PC through Control Transfer Endpoint. I am trying to do so. But it is sending always some wrong data. If I want to elaborate the problem, that is

 case HID_REQ_GET_REPORT:

  if(req->wValue==PID_POOL_BLOCK_REPORT){

    buf[0] = 0x07;
    buf[1] = 0xFF;
    buf[2] = 0xFF,
    buf[3] = 0x0A;
    buf[4] = 0x02;

    if(USBD_LL_FlushEP (pdev, 0x00)==USBD_OK){

      USBD_CtlSendData (pdev, 
                        buf,
                        5);

    }    
  }

But the data send through is actually "0xF6 0x3A 0x82 0x28 0x45". I have no clue what is happening inside. I have benn trying it with flushing the endpoint too. But it seems no working. What to do really? Any clue please. Thank you.

\$\endgroup\$
  • \$\begingroup\$ Is buf a local variable? \$\endgroup\$ – CL. Dec 13 '15 at 15:05
  • \$\begingroup\$ yes, local. But does it matter? What is your point? \$\endgroup\$ – istiaq2379 Dec 13 '15 at 16:13
1
\$\begingroup\$

USB works asynchronously. USBD_CtlSendData just saves a pointer to the buffer; the data gets actually read from memory and transmitted when the host asks for it.

So you have to ensure that the data is still available later. Use a static or global variable.

\$\endgroup\$
  • \$\begingroup\$ used global. But no change. The most disgusting stuff is, at first initialization it sends the right data. But at next request it is sending always garbage. With stm32 software package they didn't write anything on Get_Report request. Ridiculous. Any more thought? \$\endgroup\$ – istiaq2379 Dec 13 '15 at 17:43
  • \$\begingroup\$ Do you think the problem is may be with endpoints? Do I have to stall the Interrupt Endpoint, so that I can receive or send the data only through Control Endpoint? Is it possible case? \$\endgroup\$ – istiaq2379 Dec 13 '15 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.