example interfacing a STM32F4 with libusb

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
kjellhar
Posts: 39
Joined: Sun Jul 08, 2012 10:44 pm

Re: example interfacing a STM32F4 with libusb

Post by kjellhar »

Mathias wrote:The sighandler wasn't really that helpfull anyways. What exactly fails on your mac? Didn't it compile or did it crash on runtime? Finding a proper solution shutting down the program is still on my todo list.


Nah, I it didn't solve anything after all. On my Mac, the app froze when I tried to terminate it. With the debug option on, it always failed, but with the debug options off, it some times terminated ok. If I remove the handler, the app will terminate with Ctrl-C, but I'm not sure if it will release the USB device.

Mathias wrote:And I'd say the same thing about this project. Its not hard to understand what I'm doing there, but since this is my first coding on any uC and the first time I do anything with USB, it was quite a learning curve for me. But I can say, I learned a lot about it.


I spent many long hours on my first time around. As you say, it's a really steep curve. And even then, I don't know that much about USB, I only skimmed the surface and got something working.

Mathias wrote:Also if anyone has tips to improve the speed...


Have you benchmarked it? If so, what results did you get. On my AVR32 project, I managed to get around 1 and 1.2 MByte/sec i memory serves me. That was on a FS connection (12Mbps) to a Win7 machine.
Mathias
Posts: 43
Joined: Thu Jun 28, 2012 6:19 pm

Re: example interfacing a STM32F4 with libusb

Post by Mathias »

I can push around 1000 packets a second, but they only have 64 bytes payload. If I knew the specs that would probably point me into the right direction. I read so many contradictory statements about the specs... maybe I should start reading the specs from the standard.
*edit* I started reading the specs: It seems I have to send more then one packet per frame...
kjellhar
Posts: 39
Joined: Sun Jul 08, 2012 10:44 pm

Re: example interfacing a STM32F4 with libusb

Post by kjellhar »

Mathias wrote:I can push around 1000 packets a second, but they only have 64 bytes payload. If I knew the specs that would probably point me into the right direction. I read so many contradictory statements about the specs... maybe I should start reading the specs from the standard.
*edit* I started reading the specs: It seems I have to send more then one packet per frame...


Just from memory, I think each frame is 1ms, which fits well with your 1000packets/s. So yes, more packets per frame would do the trick. Didn't think you had to do anything special to make that happen. Are you waiting for the SOF somewhere? I couldn't find it just skimming through the code.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: example interfacing a STM32F4 with libusb

Post by Giovanni »

The "xxxObjectInit" functions initializes object instances, look at them as object constructors, some driver instantiate objects in xxxInit() because the objects are tied to a specific HW resource, for example SPID1, SPID2 etc.

The SDU driver (and some others like MMC_SPI) is not linked to a specific HW resource so the object initialization is left to the application.

Giovanni
Mathias
Posts: 43
Joined: Thu Jun 28, 2012 6:19 pm

Re: example interfacing a STM32F4 with libusb

Post by Mathias »

Giovanni,

does the USB driver support more then one transaction per frame? I tested the USB-CDC driver and got exactly 64kb/s.
Or do I have some general problems?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: example interfacing a STM32F4 with libusb

Post by Giovanni »

The driver needs optimizations for sure, if you are using the Serial over USB driver you may try to make its queues larger and see if the situation improves, it should enable more packets per frame (I haven' tested it yet in that situation, I would need some kind of benchmark before attempting improvements).

Giovanni
Mathias
Posts: 43
Joined: Thu Jun 28, 2012 6:19 pm

Re: example interfacing a STM32F4 with libusb

Post by Mathias »

I tried to raise SERIAL_BUFFERS_SIZE in halconf.h up to 2048, I write to the queues with 256 bytes per write, all I get is 64kb/s or do you mean another queue?

Also: When I do
uint8_t transferBuf[IN_PACKETSIZE*8];
[...]
usbPrepareTransmit(usbp, EP_IN, transferBuf, IN_PACKETSIZE*8);
usbStartTransmitI(usbp, EP_IN);

8 packets are transferred correctly, but still only 1 per frame, thus the speed still doesn't increase.

Also I wonder if its normal that only STM32/USBv1/usb_lld.c is compiled and not STM32/USBv1/usb_lld.c ? Maybe thats the problem?

And what kind of benchmark do you need? Just a simple "push as many bytes possible on the hardware, count how much arrives"? Just replace the main loop in the USB_CDC example with this:
http://pastebin.com/ZPtQq2VK
and do something like:

Code: Select all

$ dd if=/dev/ttyACM0 of=/dev/null count=1000

It will receive 1000 packets and tell you the bandwidth.

*edit* A sidenote: I know that most of this code is not even in a development release. So you can say "shut up and wait for a release" anytime you want.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: example interfacing a STM32F4 with libusb

Post by Giovanni »

No problem, it is good to discuss the issues.

I meant that queue, probably there is another limit into the driver. The USBv1 driver does not implement double buffering which is supported by the HW, probably double buffering would solve this limit.

One possible workaround is to increase the packet size of data endpoints, if I remember well bigger packet buffers are allowed.

Giovanni
Mathias
Posts: 43
Joined: Thu Jun 28, 2012 6:19 pm

Re: example interfacing a STM32F4 with libusb

Post by Mathias »

The specs limits Full-Speed Bulk EPs to 64bytes packet sizes. High Speed has a limit of 512 byte packets.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: example interfacing a STM32F4 with libusb

Post by Giovanni »

Then the only option is to implement that double buffering mode in the driver (I would not complain if somebody is willing to give it a try :)).

Giovanni
Post Reply