[STM32GENERIC] SDIO DMA

Discussions about the STM32generic core
ag123
Posts: 696
Joined: Thu Jul 21, 2016 4:24 pm

Re: [STM32GENERIC] SDIO DMA

Post by ag123 » Fri May 19, 2017 1:56 pm

ok i'm joining the 'testing' game :lol:
that black f407vet6 has a nice uSD slot that has a spring in it, click in & click out, using that slot for the test :mrgreen:
http://i.ebayimg.com/images/g/58cAAOSw4 ... -l1600.jpg
using pito's binary, black f407vet6, 5 MB test_in.bin file,
SD card is a 16GB Strongtium brand card class 10
http://www.strontium.biz/products/memor ... ory-cards/

Code: Select all

Use a freshly formatted SD for best performance.                  
Type any character to start                                       
                                                                  
*************************************************
Opening the read file..
Opening the write file..
Reading and Writing..
*************************************************
Done in 1922 msecs

Code: Select all

>ls -l
-rw-r--r-- 1 ag123 users 5175858 May 19 21:51 test_in.bin
-rw-r--r-- 1 ag123 users 5175858 Jan  1  2000 test_out.bin
> md5sum test*bin
be7f63802ba5b5beb4267d2fa31d2761  test_in.bin
be7f63802ba5b5beb4267d2fa31d2761  test_out.bin
oops need to fix my RTC maybe :) file created using:

Code: Select all

dd if=/dev/random of=test_in.bin bs=512 count=65535
5175858 * 2 / 1.922 ~ 5385908 bytes / s (read + write) - divide by 1024 ~ 5259.67 kbytes/s (read + write, i.e. copy)

u've got a binary that times the reads & writes separately? :)

more test 100 meg test file, failed with errors

Code: Select all

*************************************************
Opening the read file..
Opening the write file..
Reading and Writing..
HAL_SD_WriteBlocks Error: 5
HAL_SD_WriteBlocks Error: 5
HAL_SD_WriteBlocks Error: 3
HAL_SD_WriteBlocks Error: 3
HAL_SD_WriteBlocks Error: 3
HAL_SD_WriteBlocks Error: 3
HAL_SD_WriteBlocks Error: 3
HAL_SD_WriteBlocks Error: 3
HAL_SD_WriteBlocks Error: 3
HAL_SD_WriteBlocks Error: 3
HAL_SD_WriteBlocks Error: 16
HAL_SD_WriteBlocks Error: 5
HAL_SD_WriteBlocks Error: 5
*************************************************
Done in 37920 msecs

Code: Select all

>md5sum test*bin
640765a33e578089de8bd9052d056c1e  test_in.bin
a62c9b1c6c8853bf8a6e605b7a8d1665  test_out.bin
>ls -l *bin
-rw-r--r-- 1 ag123 users 102400000 May 19 22:52 test_in.bin
-rw-r--r-- 1 ag123 users 102498304 Jan  1  2000 test_out.bin
102400000 * 2 / 37.920 ~ 5400843 B / s- divide by 1024 ~ 5274.26 KB/s
Last edited by ag123 on Tue May 23, 2017 3:18 pm, edited 1 time in total.

User avatar
Pito
Posts: 1390
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32GENERIC] SDIO DMA

Post by Pito » Fri May 19, 2017 3:25 pm

Great! So typical errors are 2, 3, 5, 16.
Pukao Hats Cleaning Services Ltd.

ag123
Posts: 696
Joined: Thu Jul 21, 2016 4:24 pm

Re: [STM32GENERIC] SDIO DMA

Post by ag123 » Fri May 19, 2017 3:28 pm

i'm not sure if a 'complain' about the hardware SDIO say on ST's forum may point us to better clues as to how to fix it? it certainly won't look good on st to say that stm32f4 has hardware sdio but doesn't work or work with errors, no one would dare use it for anything serious and may corrupt whole gigabytes sd cards :lol:

victor_pv
Posts: 1483
Joined: Mon Apr 27, 2015 12:12 pm

Re: [STM32GENERIC] SDIO DMA

Post by victor_pv » Fri May 19, 2017 3:58 pm

I'm in the process of updating the SDIO library to the latest HAL as updated by Daniel in the FW_Update branch.

Currently DMA reads working fine, but some errors in writes, I believe timeouts due to the card taking its sweet time to write the blocks. I'm trying to add code to wait until the card is at least past the programming stage.
I think the way the HAL manages the sdcard makes more sense in the new API, we will see if it helps with reliability.

victor_pv
Posts: 1483
Joined: Mon Apr 27, 2015 12:12 pm

Re: [STM32GENERIC] SDIO DMA

Post by victor_pv » Fri May 19, 2017 4:00 pm

ag123 wrote:i'm not sure if a 'complain' about the hardware SDIO say on ST's forum may point us to better clues as to how to fix it? it certainly won't look good on st to say that stm32f4 has hardware sdio but doesn't work or work with errors, no one would dare use it for anything serious and may corrupt whole gigabytes sd cards :lol:
STM updated the SDIO HAL in the April release, just a month ago, so I would hold before complaining until we have fully tested the new version.
There was all kind of complains of the issues in the previous version in different forums, in all my searches I only found post advising to try this and that avoid this or that error, but not one post saying if you use this code it works 100%.

ag123
Posts: 696
Joined: Thu Jul 21, 2016 4:24 pm

Re: [STM32GENERIC] SDIO DMA

Post by ag123 » Fri May 19, 2017 4:04 pm

one trouble is that the sdio specs is pretty much non public, that'd make it somewhat harder to figure out the errors. we'd perhaps need go 'google' for it perhaps on some other forums avr, intel and say even on the arm app cores (raspberry pi, beagle bone black, etc) for some of the answers ;)

some scraps of info may be found in various places
http://www.digitalspirit.org/file/index ... 33-001.pdf
https://yannik520.github.io/sdio.html

stevestrong
Posts: 1450
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: [STM32GENERIC] SDIO DMA

Post by stevestrong » Fri May 19, 2017 4:16 pm

why not trying to copy the ESP8266 Teensy driver of the SdFat beta lib?

victor_pv
Posts: 1483
Joined: Mon Apr 27, 2015 12:12 pm

Re: [STM32GENERIC] SDIO DMA

Post by victor_pv » Fri May 19, 2017 4:34 pm

stevestrong wrote:why not trying to copy the ESP8266 Teensy driver of the SdFat beta lib?
The teensy driver is HW specific, accessing the registers for the SDIO and DMA devices directly.
We are copying how the main functions should behave though, but trying to use the HAL in our case so it's easier to port between series.

Now, first results with the Class 4 card, 25Mhz, 4bit wide, F407VET, FW_Update core brach, 32KB buffer:

Code: Select all

Manufacturer ID: 0X27
OEM ID: PH
Product: SD04G 
Version: 3.0 
Serial number: 0X155FF97C
Manufacturing date: 9/2011 

File size 5 MB 
Buffer size 32768 bytes 
Starting write test, please wait. 
 
write speed and latency 
speed,max,min,avg 
KB/Sec,usec,usec,usec 
2432.00,702963,3575,13388 
1734.24,755199,3576,18844 
 
Starting read test, please wait. 
 
read speed and latency 
speed,max,min,avg 
KB/Sec,usec,usec,usec 
8470.64,4599,3667,3865
8485.07,4655,3601,3865 
 
Done 
Type any character to start 
I still need to do some tuning in the functions so the timeouts adapt to the card class and number of blocks, as per the SDCard specicifications.
One more thing to add, currently the driver waits to confirm the SDCard has actually written the block without errors. The Teensy library DOES NOT do that, neither out previous driver if I remember right (have read so much thru different HALs I dont remember anymore what they do...)
The 700ms in max latency seems consistent with the specs. The card can have up to 500ms busy between 2 consecutive blocks during multiblock write, and another 500ms at the end of the write, so number of blocks*500ms. Since we write multiple blocks, latency can go over 500ms and still be within specs.

I could change the library to return OK when the card is programming, but that would not ensure the data is actually written to the card, and leave that in the hands of the card. From reading the teensy code, that's what that code does though.

If we want to keep write confirmation, we could also implement a retry mechanism. If the card return an error at the end of the write, retry the same write.
If we decide to just go for performance and return when the card is busy writing, then no retry is possible.

victor_pv
Posts: 1483
Joined: Mon Apr 27, 2015 12:12 pm

Re: [STM32GENERIC] SDIO DMA

Post by victor_pv » Fri May 19, 2017 4:54 pm

ag123 wrote:one trouble is that the sdio specs is pretty much non public, that'd make it somewhat harder to figure out the errors. we'd perhaps need go 'google' for it perhaps on some other forums avr, intel and say even on the arm app cores (raspberry pi, beagle bone black, etc) for some of the answers ;)

some scraps of info may be found in various places
http://www.digitalspirit.org/file/index ... 33-001.pdf
https://yannik520.github.io/sdio.html
The simplified specifications are available:
https://www.sdcard.org/downloads/pls/

They don't provide every little detail, but if they did I wouldn't read them anyway... :lol:
It provide enough to understand the different information fields in CID and CSD, timeouts, read and write operations. It's actually fairly long an detailed for being simplified.

stevestrong
Posts: 1450
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: [STM32GENERIC] SDIO DMA

Post by stevestrong » Fri May 19, 2017 5:11 pm

Victor, can you provide the black F407VET board BIN file for testing? I have a 16GB CL10 card.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest