Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

STM32 USB HID Boot Keyboard (BIOS / CMOS password compatible)

Sample USB keyboard stack configured as a HID Boot Keyboard so it works at BIOS/UEFI and CMOS password screens, not only in the OS.

Why this differs from CubeMX default HID

Item Typical CubeMX HID This sample
bInterfaceSubClass 0x00 (none) 0x01 (Boot)
bInterfaceProtocol 0x00 / mouse 0x01 (Keyboard)
Report often mouse / custom 8-byte boot keyboard
SET_PROTOCOL / GET_PROTOCOL missing / ignored implemented
Device shape sometimes composite single keyboard IF

Target

  • MCU family with USB Device FS (tested pattern: STM32F103 / F0 / F4 / G0 / L4)
  • STM32Cube USB Device Library (USBD)
  • USB Full-Speed device mode only (no composite)

Quick start (CubeMX)

  1. Create a new CubeMX project for your MCU.
  2. Connectivity → USB → Device (FS/FS Device only).
  3. Middleware → USB_DEVICE → Class: Human Interface Device Class (HID).
  4. Clock: ensure USB 48 MHz is valid.
  5. Generate code (STM32CubeIDE or Makefile).
  6. Copy/overwrite files from this repo into the generated project (see layout below).
  7. Call App_Keyboard_Init() after MX_USB_DEVICE_Init(), then App_Keyboard_Task() in the main loop (or use the demo button path).

Files to merge

USB_DEVICE/App/usbd_desc.c          <- VID/PID + strings (optional)
USB_DEVICE/App/usbd_hid_if.c        <- optional weak stubs
Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.c
Middlewares/ST/STM32_USB_Device_Library/Class/HID/Inc/usbd_hid.h
Core/Inc/app_keyboard.h
Core/Src/app_keyboard.c
Core/Inc/usb_hid_keys.h

If CubeMX regenerates middleware, re-apply usbd_hid.c / usbd_hid.h.

Demo behavior

After USB configures, the sample types test then Enter once (for bring-up). Disable APP_KEYBOARD_DEMO_TYPE_ONCE in app_keyboard.h for production.

BIOS checklist

  • Boot subclass + keyboard protocol in config descriptor
  • Exactly one HID keyboard interface
  • 8-byte interrupt IN reports
  • SET_PROTOCOL accepted (Boot = 0)
  • No CDC/MSC/mouse composite while validating CMOS password
  • On PC BIOS: USB legacy / USB keyboard support enabled if that option exists

License

Sample code is provided as-is for integration into ST Cube projects.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages