Skip to main content
Visitor II
May 13, 2021
Solved

STM32F4 USB Device Custom HID example

  • May 13, 2021
  • 10 replies
  • 4359 views

I am using a custom board with STM32F4 micro and I want to use the Cube libraries. I need a simple example of application of a USB Device configured as Custom HID. I need to know not only how to configure the USB, but also how to transmit data to the PC. On the PC I have a working custom driver software. I really don't know where to start.... Thank you very much.

    This topic has been closed for replies.
    Best answer by VCapu

    Ok. Solved for now. It was an hardware problem (damaged board). I tried the keyboard and the custom HID example. Now I need to modify an example so I can communicate with my custom driver on PC. My custom board has to work as a customizable keyboard. Is it better to start from the keyboard example or the custom HID example? Any suggestion on which part of the code I need to modify? Thank you

    10 replies

    ST Employee
    May 13, 2021

    Hello VCapu,

    If you are not sure where to start I would like to direct you to STM32 USB training. In the video material there is covered many topics on USB for and the lab are done on STM32F4 MCU. There are also included some examples on HID devices. Some other examples are also available in STM32CubeF4 software package. You were saying you were using custom board, if you will run in to some hardware related problem I would also consider to check this document AN4879. Let me know if you have any further questions.

    VCapuAuthor
    Visitor II
    May 14, 2021

    Thank you for the advice. I followed step by step the example "USB Custom HID Device lab", but when I connect the board to the PC it is detected as "Unkonwn Device" and if I try to open the HID terminal, it is shown the message "Failed to open device". Any suggestion? I am stuck on this part of my project...

    ST Employee
    May 14, 2021

    I will gladly try to help you, but I will need more information from you about your HW setup. For start what MCU are you using and are you using embedded pull-up or external one? Also how do you clock your USB peripheral? Are you using external high speed oscillator? If you are using MCU for which there will be ready to use example within the STM32CubeF4 FW package I would maybe recommend to try this example so you exclude HW related problems. I will wait for your answer.

    VCapuAuthor
    Visitor II
    May 17, 2021

    Hello Petr. The MCU is STM32F405ZGT6. In the GPIO settings on Cube I selected no pull up and no pull down. This is the clock configuration.0693W00000AOZeJQAX.pngIn the  STM32CubeF4 package there are no examples for boards with the same MCU. What could be the most similar to the one that I am using?

    In this phase, I need only to see that USB communication is working, and then understand how to modify an example to adjust it for my application. Thank you.

    ST Employee
    May 17, 2021

    Hello VCapu,

    according to RM0090, STM32F405xx/07xx and STM32F415xx/17xx all should be really similar together and from this reason I would go for examples in folder STM324xG_EVAL. There is also code for custom hid example. Do I understand it correctly that you have external pull-up resistor at the D+ line and external oscillator on your custom board?

    VCapuAuthor
    Visitor II
    May 18, 2021

    No, there is not external pull_up. I tried to set the internal pull-up but nothing changed. I use external oscillator.

    I will try to check that example. I need to make some modifications? Thank you.

    VCapuAuthor
    Visitor II
    May 19, 2021

    I tried also to use external pull-up on both USB lines or only on D+ but nothing changes.

    VCapuAuthor
    Visitor II
    May 19, 2021

    Do you have any suggestions? Thanks

    VCapuAuthorAnswer
    Visitor II
    May 20, 2021

    Ok. Solved for now. It was an hardware problem (damaged board). I tried the keyboard and the custom HID example. Now I need to modify an example so I can communicate with my custom driver on PC. My custom board has to work as a customizable keyboard. Is it better to start from the keyboard example or the custom HID example? Any suggestion on which part of the code I need to modify? Thank you

    ST Employee
    May 20, 2021

    Hello VCapu,

    sorry for delayed reply. I am glad to hear you have found the problem. I am not sure about what keyboard example are you talking about so I would probably start with the custom HID example with the usbd_customhid_if files. Further inspiration could be also found here. If you will have further questions It would be great if you can start a new feed for easier orientation.