2014-04-14 12:30 AM
I am using STM32F407VGT6 microcontroller featuring 1 MB of Flash memory, 192 KB of RAM in my system which is having a usb connector.
End use is logging data into pendrive.I am using STM32_USB_HOST_Library mass storage class and FatFs Module Source Files R0.07e (C)ChaN, 2009, for this.Writing & reading data from pendrive is succefully working.But when connecting 16GB pendrive system becomes slow & restarted as WatchDog() function is enabled.It will be grateful if anybody can give me a solution in this issue. regardsGeorge2014-04-14 12:56 AM
Writing & reading data from pendrive is succefully working.But when connecting 16GB pendrive system becomes slow & restarted as WatchDog() function is enabled.
I would try instrumenting the code, and log the states. Shouldn't be too difficult to find out what is timing out. My guess - you are using a rather slow USB stick, where erase cycles take much longer (writing involves Flash block erase) than on others. The price differences for such USB sticks (of the same memory size) is not always totally unsubstantiated.
2014-05-02 01:51 AM
Hi fm
Thanks for your reply.I have used standard 16 GB pendrive of sandisk which costs about 10 US $.I have tested with other 16 GB pendrives also.The result is same ie system gets slow when it is connected to 16 GB pendrives.Is there any difference between 8 GB & 16 GB pendrives?I think memory allocation size for both are different.If so wheather it affects writing speed of data into it.Sorry for the delay in reply.It will be nice if somebody could help me solve this isssue.Thanks in advanceregardsGeorge2014-05-02 02:00 AM
Hi fm
Thanks for your reply.I have used standard 16 GB pendrive of sandisk which costs about 10 US $.I have tested with other 16 GB pendrives also.The result is same ie system gets slow when it is connected to 16 GB pendrives.Is there any difference between 8 GB & 16 GB pendrives?I think memory allocation size for both are different.If so wheather it affects writing speed of data into it.Sorry for the delay in reply.It will be nice if somebody could help me solve this isssue.Thanks in advanceregardsGeorge2014-05-02 06:23 AM
Yeah, as fm suggests you're going to want to instrument and benchmark the code to understand what's going on. Probably has more/larger clusters, and the erase blocks may be bigger. If it's been poorly formatted (from alignment perspective) this can have a very negative impact on performance.
What size of data are you writing? If you're writing a few dozen bytes here and there the performance is going to be awful. At a minimum try writing 8 KB blocks, 32 KB would probably be the best trade off. FatFs is generally pretty efficient, but you could implement caching, and lazy writer.2014-05-02 10:58 PM
Hi clive,
Three files are written into the USB in 1 Second.first two files are of size 1002 bytes and the third one of 8 bytes.Below shows the code for writing one file into USB.result = f_open(&file,PathString,FA_CREATE_ALWAYS |FA_WRITE); PrintFileSystemReturn(result); if(result == FR_OK) { f_write (&file, &(USBQ.q[DataIndex].AI1),((gDevice.NumberofSamples+1)*2),&bytesWritten); UARTprintf(gDevice.DebugFlag,''\n\r no of bytes=%d'',bytesWritten); f_close (&file); FileLock = FLAG_NOTSET; FileStoreAI1 = 1; } else { f_close (&file); FileStoreAI1 = 0; FileLock = FLAG_NOTSET; ErrorCallBack(); break; }Thanks in advanceRegardsGeorge2014-05-03 11:46 AM
The files itself are rather small, and are not an obvious reason for your problem.
However, you need to realize that writing to an USB stick (pen drive) is not a 'synchronous' operation. There is a controller 'in between' who takes USB packets, interprets them and reads/writes the attached Flash memory. First, there is some kind of caching involved, showing nonlinear behavior when exceeding internal (undisclosed) block sizes. And writing to Flash is about three to four orders of magnitude slower than reading. So once an actual Flash erase/write is required, delays increase drastically. Second, you can't expect two different pen drives from different suppliers to behave exactly the same way. Most probably, they use different controller chips, with different software, and different Flash chips. Your application just needs to deal with the worst case. If you can't figure it out by specification (if you can get hold of that at all), measure it by instrumenting your software.2014-05-03 02:16 PM
system gets slow when it is connected to 16 GB pendrives. Is there any difference between 8 GB & 16 GB pendrives?
Quantify ''gets slow'' in some unit of measurement I might understand. Yes, probably a lot. The memory devices may be slower/cheaper, as geometry shrinks in flash devices, they generally get slower and more unreliable. This may be further compounded by poor alignment of file system structures with respect to the erase block size (perhaps 128KB) but likely device dependent and hidden from direct inspection by the flash controller which makes the underlying NAND, wear leveling, ECC, and bad block management decisions. Are you seeing a lot of error, or time outs at the USB abstraction?