USB HID and composite

The official STMicroelectronics Arduino core
gungsukma
Posts: 4
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 (Arduino_STM32-master.zip)
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 (Arduino_Core_STM32F1-USB_HID_Composite.zip)
3. Remove Arduino-1.8.0\hardware\Arduino_STM32-master\STM32F1
4. Extract Arduino-1.8.0\hardware\STM32_official\Tools (Arduino_Tools-master.zip)
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() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(BUTTON_PIN, INPUT);
  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?

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

stevestrong
Posts: 1011
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.

danieleff
Posts: 216
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

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 `BluePill_F103C8.menu.upload_method.serialMethod.build.upload_flags=-DSERIAL_USB` 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.

gungsukma
Posts: 4
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
  pinMode(LED_BUILTIN, OUTPUT);
  USBDevice.beginSerialHID(&Mouse, &Keyboard);
}

void loop(){
  digitalWrite(PC13, HIGH);
  delay(1000);
  digitalWrite(PC13, LOW);
  Keyboard.write('a');
  Keyboard.write('b');
  Keyboard.write('c');
  Keyboard.write('d');
  Keyboard.write('e');
  Keyboard.write('f');
  Keyboard.write('g');
  delay(5000);
}


6. Upload OK :D

The line below is the result:
abcdefgabcdefgabcdefgabcdefg

Thank you very much.

mobi123
Posts: 4
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.

gungsukma
Posts: 4
Joined: Thu Jan 12, 2017 5:44 am

Re: USB HID and composite

Postby gungsukma » Tue Feb 21, 2017 9:55 am

mobi123 wrote:

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.


If you follow my steps above, there should be the file on this location:
D:\arduino-1.8.0\hardware\STM32_official\STM32F1\system\Middlewares\ST\STM32_USB_Device_Library\Class\HID\Inc\usbd_hid.h

Board: BluePill F103C8
Upload Method: STM32duino bootloader


Return to “STM Core”

Who is online

Users browsing this forum: No registered users and 2 guests