Skip to main content
Visitor II
May 21, 2022
Question

USB custom HID: unable to send data from controller to PC consecutively

  • May 21, 2022
  • 4 replies
  • 5079 views

I am using STM32L1 series and configured it as as custom HID device. I am able to receive data from PC and able to respond once using USBD_CUSTOM_HID_SendReport function. If i am trying to send again data to PC using the same function it is not working. It is going to either USB device status as busy or device state suspended.

I have used "09.7_USB HID device - custom device lab" document to configure the project. Please let me know how to figure out the issue.

    This topic has been closed for replies.

    4 replies

    Graduate II
    May 21, 2022
    Juan.2422Author
    Visitor II
    May 23, 2022

    @Piranha​ I was trying to understand the issue using STM library itself. Have you tried it using the same?

    Graduate II
    May 23, 2022

    After the experience with Ethernet and seeing the code that team writes everywhere, when I needed USB, I didn't waste my time on a broken bloatware written by incompetent "developers" and went strait to TinyUSB. Works as a charm!

    And ST's USB stack does everything in ISRs, which is a ridiculously dumb and limiting design.

    Juan.2422Author
    Visitor II
    May 24, 2022

    @Piranha​ Thank you for your suggestions. I will look into TinyUSB implementation.

    Juan.2422Author
    Visitor II
    May 24, 2022

    @Amel NASRI​ Could you help me with some information on issue with "unable to send data from controller to PC consecutively". I am using STM32L152RC with cubeMX version 6.3.0 and latest firmware version.

    Technical Moderator
    May 24, 2022

    Hi @Juan.2422​ ,

    In the package STM32CubeL1, there is already a ready to use CustomHID example. You find it in this path under the package: STM32CubeL1/Projects/STM32L152D-EVAL/Applications/USB_Device/CustomHID_Standalone.

    To build your own example with STM32CubeMX, you can refer to this video tutorial.

    Please note that latest CubeMX version is 6.5. Please try to align with this one.

    -Amel

    Juan.2422Author
    Visitor II
    May 24, 2022

    @Amel NASRI​ I have followed the same video tutorial. I could always receive data from Host PC & also response back to the host using USBD_CUSTOM_HID_SendReport function.

    But if micro controller device initiate USBD_CUSTOM_HID_SendReport it is failing.USB device status is either busy or device state suspended. Is there anything i am missing?

    I have also tried CubeMX version is 6.5 but no progress.

    Super User
    May 24, 2022

    >  I am unable to send data to host consecutively using tud_hid_report().I am calling tud_hid_report() function two times inside tud_hid_set_report_cb() callback method.

    You cannot send data to host before the host receives the previous data and requests you to send again.

    No "pushing" data to the host. Design your software based on this.

    Juan.2422Author
    Visitor II
    May 25, 2022

    @Pavel A.​ My final requirement is to send data to host periodically (data include sensor/GPIO status etc.). I have seen few tutorials which transmit data continuously in the same manner. So is this practically possible with custom HID? Am i missing something?

    Super User
    May 25, 2022

    @Juan.2422 Strictly speaking, it is NOT possible, because you can send anything ONLY when the host allows you. But the HID protocol has special means for this.

    You can define a preferred polling interval in the IN interrupt EP descriptor less or equal than your desired sending period. The host will issue IN requests to this endpoint at this frequency, if it can. Bu no other warranties (that the rate will be exactly as you specified, that the rate will be constant...)