cancel
Showing results for 
Search instead for 
Did you mean: 

Where to start developing usb firmware?

Mohammad A
Senior
Posted on January 20, 2018 at 14:55

I need to develop an isochronous type USB firmware to transmit real time data to computer, but I dont know where to start. My question is What book/article/blog is enough to read to start developing a usb firmware over stm32

P.S: I'm not really familiar with USB specifications. But I want to know what is really required to learn to develop a new firmware. I know there are documents about usb specifications but I think those are overkill as some functions are already handled by hardware and HAL

#usb #stm32
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on January 21, 2018 at 09:49

Then an UVC class device might be the way to go. By googling i found this 

https://github.com/iliasam/STM32F4_UVC_Camera

. I never tried it, but it seems to have an UVC class with isochronous transfer. Maybe try that?

View solution in original post

8 REPLIES 8
Mario Popovic
Associate III
Posted on January 20, 2018 at 15:33

USB can be very tricky to comprehend. A good place to start is 

http://www.beyondlogic.org/usbnutshell/usb1.shtml#Introduction

. Apart from that you could read USB specification,  but that is not so light reading. There is no, to my knowledge easy tutorial for the USB for the beginners. The best thing to do is just take some basic USB code and debug it.

Unlike UART or SPI or CAN, the USB has a lot of things on the low level that need to be done just to send a couple of bytes of data. Fortunately some of them are generated by CubeMX automatically.

There a few key parts of USB protocol.

1. USB Descriptors - these are data structures that describe how the device is implemented (how many interfaces it has, how many configurations, USB classes of the interfaces, etc.)

2. Endpoints - these are virtual channels for sending and receiving data to and from the device. Depending on the class of the device there can be 1 or more endpoints assigned to it.

3. Device classes - There are some standard device classes such as Mass Storage, CDC (Virtual Com Port), Audio Class etc., that help the host to find appropriate driver and in most cases the host can just use the generic driver, ie. the Mass Storage Class device can be automatically recognized and used without any special driver

4. Host driver - Every device should have compatible driver on the host side, which can be problem when writing your own device class

That being said, why do you need isochronous device? Unless you are making a Video or Audio device, thera are nott many host drivers that support isochronous transfer which means you would need to write your own host driver.

My suggestion is to start small with CDC class driver generated from cube and continue from there.

Regards

Posted on January 20, 2018 at 15:57

It is a multi-faceted problem. It is important to understand the protocol and expectations first. Application to a specific architecture will make a lot more sense in that context.

Jan Axelson has written numerous books on the topic, and might provide an overview from which you can expand on.

http://janaxelson.com/usb.htm

 

My approach to these things is to read/skim multiple perspectives, and then triangulate. Then walk the code examples and if the behaviour expressed doesn't make sense go back to the books and get a better understanding. Look also at Linux USB stack and drivers to understand how the OS expects USB devices to behave and present data/descriptors.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on January 20, 2018 at 16:52

Referring to the

Turvey.Clive.002

suggestion to start with the Linux.

Some time ago when I started playing with USB I used the following lib:

http://libusb.info/

I used it for Linux to connect USB temperature sensor.

Posted on January 20, 2018 at 18:26

Thanks for reply.

Yes, as you may have suggested I am developing a Video device which in a part of it is required to send a stream of video to computer. At the moment this requirement is implemented using CDC, but this class is not suitable as it is based on bulk transfers.

So, I think that I have to develop a class as CubeMX does not provide it.

Posted on January 20, 2018 at 18:30

is it possible to use libusb to write a new computer side firmware/driver to make CDC suitable for Video streaming application?

Posted on January 20, 2018 at 19:34

openMV uses CDC over USB-FS which is not a big deal (I already have implemented that). The problem is using CDC over USB-HS when it streams 50 fps uncompressed data (each frame is about 200KB in grayscale and 400KB in YCrCb format.)

Posted on January 21, 2018 at 09:49

Then an UVC class device might be the way to go. By googling i found this 

https://github.com/iliasam/STM32F4_UVC_Camera

. I never tried it, but it seems to have an UVC class with isochronous transfer. Maybe try that?