cancel
Showing results for 
Search instead for 
Did you mean: 

USB HID mouse

_behn4m
Associate II
Posted on May 08, 2014 at 09:42

Hi

I want to create custom HID device with stm32f407 and as first step I tried to rebuild the demo project for usb Mouse HID on my own, i've added needed libraries and definitions (frome demo project) and use USB_init as below to config the usb on micro, but when I connect USB to pc, after some second it says ''not usb recognized device'' anything more should I do for config the usb?

#include ''stm32f4xx.h''

#include ''usbd_hid_core.h''
#include ''usbd_usr.h''
#include ''usbd_desc.h''
#include ''usbd_conf.h''
#include ''usb_conf.h''
__ALIGN_BEGIN USB_OTG_CORE_HANDLE USB_OTG_dev __ALIGN_END;
int main(void)
{ 
USBD_Init(&USB_OTG_dev,
USB_OTG_FS_CORE_ID,
&USR_desc, 
&USBD_HID_cb, 
&USR_cb);
while(1) {}
return 0; 
}

thank you #hid-usb-stm32f4-demonst
8 REPLIES 8
chen
Associate II
Posted on May 08, 2014 at 10:47

Hi

You have only mentioned which processor you have but you have not said which development board (assuming you are using a dev board) you have.

If you have this one :

http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF252419

The pre-loaded demo has HID functionality built in.

Download the demo project from here :

http://www.st.com/web/en/catalog/tools/PF257904#

The project under 'Demonstration' should just work as a HID mouse.

Alternatively, use this as a starting project and modify as needed.

_behn4m
Associate II
Posted on May 08, 2014 at 11:35

ow, I'm sorry, yes i have discovery board as you said

I found the problem just minutes ago, I forgot to use IRQ HANDLERS to send reports.

now another problem I have. The structure of USB classes and drivers are so complicate, I'm going to write my own custom descriptors, and I don't understand how should I use them in this structure (usb cores, classes , ...) !?

chen
Associate II
Posted on May 08, 2014 at 11:56

Hi

''The structure of USB classes and drivers are so complicate,''

Yep.

''I'm going to write my own custom descriptors,''

No, I would avoid that. It gets complicated real quick.

Just modify the existing descriptors.

Search the STM32 forums, there have been  a few people modifying the HID mouse example with help from the forum.

''I don't understand how should I use them in this structure (usb cores, classes , ...) !?''

Try the documentation :

http://www.st.com/web/en/catalog/tools/FM147/CL1794/SC961/SS1743/PF257882

The structure of the OTG library starts to make a little sense after reading the documentation.

Certainly give big hints on which files need modifying and which to leave alone.

_behn4m
Associate II
Posted on May 09, 2014 at 16:39

thank a lot, I read that doc before, but I still don't know where should I edit descripto to create my custom HID device.

I think it's neede to read the document again.

thank you

chen
Associate II
Posted on May 09, 2014 at 17:06

Hi

''but I still don't know where should I edit descripto to create my custom HID device.''

The USB descriptor is 'easy'. It is in

usbd_desc.c

usbd_desc.h

This file holds the description that is returned to the host during enumeration.

What I suspect you mean is

''How do I implement the functionality of my custom HID device''

The documentation describes the layout/layers of the USB OTG driver.

Hints at which files need to be modified (for USH Host or USB Device - HID is a USB Device).

Also Search this forum, I know a cuple of others have asked about implementing joypad HID

_behn4m
Associate II
Posted on May 09, 2014 at 18:38

Just last question, I promise :D

I found descriptor and its clear, now after modifying that, I want to send my reports to PC by ''

USBD_HID_SendReport()'' function. is it create report automatically (in class functions & etc) and its I should just return buffer of data to it? or I should myself create the report?

thank you much more ;)

chen
Associate II
Posted on May 09, 2014 at 19:04

Hi

''Just last question, I promise :D''

No problems. Feel free to ask (sensible) questions.

''I want to send my reports to PC by ''

USBD_HID_SendReport()'' function. is it create report automatically (in class functions & etc) and its I should just return buffer of data to it? or I should myself create the report?

''

It looks like the function is provided by the core library for USB HID

I am afraid that I have not tried a HID device myself so I cannot say from experience.

The document (UM1021 STM32F105xx, STM32F107xx, STM32F2xx and STM32F4xx USB On-The-Go host and device library) states :

''The USBD_HID_SendReport can be used by the application to send HID reports, the HID driver, in this release, handles only IN traffic.''

so my guess is that you just call the function and pass your data in.

Again, search this forum. I know some others have been asking about USB HID

_behn4m
Associate II
Posted on May 09, 2014 at 20:36

I think I found answer of all my questions now.

here I found good description about HID packets: http://www.usbmadesimple.co.uk/ums_5.htm

and in this page, I found my last questions answer :

http://www.usbmadesimple.co.uk/ums_ms_desc_conf.htm

after introduce HID device to host, it's just needed to send data as described in ''

Device Descriptor

'' before.

thank a lot for your patience and help.

Now I think I'm ready to start my custom HID