USB Host stack and driver for STM32

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

Moderator: RoccoMarco

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,

How did you perform the test with the 512-byte blocks? Your results:

Code: Select all

FS: Write test (create file /test.dat, 1MB)
FS: Written 1MB in 1185 ms, 864kB/s
FS: Read test (read file /test.dat, 1MB, compare)
FS: Read 1MB in 1057 ms, 968kB/s


show that the write speed is 864kB/s using FatFS, which usually uses 512 byte sectors... Am I wrong?

Diego.
king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

Re: USB Host stack and driver for STM32

Post by king2 »

I have reduced quantity of repetitions in for statement down to 256, and increased buffer size when calling f_write to 4096, so it is still 1M of size. In default test, with 2048 times of 512 blocks, I got 230Kb/s only.
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 »

Ok, but internally FatFS uses 512 byte sectors, independent of the parameter passed to f_write. Check _MAX_SS in ffconf.h.

Diego.
king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

Re: USB Host stack and driver for STM32

Post by king2 »

512/512 - default values.
king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

Re: USB Host stack and driver for STM32

Post by king2 »

I have changed reads capacity and test unit ready.
USB stick now recognized successfully, but sometimes:

Code: Select all

00157.273  Load a driver for each IF.
00157.285  Try load driver MSD
00157.311  BULK IN endpoint found: bEndpointAddress=81
00157.362  BULK OUT endpoint found: bEndpointAddress=02
00157.404  Reading Max LUN:
00158.433       max_lun = 1
00158.453       MSD[BIN ]: Open EP
00158.488       MSD[BOUT]: Open EP
00158.518  INQUIRY...
00159.724       PDT=00
00159.739  TEST UNIT READY...
00159.906       TEST UNIT READY: Command Failed
01371.478       REQUEST SENSE: Sense key=6, ASC=28, ASCQ=00
01371.522  TEST UNIT READY...
01372.076       Ready.
01372.082  READ CAPACITY(10)...
01375.161       Block size=512bytes, blocks=15130624 (~7388 MB)
01375.208  MSD Connected.


Speeds:

Code: Select all

BLK: Raw read test (1MB, 10240B blocks)
BLK: Raw read in 1084 ms, 944kB/s
FS: Block driver ready, try mount...
FS: Mounted.
FS: 472083 free clusters, 32 sectors per cluster, 3439640576 bytes free
FS: Write test (create file /test.dat, 1MB)
FS: Written 1MB in 3415 ms, 299kB/s
FS: Read test (read file /test.dat, 1MB, compare)
FS: Read 1MB in 1431 ms, 715kB/s
FS: Tests done, restarting in 3s

This is with 4096 bytes blocks.
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 King2,

This:

Code: Select all

00159.739  TEST UNIT READY...
00159.906       TEST UNIT READY: Command Failed
01371.478       REQUEST SENSE: Sense key=6, ASC=28, ASCQ=00
01371.522  TEST UNIT READY...
01372.076       Ready.


is completely normal; TEST UNIT READY fails until the USB stick is ready (check the sense key code table).

I think the speeds are also normal. You can check the maximum speed using a PC, connecting the USB stick through a *full speed*
USB hub.

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 King,

Did you fork my repo ChibiOS-Contrib on github?
If so, you can send me a pull request to merge the changes.

I have no time to check each source file and do it manually for now.

Thanks
king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

Re: USB Host stack and driver for STM32

Post by king2 »

mobyfab, I did not forked repo, but I can make a diff for you (or make a fork, if it will more suitable for you). But this is useless, you cannot just apply changes.

My modifications:
1. changed list.h, and all places where macros from it was called, but in MSD and main sources. Changes can be applied directly, but it is needed to change same way sources for rest of drivers.

2. alignment and defining buffers. was changed by adding #pragma data_alignment and removing GCC macro, so this cannot be applied as is, checking for compiler needed. Also, I'm not sure that I did it right way (yes, it works, but may this is my luck?)

3. packed structures. Defining structs was changed in many places, and again, it is needed to add compiler checks there.

Sorry, but my patches is just a test now, not ready-to-repo sources, and I do not know how to make it right to be included in repo. Some checking and changed are needed..

I will try to make all I can with sources, and then I will fork repo and will make push request. But I do not know if I will able to get it roght way.
king2
Posts: 98
Joined: Mon May 28, 2012 1:57 pm
Been thanked: 2 times

Re: USB Host stack and driver for STM32

Post by king2 »

I took fresh repo and made my changes one more time, to get more accurate results.
Then I made pull request to main repo:
- changed list.h to eliminate using of typeof(), changed all calls in sources
- removed aligning in IAR due to automatic align(4) in IAR (except one place where aligning was added by two-bytes variable)
- changed GCC's atrribute packed to ChibiOS's PACKED_VAR
- now TEST UNIT READY placed before READ CAPACITY as dismirlian suggested
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 »

Merged, thanks a lot!
Post Reply