USB HID and composite

The official STMicroelectronics Arduino core
danieleff
Posts: 99
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

USB HID and composite

Postby danieleff » Sat Nov 26, 2016 8:06 am

I uploaded a HID and USB Composite experiment to https://github.com/danieleff/Arduino_Co ... _Composite

Code: Select all

#include "USBDevice.h"
#include "usbd_hid.h"

#define BUTTON_PIN 32

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(BUTTON_PIN, INPUT);

  USBDevice.beginSerialHID();
}

uint8_t hidreport[4] = {0, 0, 0, 0};

int previous_buttons = 0;

void loop() {
 
  if (previous_buttons != digitalRead(BUTTON_PIN)) {
    hidreport[0] = digitalRead(BUTTON_PIN) ? 1 : 0;
    previous_buttons = hidreport[0];
    USBD_HID_SendReport(&hUsbDeviceFS, hidreport, 4);
    digitalWrite(LED_BUILTIN, hidreport[0]);

    Serial.println("Button pressed");
  }
 
}

EDIT * Use code in viewtopic.php?f=48&t=1586&p=20807#p20807

Could somebody check if it is showing up as usbserial + mouse, and pushing the button acts as a mouse button?
If it does not work, try changing usbd_desc.c #define USBD_PID_FS 22336 to someting else (as per UM0424 manual 11.3 section).
If still does not work, use an usb analizer, as troubleshooting USB remotely is impossible.
Last edited by danieleff on Sat Dec 03, 2016 8:14 am, edited 1 time in total.

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

Re: USB HID and composite

Postby RogerClark » Sat Nov 26, 2016 10:24 am

Sorry Daniel

Compiles OK now.

But I can't get it to upload to my Maple mini as its got the old bootloader

I'll have to look tomorrow as its getting too late today.

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

Re: USB HID and composite

Postby RogerClark » Sat Nov 26, 2016 8:26 pm

Daniel

I run the code but it seems to initially completely crash Java on Windows.

The Arduino IDE crashed straight after upload, and when I tried to restart the IDE it just crashed, so I ran the debug version and I get

Code: Select all

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x617493cd, pid=516, tid=0x00000d18
#
# JRE version: Java(TM) SE Runtime Environment (8.0_92-b14) (build 1.8.0_92-b14)
# Java VM: Java HotSpot(TM) Client VM (25.92-b14 mixed mode windows-x86 )
# Problematic frame:
# C  [listSerialsj.dll+0x93cd]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\rclark\AppData\Local\Temp\\hs_err_pid516.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#


I tried unplugging and changing the com port to COM1 then plugging the maple mini in again, but the IDE instantly crashes with the same message

I'm going to reboot and try again

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

Re: USB HID and composite

Postby RogerClark » Sat Nov 26, 2016 8:42 pm

Daniel

I don't know what you changed, but it completely crashes the IDE when I plug the Maple mini into my W7 PC.

If I comment out

Code: Select all

USBDevice.beginSerialHID();


It is OK again

I tried using

Code: Select all

  USBDevice.beginHID();


And it doesnt crash, but it doesnt work either ;-(

I don't get any new HID devices, and the serial device shows a yellow warning against it in the device manager

Did you commit all your files to github ?

Which OS are you using W8 or W10 ?

I have W10 on another machine, but don't have any current W8 or W8.1 installations I can try

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

Re: USB HID and composite

Postby danieleff » Sat Nov 26, 2016 9:11 pm

Thanks for trying. Even if not working, it should not crash the IDE, wow.
I am using windows 10 (and tried on a linux). git diff shows empty so it should be uploaded.

Could you try changing usbd_desc.c #define USBD_PID_FS 22336 (which is 0x5740 by the way) to for example 0x5750, then recompile the static lib. It might try to use a previous driver with the new "device".

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

Re: USB HID and composite

Postby RogerClark » Sat Nov 26, 2016 9:25 pm

Daniel

OK.

I'll try that.

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

Re: USB HID and composite

Postby RogerClark » Sat Nov 26, 2016 9:40 pm

Hi Daniel

Yes. Changing the PID stops it crashing, but it then won't install the driver for the Serial device (because the PID is wrong)

So I use the libwdi driver installer exe to install the serial driver, but the IDE immediately crashed again :-(

I have some other installations of W7 that I can try it on, which don't have the STM drivers installed.

I'll also try rebooting my machine, but I don't think rebooting will fix it :-(

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

Re: USB HID and composite

Postby danieleff » Sun Nov 27, 2016 6:01 am

I just tried it on a windows 7 and the result was as your: button worked as mouse (did you try it?), virtual COM not working, had yellow warning.

Than I used the libmaple driver Arduino\hardware\Arduino_STM32\drivers\win\install_drivers.bat , with the following line:

Code: Select all

"%~dp0wdi-simple" --vid 0x0483 --pid 0x5750 --iid 0 --type 3 --name "Maple Serial" --dest "%~dp0maple-serial"
Note the added "--iid 0" for composite interface ID

Could you try removing the driver you just installed from 0x5750, and add using this method instead? (Or with a different PID again)

(I will change the code later so that Serial.begin() uses 0x5740, and my experimental code uses other PID)

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

Re: USB HID and composite

Postby RogerClark » Sun Nov 27, 2016 6:11 am

Hi Daniel

I could not get it to work as it kept crashing the Arduino IDE.

I will try uninstalling and then using libwdi with the interface setting you used.

Did it crash for you.

All I have to do to make the IDE crash is plug in the Maple mini with the SerialHID sketch uploaded.

At one point Windows displayed a popup to say it was installing the composite and HID device, but could not install the Serial because of the PID, but as soon as I used libwdi to install the Serial driver, it crashed the IDE again :-(

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

Re: USB HID and composite

Postby RogerClark » Sun Nov 27, 2016 6:29 am

Daniel,

What version of the IDE and Java are you running.

I just tried updating my Java (I had to update it for something else recently, but I thought I'd update it again, but it was actually the same version.

V 8.0_92-b14 on

Actually, it may be my IDE installation. As its crashing in listserials.dll and I recall trying an update for that to resolve some other problem.

I'll re-install the IDE and let you know if that resolves the problem.

Edit.

I just noticed that the latest release of the IDE is 6.13 and I'm running 6.12, so it will be an upgrade for me ;-)


Return to “STM Core”

Who is online

Users browsing this forum: No registered users and 1 guest