USB HID and composite

The official STMicroelectronics Arduino core
Posts: 3
Joined: Thu Jan 12, 2017 5:44 am

Re: USB HID and composite

Postby gungsukma » Thu Jan 12, 2017 7:29 am

I want to use keyboard and mouse from my Blue Pill (STM32F103C8T6).
Searching "HID" in this forum and ends up here.
Well, will be very nice to have Keyboard/Mouse, and on the same time, serial. :D

So I install STM32Duino, here what I was done, if I remember correctly:
1. Extract Arduino-1.8.0 IDE
2. Make Arduino-1.8.0\Portable folder (I use external hard drive)
3. Install Arduino Zero board
4. Extract Arduino-1.8.0\hardware\Arduino_STM32-master (
5. Run Arduino-1.8.0\hardware\Arduino_STM32-master\drivers\win\install_drivers.bat
7. Test "blink", success.

And for the HID:
1. Make Arduino-1.8.0\hardware\STM32_official folder
2. Extract Arduino-1.8.0\hardware\STM32_official\STM32F1 (
3. Remove Arduino-1.8.0\hardware\Arduino_STM32-master\STM32F1
4. Extract Arduino-1.8.0\hardware\STM32_official\Tools (
5. Remove Arduino-1.8.0\hardware\Arduino_STM32-master\Tools

6. Try to compile this code:

Code: Select all

#include "USBDevice.h"
#include "Mouse.h"
#include "Keyboard.h"
#define BUTTON_PIN 32
void setup() {
  USBDevice.beginSerialHID(&Mouse, &Keyboard);

7. Got this error: :cry:

Code: Select all

In file included from D:\arduino-1.8.0\Portable\sketchbook\serial-hid\serial-hid.ino:1:0:
D:\arduino-1.8.0\hardware\STM32_official\STM32F1\cores\arduino/USBDevice.h:8:24: error: 'USBD_HandleTypeDef' has not been declared
         void attachUSB(USBD_HandleTypeDef *usbDevice, uint8_t HIDReportID);
D:\arduino-1.8.0\hardware\STM32_official\STM32F1\cores\arduino/USBDevice.h:13:9: error: 'USBD_HandleTypeDef' does not name a type
         USBD_HandleTypeDef *usbDevice;
Multiple libraries were found for "Mouse.h"
 Used: D:\arduino-1.8.0\hardware\STM32_official\STM32F1\libraries\Mouse
 Not used: D:\arduino-1.8.0\libraries\Mouse
Multiple libraries were found for "Keyboard.h"
 Used: D:\arduino-1.8.0\hardware\STM32_official\STM32F1\libraries\Keyboard
 Not used: D:\arduino-1.8.0\libraries\Keyboard
exit status 1
Error compiling for board BluePill F103C8.

8. Removing folder Arduino_STM32-master, same

"'USBD_HandleTypeDef' has not been declared"
May be I miss some steps?

Board: BluePill F103C8
Upload Method: Serial
OS: Windows 7 32 bit

Posts: 630
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: USB HID and composite

Postby stevestrong » Thu Jan 12, 2017 8:08 am

Serial upload is only targeted to be used for bootloader.
Try the "Stm32duino bootloader" upload option, otherwise is not guarantied that the serial USB is compiled.

Posts: 103
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary

Re: USB HID and composite

Postby danieleff » Fri Jan 13, 2017 5:25 am

Can confirm that the error is because of the serial upload method.

If you really want to upload via Serial, you can workaround by adding `` to the `boards.txt`, although this will change `Serial` to USB , and `Serial1` will be the UART1.

I will have to modify the code so that USB is included if the chip has USB, and not only if Serial-is-USBSerial based on menu settings. Or something.

Posts: 3
Joined: Thu Jan 12, 2017 5:44 am

Re: USB HID and composite

Postby gungsukma » Fri Jan 13, 2017 6:35 am

1. D:\Arduino-1.8.0\hardware\Arduino_STM32-master\tools\win\stm32flash.exe -w generic_boot20_pc13.bin -v -g 0x0 COM5
2. Boot0: LOW
3. Use the USB cable data.
4. Upload method: STM32duino bootloader

5. serial-hid.ino as below

Code: Select all

#include "USBDevice.h"
#include "Mouse.h"
#include "Keyboard.h"

void setup() {
  pinMode(PC13, OUTPUT); // PC13 and LED_BUILTIN
  USBDevice.beginSerialHID(&Mouse, &Keyboard);

void loop(){
  digitalWrite(PC13, HIGH);
  digitalWrite(PC13, LOW);

6. Upload OK :D

The line below is the result:

Thank you very much.

Posts: 1
Joined: Fri Feb 17, 2017 7:45 am

Re: USB HID and composite

Postby mobi123 » Fri Feb 17, 2017 9:10 am

Code: Select all

D: \ Arduino \ hardware \ Arduino_STM32-master \ STM32F1 \ cores \ maple \ USBDevice.cpp: 2: 22: fatal error: usbd_hid.h: No such file or directory

  #include "usbd_hid.h"


Compilation terminated

Exit status 1
Compiler error for development board Generic STM32F103C series.

Return to “STM Core”

Who is online

Users browsing this forum: No registered users and 1 guest