AnsweredAssumed Answered

How to handle "slow" USB requests in STM32Cube library

Question asked by Germann.Daniel on Nov 15, 2016

I have a HID device implemented with a STM32F205.  I have I2C and SPI peripherals attached to the 205, and HID "Get Feature" reports to return values read from those peripherals.  Normally, I'd just fill up a report buffer in the Setup() handler with the values, but since Setup is called from interrupt context, it's a bad idea to do I2C and SPI reads from there.

In the old USB firmware library, I'd return "USB_NOT_READY" for those reports, and have a state machine called from my main loop do the I2C/SPI reads, fill in the report buffer and then send the report data like this:

      _SetEPRxStatus(ENDP0, SaveRState);
      _SetEPTxStatus(ENDP0, SaveTState);

The STM32Cube library works a bit differently.  My first attempt returned USBD_BUSY from Setup(), and then in my state machine I filled in the report buffer and tried to send it with USBD_CtlSendData:

    USBD_CtlSendData(pdev, hhid->Report_buf, hhid->ReportLength);

That didn't work.  I'm thinking that there's some state information inside the USB stack that doesn't allow that to work.

Has anyone else done this?  What's the trick to getting this to work using the STM32Cube USB library?

Thank you!