STM32 USB HID Custom Joystick/Gamepad Tutorial: Creating a DIY Controller
0:00 Introduction: This tutorial demonstrates how to create a custom USB HID (Human Interface Device) joystick/gamepad using an STM32H7 microcontroller, thumbsticks, switches, and USB 2.0.
0:32 Design Files: The hardware design files, including Altium Designer schematic and PCB files, are available on the creator's GitHub repository (github.com/pms67/QueenB).
2:29 HID Introduction: USB HID is a standardized device class for easy communication between custom devices (like joysticks, keyboards, mice) and host computers.
3:11 Hardware Overview: The tutorial focuses on interfacing an STM32H7 with two thumbsticks (each with X, Y axes and a button) and four slide switches.
5:14 CubeIDE Setup: Demonstrates the initial setup in STM32CubeIDE, including pin configuration, clock configuration (26MHz HSE oscillator, 480MHz core clock), and enabling USB device (full speed).
8:58 ADC, DMA, and Timer Setup: Configures ADC channels for thumbstick potentiometers, sets up DMA for continuous sampling, and configures Timer 3 for triggering ADC conversions at 100Hz.
13:18 USB HID Middleware: Enables the STM32's USB HID middleware, configuring it for a joystick/gamepad (not a mouse) and setting the polling interval to 10ms (full speed).
15:36 ADC Code Implementation: Shows how to implement ADC data acquisition, calibration, and starting ADC with DMA and Timer.
18:52 GPIO Reads: Implements polling routines to read the states of the four switches.
20:09 usbd_hid.h/.c Explanation: Explores the core USB HID files, focusing on the usbd_hid_SendReport function which sends data to the host.
24:04 Report Descriptor Customization: Details the crucial step of modifying the HID report descriptor to define the joystick's structure (buttons, axes) and data format. This involves specifying usage pages, usage IDs, logical minimums/maximums, report sizes, and report counts for each element.
30:08 Filling and Sending the Report: Explains how to create a struct (joystick_report) to hold the button states and thumbstick values, fill it in the ADC callback and main loop, and send it to the host using usbd_hid_SendReport.
33:30 Testing: Demonstrates how to verify the functionality of the custom joystick/gamepad in Windows' Game Controllers control panel and an online gamepad tester, confirming that the buttons and axes are correctly mapped and recognized by the host.