USB Host stack and driver for STM32

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: USB Host stack and driver for STM32

Post by mobyfab »

Hey,

Please let us know which license you are going to use, I would like to include these drivers in the contrib repo.

Fantastic work! :)
dismirlian
Posts: 65
Joined: Fri Dec 20, 2013 3:59 pm
Has thanked: 1 time
Been thanked: 16 times

Re: USB Host stack and driver for STM32

Post by dismirlian »

Hi mobyfab,

Thanks, good idea! I hadn't heard of the contrib repository.

I can use the same licenses as the ChibiOS HAL (just to be consistent with it). I'll post an updated version of every file tomorrow.

Diego.
User avatar
Giovanni
Site Admin
Posts: 14894
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: USB Host stack and driver for STM32

Post by Giovanni »

Hi,

If you put the code on the community repository then there are no restriction on licenses, you can keep copyright assigned to you. The only restriction is that you have to use a compatible license, Apache 2.0 and BSD are fine.

Giovanni
dismirlian
Posts: 65
Joined: Fri Dec 20, 2013 3:59 pm
Has thanked: 1 time
Been thanked: 16 times

Re: USB Host stack and driver for STM32

Post by dismirlian »

Hi,

I attach a new version of the USB host stack and drivers. The license of the files is now the Apache license.

There is a new driver for FTDI chips. The driver should work with (almost) all models in full speed; tested with FT232RL- and FT232BM-based USB-serial converters. The driver saturates the FTDI chip in TX mode (3Mbps is the maximum baudrate for these ICs), but I haven't tested the throughput in RX mode. The driver demonstrates the use of the asynchronous API (in this case, using Bulk endpoints), and exposes a ChibiOS AsynchronousChannel, so it can be used just as a normal serial port.

The (still untested) demo includes an FTDI driver example (opens up a shell using the USB-serial port, where you can type commands, etc), as well as the Mass Storage demo.

Here is the shell running using a USB-serial converter (STM32F207 120MHz, -O0, checks enabled):

Code: Select all

ChibiOS/RT Shell
ch>
ch>
ch> help
Commands: help exit info systime mem threads test write
ch> info
Kernel:       3.1.0
Compiler:     GCC 4.9.3 20141119 (release) [ARM/embedded-4_9-branch revision 218278]
Architecture: ARMv7-M
Core Variant: Cortex-M3
Port Info:    Advanced kernel mode
Platform:     STM32F407 High Performance
Board:        Test
Build time:   Nov 23 2015 - 17:57:17
ch> test

*** ChibiOS/RT test suite
***
*** Kernel:       3.1.0
*** Compiled:     Nov 23 2015 - 17:57:30
*** Compiler:     GCC 4.9.3 20141119 (release) [ARM/embedded-4_9-branch revision 218278]
*** Architecture: ARMv7-M
*** Core Variant: Cortex-M3
*** Port Info:    Advanced kernel mode
*** Platform:     STM32F407 High Performance
*** Test Board:   Test

----------------------------------------------------------------------------
--- Test Case 1.1 (System, critical zones)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 1.2 (System, interrupts handling)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 1.3 (System, integrity)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 2.1 (Threads, enqueuing test #1)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 2.2 (Threads, enqueuing test #2)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 2.3 (Threads, priority change)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 2.4 (Threads, delays)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 3.1 (Semaphores, enqueuing)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 3.2 (Semaphores, timeout)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 3.3 (Semaphores, atomic signal-wait)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 3.4 (Binary Semaphores, functionality)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 4.1 (Mutexes, priority enqueuing test)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 4.2 (Mutexes, priority return)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 4.3 (Mutexes, status)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 4.4 (CondVar, signal test)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 4.5 (CondVar, broadcast test)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 4.6 (CondVar, boost test)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 5.1 (Messages, loop)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 6.1 (Mailboxes, queuing and timeouts)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 7.1 (Events, registration and dispatch)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 7.2 (Events, wait and broadcast)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 7.3 (Events, timeouts)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 8.1 (Heap, allocation and fragmentation test)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 9.1 (Memory Pools, queue/dequeue)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 10.1 (Dynamic APIs, threads creation from heap)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 10.2 (Dynamic APIs, threads creation from memory pool)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 10.3 (Dynamic APIs, registry and references)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 11.1 (Queues, input queues)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 11.2 (Queues, output queues)
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 12.1 (Benchmark, messages #1)
--- Score : 175731 msgs/S, 351462 ctxswc/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 12.2 (Benchmark, messages #2)
--- Score : 150786 msgs/S, 301572 ctxswc/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 12.3 (Benchmark, messages #3)
--- Score : 150786 msgs/S, 301572 ctxswc/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 12.4 (Benchmark, context switch)
--- Score : 797128 ctxswc/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 12.5 (Benchmark, threads, full cycle)
--- Score : 44167 threads/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 12.6 (Benchmark, threads, create only)
--- Score : 51308 threads/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 12.7 (Benchmark, mass reschedule, 5 threads)
--- Score : 56540 reschedules/S, 339240 ctxswc/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 12.8 (Benchmark, round robin context switching)
--- Score : 401460 ctxswc/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 12.9 (Benchmark, I/O Queues throughput)
--- Score : 443460 bytes/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 12.10 (Benchmark, virtual timers set/reset)
--- Score : 581258 timers/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 12.11 (Benchmark, semaphores wait/signal)
--- Score : 464264 wait+signal/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 12.12 (Benchmark, mutexes lock/unlock)
--- Score : 401516 lock+unlock/S
--- Result: SUCCESS
----------------------------------------------------------------------------
--- Test Case 12.13 (Benchmark, RAM footprint)
--- System: 360 bytes
--- Thread: 72 bytes
--- Timer : 20 bytes
--- Semaph: 12 bytes
--- EventS: 4 bytes
--- EventL: 20 bytes
--- Mutex : 16 bytes
--- CondV.: 8 bytes
--- Queue : 36 bytes
--- MailB.: 40 bytes
--- Result: SUCCESS
----------------------------------------------------------------------------

Final result: SUCCESS
ch>


It passes! :shock:

Here is the Mass Storage test (STM32F207 120MHz, -O2, checks and asserts disabled):

Code: Select all

16383.000     HPRT: Port connection detected
16383.000  Port 1 connected, wait debounce...
16383.000  Try reset...
16383.002     HPRT: Port enabled
00019.003  Reset OK, recovery...
00119.001     DEV[CTRL]: Open EP
00119.015  Enumerate.
00119.019  Get first 8 bytes of device descriptor
00119.204  Configure bMaxPacketSize0 = 64
00119.224     DEV[CTRL]: Closing EP...
00119.239     DEV[CTRL]: Closed
00119.254     DEV[CTRL]: Open EP
00119.269  Set device address: 1
00119.521     DEV[CTRL]: Closing EP...
00119.537     DEV[CTRL]: Closed
00119.554     DEV[CTRL]: Open EP
00119.569  Wait stabilization...
00138.998  Get full device desc
00139.096  Enumeration finished.
00139.109  Loading langID0...
00139.299  langID0=0409
00139.311  Device has only one configuration
00139.319  Reading basic configuration descriptor 0
00139.538  Selecting configuration 0
00139.632  Device configured.
00139.641  New device found.
00139.646  ----- Device info -----
00139.652  Device descriptor:
00139.658     USBSpec=0200, #configurations=1, langID0=0409
00139.687     Class=00, Subclass=00, Protocol=00
00139.708     VID=AAAA, PID=8816, Release=1308
00139.807     Manufacturer: MXTronics
00139.910     Product: MXT USB Device
00140.056     Serial Number: 130818v01
00140.074  Configuration descriptor (partial):
00140.083     bConfigurationValue=1, Length=32, #interfaces=1
00140.109     Current=100mA
00140.123     SelfPowered=0, RemoteWakeup=0
00140.142     Name:
00140.150  ----- End Device info -----
00140.242  ----- Configuration info -----
00140.252  Configuration descriptor:
00140.259  Configuration 1, #IFs=1
00140.276    Interface 0, alt=0, #EPs=2, Class=08, Subclass=06, Protocol=50
00140.316      Endpoint descriptor, Address=01, Type=2, MaxPacket=64, Interval=0
00140.355      Endpoint descriptor, Address=81, Type=2, MaxPacket=64, Interval=0
00140.395  ----- End Configuration info -----
00140.404  Load a driver for each IF.
00140.413  Try load driver MSD
00140.430  BULK OUT endpoint found: bEndpointAddress=01
00140.455  BULK IN endpoint found: bEndpointAddress=81
00140.483  Reading Max LUN:
00140.551     max_lun = 1
00140.562     MSD[BIN ]: Open EP
00140.575     MSD[BOUT]: Open EP
00140.589  INQUIRY...
00140.735     PDT=00
00140.744  READ CAPACITY(10)...
00140.863     Block size=512bytes, blocks=3862528 (~1886 MB)
00140.892  TEST UNIT READY...
00141.039     TEST UNIT READY: Command Failed
00141.168     REQUEST SENSE: Sense key=6, ASC=28, ASCQ=00
00141.193  TEST UNIT READY...
00141.282     TEST UNIT READY: Command Failed
00141.410     REQUEST SENSE: Sense key=6, ASC=28, ASCQ=00
00141.438  TEST UNIT READY...
00141.522     Ready.
00141.526  MSD Connected.
00165.001  BLK: Raw read test (1MB, 10240B blocks)
01048.567  BLK: Raw read in 883 ms, 1159kB/s
01048.588  FS: Block driver ready, try mount...
01050.700  FS: Mounted.
01192.902  FS: 60227 free clusters, 64 sectors per cluster, 1973518336 bytes free
01192.940  FS: Write test (create file /test.dat, 1MB)
02664.489  FS: Written 1MB in 1451 ms, 705kB/s
02686.669  FS: Read test (read file /test.dat, 1MB, compare)
03902.883  FS: Read 1MB in 1216 ms, 842kB/s
03902.905  FS: Scan files test
03903.884  FS: /TEST.DAT
03905.047  FS: /MEDIA.TXT
03905.620  FS: /MT411.FW
03905.644  FS: /UPDATE~2.FW
03906.267  FS: /CONFIG~2.TXT
03906.287  FS: /CONFIG.TXT
03906.305  FS: /UPDATE~1.FW
03906.324  FS: /UPDATE.FW
03906.339  FS: Tests done, restarting in 3s


Also, there are some bug corrections, and some minor API changes.

Thanks,
Diego.
Attachments
RT-STM32F407-DISCOVERY-usbh.zip
USB Host stack (F407 Discovery test)
(133.38 KiB) Downloaded 744 times
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: USB Host stack and driver for STM32

Post by mobyfab »

Thanks a lot!

I am working on merging this to the contrib repo. (https://github.com/ChibiOS/ChibiOS-Contrib)

In the meanwhile it is available in my fork: https://github.com/fpoussin/ChibiOS-Contrib
I haven't done any tests yet, and I still need to make some cleaning.
dismirlian
Posts: 65
Joined: Fri Dec 20, 2013 3:59 pm
Has thanked: 1 time
Been thanked: 16 times

Re: USB Host stack and driver for STM32

Post by dismirlian »

Hi mobyfab,

Thanks for taking the time to do this! For the upcoming bug fixes and updates, I could follow the format and directory layout you propose. I have never used GitHub nor git, but if I sign up I can make the changes in my repository and then you could merge directly to the contrib repository, am I right? Or do you prefer me to keep posting the zipped files here?

Thanks!
Diego
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: USB Host stack and driver for STM32

Post by mobyfab »

Hi Diego,

If you could make some tests using the code I merged to my repo first that would help me a lot.
You probably have to change the example code a bit as it's make for the F4 discovery board. (unless you have one too)

The easiest solution for future updates/fixes is to work from the same code base: the contrib repo on github.
You can make changes, commit and push them to your fork, then make a "pull request" to merge them to the contrib repo. So yes you are right.
dismirlian
Posts: 65
Joined: Fri Dec 20, 2013 3:59 pm
Has thanked: 1 time
Been thanked: 16 times

Re: USB Host stack and driver for STM32

Post by dismirlian »

Hi mobyfab,

No problem, I can make some tests using your repo. I'll probably be doing this the next week, because I have some pressing matters at work. I don't have a F4 discovery board, only two custom boards (F207 and F411). I'll make the necessary modifications and test the driver.

Ok, so I should learn the git jargon :?...

A+,
Diego.
chibby
Posts: 66
Joined: Wed Oct 22, 2014 11:20 am

Re: USB Host stack and driver for STM32

Post by chibby »

Hi Diago, Mobyfab.

I have finally got back to looking at this. I still have cvs pull from 7th Nov. and the usbh zip file above. Is that still current?

I have added MAX3232 to the f407-Discovery which I have to run the demo. I also have a F4iiRE board.

The (still untested) demo includes an FTDI driver example (opens up a shell using the USB-serial port, where you can type commands, etc), as well as the Mass Storage demo.


What is this driver for? Is it intended to connect the USART via RS232 level converter into a DB9 to USB-A cable with built-in FDTI chip, then test the OTG port on the board, while keeping the STLINK dedicated to flashing and hardware debugging?

The (still untested) demo includes an FTDI driver example (opens up a shell using the USB-serial port, where you can type commands, etc),

I initially thought this was intended to run on a true RS232 COM port on a desktop PC.

Thanks for any clarifications of what this is intended to do and in what hardware configuration. Is it now tested?
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: USB Host stack and driver for STM32

Post by mobyfab »

Hey,

The most up to date code is from Nov 25th.
This has not been tested yet, I will try to find some time for it. ;)

The USART/RS232 stuff has nothing to do with this driver (or any software).

It is a host driver, that means you can use an FTDI serial to USB interface/cable and use it just like you would on a computer, standalone.
Post Reply