cancel
Showing results for 
Search instead for 
Did you mean: 

USB HID - Host PC-Windows Application

JBlackann
Associate III
Posted on June 19, 2018 at 16:59

Hello ST Community, 

I am fairly new to the ST world.  I have used MXCube to create a USB HID device but I am having difficulty find an example USB HID - Host PC/Windows application that I can use to see the communication back and forth with my USB HID device.  I found the USB HID Demonstrator (

https://my.st.com/content/my_st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-utilities/stsw-stm32084.html

  ) but it failed to build with Visual Studio 2017.  The failure stated that it didn't support MFC version less than 0x0500.  I changed this to 0x0600 and then it built successfully.  I was able to launch the application but I don't know what USB HID firmware (device firmware) I should be using to communicate with the USB HID Demonstrator app.  From the documentation, it doesn't discuss what firmware should be used to communicate with the application. 

If anyone know of a good example that explains sending USB HID messages and an example application (for PC) that I can utilize to communicate back and forth that would be extremely helpful.  I found YAT (Yet Another Terminal) which looks like it supports HID communication but I can't see any communication from my USB HID Device. 

https://learn.sparkfun.com/tutorials/terminal-basics/yat---yet-another-terminal-windows

  

Thanks for any assistance. 

2 REPLIES 2
Ben K
Senior III
Posted on June 19, 2018 at 18:26

You could write your own simple application using the

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwjs1qaSkeDbAhWxsKQKHe-4DukQFggnMAA&url=https%3A%2F%2Fgithub.com%2Fmikeobrien%2FHidLibrary&usg=AOvVaw0T2nwMrSKIFtt34qb6vLZg

. It's a simple C# wrapper for Windows kernel calls. It contains some examples that get you started pretty fast. Unfortunately it won't necessarily work (if it doesn't, you will receive all 0s), but it's a good bet anyway.
JBlackann
Associate III

0690X000006Buf0QAC.pngSo I was able to get somewhere with the USB Hid Demonstrator from ST. I actually found a different example that was on YouTube and modified it to transmit and receive via Custom USB HID. Attached is the source that I had working in. I was using a STM32F401 via a Nucleo-F401RE board and my code was done in System Workbench for STM32.

On my Nucleo-F401RE I added a 4MHz crsytal to X3 and on my own dev board I used a 10MHz crystal. The defines are:

HSE_CRYSTAL_4MHZ

HSE_CRYSTAL_10MHZ

I used the clock generator via STM32CubeMX to generate the correct settings for the specific USB clock. You will either need to add a 4MHz or 10MHz crystal to use this code, or modify the code to use the crystal you have on hand. The code for the clock config stuff is found in SystemClock_Config.

Attached is a screenshot of a terminal application and also the USB Hid Demonstrator application. In the input/output transfer, you can see the input and output reports. The demo code is just sending the message "Hello World" plus a count over and over. It is possible to send information into the board using the Output Report. For demo purposes, you can manually modify the bytes then click on the Write button to perform a USB communication with the bytes in the Output Report window.

From the terminal, screenshot it shows:

received "1" in buffer[2]

received "1" in buffer[3],

received "1" in buffer[4],

I used this as the basis of building the different functions by sending different bytes into the devices and then performing different operations.

I also found the following example. https://soldernerd.com/2017/02/14/c-usb-hid-utility/ which details how to create a USB HID demo in C#.  

Once you have master communicating in and out of the device using the above USB HID Demonstrator it possible to work on the specific communication required to communicate with the USB HID Utility.

I hope other find this helpful.