cancel
Showing results for 
Search instead for 
Did you mean: 

HID USB HOST example ported to STM32F4 Discovery: Mouse + KeyBoard

STM32 hobbyist
Associate III
Posted on September 16, 2012 at 20:51

Hi All;

For people who interested by connecting a mouse or a keyboard to the STM32F4 Discovery:

Attached a project that I have ported from the example provided in ''USB On-The-Go host and device library'' that works on STM3240G-EVAL board.

IAR 6.40 is used to compile the project. I didn't port it to other toolchains: keil, Tasking ...

When a mouse is connected:

The Blue Led should turn on.. Otherwise, desconnect the mouse or push the RESET button.

Clicking on the Left button of the mouse the green LED toggles

Clicking on the right button of the mouse the Red LED toggles

Clicking on the middle button of the mouse the orange LED toggles

moving the mose toggle the blue LED

Disconnecting the mouse from the Discovery board turns off all LEDs

When a Keyboard is connected:

The Blue Led should turn on.. Otherwise, desconnect the mouse or push the RESET button.

Hitting any key on the keyboard toggles the orange LED.

Disconnecting the mouse from the Discovery board turns off all LEDs

The port is done by:

Modifying the clock configuration: HSE clock from 25Mhz to 8Mhz

Removing all related LCD functions.

Configuring LEDs for the Discovery board. 

Deleting the polling on the user button in order to launch the HID application without waiting on user key press.

Have fun ;)

STM32
10 REPLIES 10
bluexav
Associate III
Posted on January 12, 2013 at 16:48

Thank you very much for this !

I've built the example with IAR 6.40 KickStart : my keyboard will work very well but neither of my two mouses...

The one rated at 50mA light on for 1 s then lights off.

The other one rated at 100mA won't light on.

What could be the problem ?

Cheers,

Xavier

bluexav
Associate III
Posted on January 14, 2013 at 17:49

Please could anybody try this piece of code with a mouse and tell me wether it works or not ? (You need an adapter micro male USB <--> USB A female to plug the mouse)

I've tried many different configs but I've got nothing...

THX

chichkinei
Associate II
Posted on January 15, 2013 at 08:51

It's a shame I don't know how to compile it with truestudio. Can you post a .hex or .elf so I can upload it directly? (if I can figure that out) I at least want to know if I've wired my usb A to micro B correctly (soldered together my own; yes I'm a hack)

bluexav
Associate III
Posted on January 16, 2013 at 00:59

Thank you Ivan to accept to try it !

I've attached the (non functionning) hex file...

In the meantime I have applied fixes coming from here:

https://github.com/byly/uubt

It greatly improve the situation as my Logitech mice sometimes work now but not always....

The mouse is not recognized at each startup, it's very unpredictable !

The corresponding hex file is also attached.

________________

Attachments :

USBH_HID_bad.hex : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hzyc&d=%2Fa%2F0X0000000bS4%2FIlErl5s6OBfZnR6b9oFsvQuwavCu9F0MV.IIpUn3ihM&asPdf=false

USBH_HID_better.hex : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I00N&d=%2Fa%2F0X0000000bS3%2FgBTapHdo2BYV0JhWkPhDSKEHs._bOWoHKeoiAIZnMDA&asPdf=false
chichkinei
Associate II
Posted on January 16, 2013 at 03:28

No problem, thanks for hex files. Both bad.hex and better.hex work with my 100mA mouse, but neither work with my keyboard. better.hex causes the green led to be lit up along with the blue one when the device is recognized.  Now I just need to port this into TrueSTUDIO.

frankmeyer9
Associate II
Posted on January 16, 2013 at 13:35

This forum is a PITA, it routed 4 posts of mine to /dev/null ...

But back to the topic.

Have you tried an ext. powered hub ?

I doubt your board can supply so many USB devices.

bluexav
Associate III
Posted on January 16, 2013 at 18:31

fm : It's just about plugging *one* mouse on the OTG connector !

Well the original file seems to work only with USB 2.0 mice or keyboards.

My low-end USB 1.10 mouse will never be recognized...

bluexav
Associate III
Posted on January 16, 2013 at 22:26

Ivan : thank you for testing !

I'm going to try to compile this project with GNU ARM gcc and makefiles...

bluexav
Associate III
Posted on January 28, 2013 at 19:12

Work done !

If you use the GNU tool chain, see :

https://github.com/MrBlueXav/USB_host_HID_demo

Enjoy !