cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F107 and USB Lib Mass Storage Device Speed Issue

louis
Associate II
Posted on November 18, 2013 at 15:54

Hi,

I am using the STM3210C-Eval board and the STM32_USB-Host-Device_Lib_V2.1.0 Host MSD example.

It is working i.e it reads and writes to disk but it is slow. I need to make / save a 2 Mbyte file on the USB.

The code section is :- usbh_usr.c // I modified the source to write bigger file

bytesToWrite = 512;

      

      for(nLinesToWrite=0;nLinesToWrite<4000;nLinesToWrite++){

                    

        res= f_write (&file, writeTextBuff, bytesToWrite, (void *)&bytesWritten);   

           

        if((bytesWritten == 0) || (res != FR_OK)) /*EOF or Error*/

          {

          TerminalWriteString(''Error Writing file \r\n'');

          }

      

      }

It does work ( It writes a file to the USB drive ) but takes between 12 and 18 seconds to write. the USB drive I am using came with the kit and on a windows PC it writes the same size ( 2 MByte ) file under 1 second.

When I send a line count to a RS232 terminal it tends to run for approx. 256 lines ( nLinesToWrite ) and then stall, then run again and stall. The stall time is approx. 0.25 to 0.5 seconds.

The 256 is not fixed and does vary. 

It is like the system is erasing flash sectors but why so slow compared to a PC?

Is this a problem with the USB lib?

Are there better / faster USB lib's out there?

Any help appreciated.

Thanks,

Louis

#stm32f-usb
6 REPLIES 6
Posted on November 18, 2013 at 17:07

The NAND Flash on the USB drive likely has 128KB blocks, writing more than 512 bytes, and closer to 32KB might help. Not sure anything on the 107 is going to be particularly rapid (72 vs 2500-3500 MHz, and a GB of caching, USB 2.0 HS).

Thought about SDIO?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
louis
Associate II
Posted on November 18, 2013 at 17:36

Hi Clive,

Thank you so much for your fast response. I did the 32K block as you suggested and it now does it in approx. 1 second ( Was 12 seconds ). We needed it down below 5 seconds so happy days.

Thanks Again,

Louis

louis
Associate II
Posted on November 19, 2013 at 10:03

Sorry... Should clarify...

The approx. one second ( actually 1.5 seconds ) was for the STM3220G-Eval board using the High Speed USB Interface. 

For Reference if you are doing something similar

On the STM32F107 it is about 4.5 seconds for 2MByte file save( Full speed USB Interface )

On the STM32F207 it is about 3.5 seconds for 2MByte file save( Full speed USB Interface )

Louis

89maninder
Associate II
Posted on June 17, 2015 at 15:34

hi clive1....

i am using STM32_USB-Host-Device_Lib_V2.1.0.... in stm32f205vgt6. i trying to write data in 4GB pendrive. so after writing around 30MB data, the program get stuck in do-while loop in disk read() / disk write() function in usbh_msc_fatfs.c. I did debugging and found that whenever program is stuck there, the URB_Status in USBH_MSC_BOTXfer() is not updating and always keeping as URB_Idle.  

I read on other forums that, people had similar issues but it resolved by changing the otg interrupt priority to higher level. I did same, but problem is not resolved. 

so made a logic that if program gets stuck in do-while loop, then break the loop and reset USB module, it worked, but after few resets, after enumeration, the URB_Status in USBH_MSC_BOTXfer() is updated as URB_Notready.

can you help in this case.????
Posted on June 17, 2015 at 16:56

can you help in this case.????

Probably not. You'd want to take a look at what exactly is happening with a USB analyzer, or sufficiently instrument your code and it's interaction with the bus. Stepping around in the debugger probably not going to give you the insight you want, and will disturb the timing/interaction.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
89maninder
Associate II
Posted on June 18, 2015 at 15:10

well thanksfor quick reply....

i kept some delay after write operation (2 millisecond ), with this the performance improved... Now i was able to write more than 100MB. 

the maximum number of endpoints in source code was defined as 3, i changed it to 7(as i read it somewhere). now after this i have written 900MB.... but the problem is still there..... the program still stucks in BOT state machine as i told you earlier...

what can be the impact of changing the maximum number of endpoints??

also in what direction i should work, to sort out this issue.... ??