Custom USB HID Interface using STM32 (stm32f103c8)

Sdílet
Vložit
  • čas přidán 22. 06. 2020
  • How to build a Custom USB HID interface on an STM32 (stm32f103c8) and control it using a GUI built with Python and GTK .
    Project Code :
    github.com/foxmjay/usbHidDemo
    Useful links :
    www.beyondlogic.org/usbnutshe...
    www.keil.com/pack/doc/mw/USB/...
  • Věda a technologie

Komentáře • 47

  • @user-qy7fw9id5n
    @user-qy7fw9id5n Před měsícem +1

    Thank you for taking the time to make this. It saved me hours. The USB protocol is very complex and I couldn't find a concise tutorial. I thought I needed to make a custom report descriptor which is a real rabbit hole.. Oussama walked me through how to setup exactly what I was looking for and tied to together information I'd gathered elsewhere. I have solved my current problem and I have better understanding of USB HID protocol and STM32 USB.

    • @OussamaOusmoi
      @OussamaOusmoi  Před měsícem

      Thank you, i'm glad it helped.
      Good luck and keep on building:)

  • @tonyzhang5125
    @tonyzhang5125 Před 7 měsíci

    Very nice video, I've been taught not only STM32 Embedded HID interface but also a GTK-based upper software to control via this interface. Thank you

  • @fpgamachine
    @fpgamachine Před 2 lety +1

    Thanks for the explanation. This is gold.

  • @TheCitygear
    @TheCitygear Před 10 měsíci +1

    Thank you for detailed explanation!

  • @otenyop
    @otenyop Před 3 lety +2

    Thanks,this is what I was actually looking ! i.e. a code to write from host to device USB. Thanks man!

    • @OussamaOusmoi
      @OussamaOusmoi  Před 3 lety +1

      I'm glad you found it useful. Good luck man !

    • @otenyop
      @otenyop Před 3 lety

      @@OussamaOusmoi Hi its me again! I have data in an array of 150 rows with 2 columns that I need to send from my host to my STM32 device using USB. I can see there is a 64 bytes limitation when setting up the out report buffer. How can I go round this limitation to send the full data set to my device? Thanks

    • @OussamaOusmoi
      @OussamaOusmoi  Před 3 lety

      64 bytes is the maximum data you can send at once using full-speed configuration.
      But you can split your data and send it on multiple writes , that's the easiest way if the speed is not critical .
      You can also look into other transfer modes like bulk .
      64bytes is the maximum for full speed usb though, i don't think there is a way around that .

    • @otenyop
      @otenyop Před 3 lety

      @@OussamaOusmoi Thanks for the reply. I don't mind using other transfer modes. Do you have a video or article on how I can use the bulk transfer mode? Thanks

    • @OussamaOusmoi
      @OussamaOusmoi  Před 3 lety

      @@otenyop Unfortunately i don't have any video regarding bulk transfer, i never worked on it either . Probably i didn't explain well in my last message, but even with bulk in full-speed USB you will be limited to 64Bytes , the only thing you will gain with bulk is speed.
      High-speed USB can go up to 512bytes , but that's a different hardware and software implementation which is beyond my capabilities at the moment : ).
      But i still believe you can get away with 64bytes . if i understand well , you need to transfer 150*2= 300Bytes ? . you can send that in 5 parts

  • @user-vu9my4mc8m
    @user-vu9my4mc8m Před rokem +1

    Thanks for your videos!

  • @m1geo
    @m1geo Před rokem

    Really useful, thanks!

  • @zetaconvex1987
    @zetaconvex1987 Před rokem

    Thanks for the tutorial.

  • @johnadcock5342
    @johnadcock5342 Před rokem

    Thanks for your videos! I jumpered my ST-Link V2 and although it's difficult it works like a charm. Enjoyed that video. I'm looking at this HID interface video and I'm wondering if you can describe the tools your using to create the gui etc. Python apparently as well as? Glade maybe? If you could go into some detail about what you're using I would certainly appreciate it. I'm on Mint Mate 20.2 Uma. Thanks in advance Oussama!

    • @OussamaOusmoi
      @OussamaOusmoi  Před rokem

      Thanks, i'm glad it helped .
      Regarding the GUI i didn't use any tool, you just need Python and the GTK library , i've used grid layout to align the elements and that's it :) .

  • @alexstickel5884
    @alexstickel5884 Před 2 lety

    This is a wonderful video. I know you have not tested it in Windows but when I does not seem to work it still shows up as a Virtual Comm Port just as the NUCLEO board did when it was out of the box. I see no HID.

    • @OussamaOusmoi
      @OussamaOusmoi  Před 2 lety

      Thanks 👍 . You are right, i haven't test this on windows, buy can you install usblib binaries for Windows, i'm not sure if it will work, but worth the try.
      Good luck

  • @maofpv9272
    @maofpv9272 Před 5 měsíci

    Thanks for the video! Ive been exactly looking for something like this. I have some questions: 1. Is it possible to change the hid descriptor so that the stm32 is being recognized as a keyboard? (So the stm32 acts like a keyboard, but you can still control it via a GUI in python for example). 2. Is it also possible to receive data from the stm32? (So for example the GUI in python reads some data from the STM32 over the usb hid interface)

    • @Jukebox300Minecraft
      @Jukebox300Minecraft Před měsícem

      Yes and yes. Matej Blagsic has a CZcams video showing how to make a keyboard with the Custom HID class. Sending data is actually easier than receiving because you can just use USBD_CUSTOM_HID_SendReport. You should be able to make your device work as both a keyboard and a custom HID device to send data back and forth by using multiple collections in your report descriptor.

  • @abhishekshankar4072
    @abhishekshankar4072 Před 2 lety

    Hi, Thank you for such detailed explanation. I'm facing this issue on windows, where the dev.write() method is timing out. Occasionally it has not. Would you have any idea what's happening?

    • @OussamaOusmoi
      @OussamaOusmoi  Před 2 lety

      If you are not sending a lot of data and not sending it too quickly it shouldn't timeout , the only thing that i suspect that could cause that is hardware, double check if your usb wirings is well connected and of a good quality cable to minimise interference.
      Good luck

    • @abhishekshankar4072
      @abhishekshankar4072 Před 2 lety

      @@OussamaOusmoi I'm just trying to write 2 bytes. Also, I'm able to read (2 bytes) without any issue. But write times out most of the time. There is no problem with device recognition either. So I don't think it's a hardware issue.

    • @abhishekshankar4072
      @abhishekshankar4072 Před 2 lety

      There is some issue with the CUSTOM_HID_OutEvent_FS() function which does not get invoked whenever the PC is sending something to the MCU. But when I used the USBD_CUSTOM_HID_ReceivePacket(&hUsbDeviceFS) function (I'm using STM32G473) in the main while loop to read data, the timeout issue doesn't occur and the data is reliably sent to the MCU! I don't understand why the CUSTOM_HID_OutEvent_FS() callback function isn't working.

    • @OussamaOusmoi
      @OussamaOusmoi  Před 2 lety

      @@abhishekshankar4072 I see that's odd, I would love to thinker a bit more on this but i had to disassemble my setup . if you find the cause plz share it with us 👍

  • @samsamm777
    @samsamm777 Před 2 lety

    I don't really understand the part where you updated the report descriptor to include an extra byte (12:02) Can you link any documentation on this part please?

    • @OussamaOusmoi
      @OussamaOusmoi  Před 2 lety +1

      As i mentioned the report descriptor is for devices that need to be recognized by the host , such as keyboard, mouse , joystick ... . the byte 0xa1 0x01 represents the beginning of somethings called a Collection( Application ) and the end of the collection is represented with 0xc0 . It's the minimum that the report descriptor need to have , at least what worked for me .
      you can check this link eleccelerator.com/tutorial-about-usb-hid-report-descriptors it's not applied for the stm32 , but it may help you understand it a little better .

    • @samsamm777
      @samsamm777 Před 2 lety

      @@OussamaOusmoi Ahh Thanks! I understand now. Those 3 bytes creates an empty collection. I guess you could have specified more in the report here to describe all the buttons.

    • @jamilf84
      @jamilf84 Před 2 lety

      Actually, when I plug in my stm32 device I have an exclamation mark next to the "USB Input Device" in device manager, and I have the message "A top level collection was declared without a usage or with more than one usage." Any thoughts?

  • @najamiqbal5503
    @najamiqbal5503 Před 3 lety

    Hi. Great work, Would you be kind enough to assist me how can i use my esp32 as an HID keyboard device

    • @OussamaOusmoi
      @OussamaOusmoi  Před 3 lety +2

      Hi najam,
      The esp32 is actually different than the stm32 , I never tried HID usb on it and I don't see anyone managed to implement that so far . however if you want bluetooth HID keyboard it appears that there is a github repository owned by manuelbl, check it out.
      Good luck

  • @khalidkhushal3563
    @khalidkhushal3563 Před 3 lety

    you are doing great, I am working on my final year project , I want to build a password manager using hid devices . I need guidance like where to start from can you help me?

    • @OussamaOusmoi
      @OussamaOusmoi  Před 3 lety

      Hi,
      Most of DIYs password managers i've seen do acting as an HID keyboard , so i would suggest to start by implementing that first . i suggest to look for an arduino based DIY projects instead of an STM32 as really the documentation is lacking a bit on the STM32 HID devices .
      I was actually very interested to build a password manager as well, i just couldn't find the time to do so. so maybe it's the time :).
      If you want to keep it simple, there is an arduino implementation for HID usb, it's called V-USB , it uses a regular atmega8 or an atmel 328p microcontroller that are found in most of the standard arduinos. you can check it out as well.
      Good luck

  • @hoantran4002
    @hoantran4002 Před 3 lety

    I made the same but it gave me "driver error" issue on windows 10.

    • @OussamaOusmoi
      @OussamaOusmoi  Před 3 lety +1

      I haven't test it on windows, so i can't help you much. however make sure to install libusb version 1.2.6.0 as it does support windows 10 64bit and see if it works.

  • @bassamry
    @bassamry Před rokem

    im on windows 10 and get in device manager "unknown USB device (Device descriptor request failed)" any idea in which stage this can fail?

    • @OussamaOusmoi
      @OussamaOusmoi  Před rokem

      If I was you, I will probably check CUSTOM_HID_ReportDesc_FS and
      USBD_CUSTOM_HID_CfgFSDesc
      maybe you missed something.
      Good luck :)

    • @bassamry
      @bassamry Před rokem

      @@OussamaOusmoi How does your computer identify the device? did you install a driver?

    • @OussamaOusmoi
      @OussamaOusmoi  Před rokem +1

      @@bassamry In linux the driver is supposed by default. on windows not sure, try search for usblib driver for windows maybe that's what missing.

  • @muhamedtrumic4700
    @muhamedtrumic4700 Před 3 lety

    Can this be done with arduino bootloader ? I have stm32 with arduino bootloader and I want to make gampepad.

    • @OussamaOusmoi
      @OussamaOusmoi  Před 3 lety

      Yes it's possible, but i haven't tried it though .
      you can google STM32 arduino joystick . i have seen few .
      Cheers.

    • @muhamedtrumic4700
      @muhamedtrumic4700 Před 3 lety

      @@OussamaOusmoi Great, thanks

  • @silvioaugustobortolim3795

    Hello how are you. Excellent video, good explanation. Congratulations. I unfortunately for my application with the Host already developed I can't receive more than 2 payloads by the function -> static int8_t CUSTOM_HID_OutEvent_FS(uint8_t *buffer). Even the link on the STM website similar to your explanation didn't work either. To send payloads from Device to Host works fine, Ok. Could you help me and I thank you in advance.

  • @tallabrianmonde3021
    @tallabrianmonde3021 Před 3 lety

    Great tutorial please can you kindly give me your email i have searched but could not find thanks.

    • @OussamaOusmoi
      @OussamaOusmoi  Před 3 lety

      Hi, i have updated the channel's about details, you can find my email there now .
      Thanks