USB HID and composite

The official STMicroelectronics Arduino core
User avatar
RogerClark
Posts: 5542
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: USB HID and composite

Postby RogerClark » Sun Nov 27, 2016 9:47 am

Daniel (or anyone else who wants to try it)

Here is my compile maple mini binary

(see attached)

Edit

BTW

I tried on Windows 10, and the Com port shows even before I load the driver and I see the HID devices

But I don't have the IDE installed on that machine, and I don't have a terminal program either, so I don't know if it actually works - though I presume it does

Perhaps Windows 7 has a bug with composite devices - I know that Windows XP had problems with composite devices, which is why Leaflabs decided that the Bootloader was only DFU and did not include Serial.

But I hoped that Windows 7 didnt have the same problem (but perhaps it does)
Attachments
usb_hid_composite.ino.STM32F103CB_MapleMini.zip
(11.76 KiB) Downloaded 44 times
Last edited by RogerClark on Sun Nov 27, 2016 9:51 am, edited 1 time in total.

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

Re: USB HID and composite

Postby danieleff » Sun Nov 27, 2016 9:48 am

The descriptor looked kinda OK in USBlyzer, but I will redo it next week. I am 100% sure it can work on Win7

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

Re: USB HID and composite

Postby danieleff » Sat Dec 03, 2016 8:04 am

I updated the branch, tried with Win10 (no driver needed), linux (no driver needed), Win7 (driver needed for usbserial).
PID: 0x5740 is used for Serial.begin(), 0x5741 for composite with Serial on interface 0, and 0x5742 where no driver is needed (HID, later MSC/audio...).

Added Mouse (set/press/release/click/move) and Keyboard(just experimental) files.

Current example 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);
}

int previous_buttons = 0;

void loop() {
 
  if (previous_buttons != digitalRead(BUTTON_PIN)) {
    previous_buttons = digitalRead(BUTTON_PIN) ? 1 : 0;
   
    Mouse.setButton(digitalRead(BUTTON_PIN));
    Keyboard.println("Hello!");
    digitalWrite(LED_BUILTIN, previous_buttons);
    Serial.println("Button pressed");
  }
 
}


To use USBSerial on Win7, run the `install_drivers_composite.bat`. (It needs the wdi-simple.exe, and I did not want to commit an .exe to git)

If it does not work:
  1. Make sure to use the correct COM port, as it will be different.
  2. Reboot?
  3. Use USB Device Tree Viewer, and copy/paste the data that is on the right side in that program.
Last edited by danieleff on Tue Dec 06, 2016 7:16 pm, edited 1 time in total.

User avatar
RogerClark
Posts: 5542
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: USB HID and composite

Postby RogerClark » Mon Dec 05, 2016 2:06 am

Thanks Daniel

I will test when I get some free time

Cheers

Roger

Elektrik
Posts: 4
Joined: Mon Dec 12, 2016 1:11 am

Re: USB HID and composite

Postby Elektrik » Mon Dec 12, 2016 1:16 am

Hello,

Tested on stm32f103c with 1.6.13 arduino ide on W10 x64, work very well.
Can't wait for it to have Joystick library (passing pot value from ADC) :o

User avatar
RogerClark
Posts: 5542
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: USB HID and composite

Postby RogerClark » Mon Dec 12, 2016 9:23 am

Daniel

Thanks.

It does seem to work OK for me now on Windows 7.

In the WIndows device manager, the Serial port becomes "Maple Serial Interface 0 (COMxx)"

and another "USB Input Device" appears in the "Human Interface Devices" section

I guess we need to work out how to merge all this into the stm32duino F1 repo

I'm a bit concerned that some of this stuff could impact on the original Nucleo codebase

I think I asked Frederic @ STM a similar question a month ago, so I will need to find his answer, as the changes we need to make to the official repo are getting more and more invasive as we need to change a high proportion of their code (not just for this but for the I2C and the RAM usage, and the USB support, etc etc etc

Freakeyyy
Posts: 5
Joined: Sat Sep 10, 2016 8:42 pm

Re: USB HID and composite

Postby Freakeyyy » Tue Dec 13, 2016 1:29 pm

Hey guys, noobie question here :
While trying to upload anything to a maple mini with this branch, I keep getting "Cannot set alternate interface: usb_set_altinterface: could not set alt interface 0/2: win error: No more data is available."
Do you have any idea why ?

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

Re: USB HID and composite

Postby danieleff » Tue Dec 13, 2016 1:48 pm

Freakeyyy wrote:Hey guys, noobie question here :
While trying to upload anything to a maple mini with this branch, I keep getting "Cannot set alternate interface: usb_set_altinterface: could not set alt interface 0/2: win error: No more data is available."
Do you have any idea why ?

Check that you have the correct board, upload method, com port selected. (Actually the COM port will be different than when using the main branch).
This thread might help: http://www.stm32duino.com/viewtopic.php?t=708

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

Re: USB HID and composite

Postby danieleff » Tue Dec 13, 2016 2:02 pm

Elektrik wrote:Hello,

Tested on stm32f103c with 1.6.13 arduino ide on W10 x64, work very well.
Can't wait for it to have Joystick library (passing pot value from ADC) :o

It would be cool to use https://github.com/MHeironimus/ArduinoJ ... r/Joystick
Unfortunately that code is based on the arduino due usb code which uses C++ virtual functions, specifically the PluggableUSBModule class.
While the current stm32duino USB code (serial and hid) is currently based on the ST USB middleware, which is based on c function pointers.

It might be possible to create some glue code between the two, although thats ugly.
Or copy the joystick library, and modify it. Its copy-paste duplicate.
Or rewrite the whole USB code to be compatible with official arduino USB. That would be ideal. But error prone, and a lot of work.

Freakeyyy
Posts: 5
Joined: Sat Sep 10, 2016 8:42 pm

Re: USB HID and composite

Postby Freakeyyy » Tue Dec 13, 2016 3:13 pm

danieleff wrote:Or copy the joystick library, and modify it. Its copy-paste duplicate.


Do you mean copy the Mouse library and modify it ?


Return to “STM Core”

Who is online

Users browsing this forum: No registered users and 1 guest