Page 1 of 1

Need a simple example with (lib)USB

Posted: Thu Jul 05, 2012 4:35 pm
by Mathias
Hi,
I'm using and STM32F4 Discovery and want to use the USB port. For various reasons I don't want to use the CDC interface. So after two days of digging through USB descriptors, configurations and other code, does anyone have a simple example?
All I want is an example with two bulk endpoints, one callback for received data, and one function to send data back.
I think I have code for the Host part using libUSB, but if anyone has both working together I'd gladly use that too.

Thanks in advance,
Mathias

Re: Need a simple example with (lib)USB

Posted: Thu Jul 05, 2012 5:29 pm
by Abhishek
Hi Mathias,

I remember using AVR and V-USB two years ago. I had developed a complete AVR-GCC firmware + C# software combo to remote control a Nokia 6610 LCD. I could even upload images to the display via the control-in endpoint. Of course bulk-endpoints were not used on AVR, it wasn't powerful enough.

I've tried to find examples for a vendor-class device for STM32 USB Library, but seems that none exists around. I haven't even attempted to use USB on STM32 in my own code, I found it very unfamiliar as compared to the V-USB library on AVR (though I've tried out STM32 demos on my F4Disco). I'm looking forward to trying out the code you posted in the 'Code Samples' section, really a nice effort.

Now that you've raised a demand for a 'vendor-class' device, I'll second it. :)

Such an example for ChibiOS would certainly be a good idea, what does the community have to say?

Abhishek

Re: Need a simple example with (lib)USB

Posted: Thu Jul 05, 2012 5:53 pm
by Mathias
I wanted to post a few lines about my status:
I think I have my device descriptors correct, although I think they are kind of difficult on ChibiOS compared to other implementations I've seen (maybe thats because its more efficient?). The device enumerates correctly, I can open it, claim it but read/write fails.
On the ChibiOS side, I have no idea what to do in the "Requests hook callback", when I always return false it enumerates, but that can't be right. I wasn't able to deduce what to do in that function from the CDC or MSC examples. Also I'm not sure what exactly to do int the dataTransmitted callback...

Someone seemed to be able to get something USBish working:
viewtopic.php?f=2&t=111&p=578

Re: Need a simple example with (lib)USB

Posted: Thu Jul 05, 2012 6:10 pm
by Abhishek
I think the callback should always return 'false' for a normal operation. It is required only for handling custom vendor-requests. The HAL Code seems to handle the most common ones for us.

I'm trying to figure out what the dataTransmitted callback does.

Abhishek

Re: Need a simple example with (lib)USB

Posted: Thu Jul 05, 2012 6:15 pm
by Giovanni
About descriptors, so far I don't have a better idea in order to make them in an easier way, I considered structure but those are not portable because alignment and byte ordering issues.

The driver uses the requests callback to give the application a chance to handle EP0 messages before the driver, if you return FALSE the driver handles that message itself, if you return TRUE then the driver assumes your callback handled it (which is not true in your case apparently).

The data-received and data-transmitted callbacks are called when the data you requested/transmitted has been completely transferred, after the callback the driver is ready to accept more transfer commands. The best example of callbacks usage is serial_usb.c. Note that the driver is asynchronous, functions return immediately, the end of the operation is always signaled by a callback.

That the MSC demo is not complete. Please refer only to the various CDC demos.

Giovanni

Re: Need a simple example with (lib)USB

Posted: Fri Jul 06, 2012 2:07 pm
by Mathias

Code: Select all

receive message from device = hello USB!

Just as I tried to integrate a serial UART to debug the thing, I got this message.
Thanks everyone for their help, I will clean the code and share it in the examples forum.

*edit*
Here it is:
viewtopic.php?f=4&t=523