[STM32GENERIC] SDIO DMA

Discussions about the STM32generic core
Post Reply
victor_pv
Posts: 1337
Joined: Mon Apr 27, 2015 12:12 pm

[STM32GENERIC] SDIO DMA

Post by victor_pv » Sun Apr 30, 2017 11:25 pm

Seems like adding DMA to the SDIO library should not be much harder than adding it to the SPI.
Now, my F407 board doesn't have an SDcard slot so I haven't tested yet the current SDIO.
Can someone confirm if everything is working fine with the current SDIO with an F4 and the SdFat library?
If so, what changes are necessary to make it work with the current SDIO library?

I would like to set it up so I can add DMA to the SDIO and test it.

Update:
Daniel already pointed to the example in this post:
viewtopic.php?f=42&t=1966&p=27197&hilit=sdfat#p27197

Adding it here for anyone wondering if SDIO works with SdFat. The folder in question has 2 files needed, and the comments in the .ino file explain what needs to be done in the sdFat library.
I'll see if I can get it working later today, and if so, turn to DMA and see what happens. I'll post back the results.

Update2:
This branch contains my latest SDIO files. The rest of the core in that branch is not in sync with Daniel's so I would recommend to just download the SDIO files:
https://github.com/victorpv/STM32GENERI ... DMA-Latest

Update 05/19/17:
New bin using the latest F4 HAL.
F407VET, DMA, SDIO 4b, 512bytes buffer bench test.
download/file.php?id=1611

Update 05/25/17:
My latest working version + Daniel's latest HAL core
https://github.com/victorpv/STM32GENERIC/tree/FW-Update
Last edited by victor_pv on Thu May 25, 2017 1:18 pm, edited 5 times in total.

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

Re: [STM32GENERIC] SDIO DMA

Post by ag123 » Mon May 01, 2017 11:00 am

accordingly sdio is quite different from spi, those same pins are also assigned differently and more pins are used e.g. uses the pins d0:d3 on sd card
did a little google and found the following links

https://community.st.com/thread/30654
https://github.com/hexanaft/stm32f4-dis ... sdio-fatfs
http://www.st.com/resource/en/product_t ... _sdmmc.pdf
http://www.digitalspirit.org/file/index ... icrosd.pdf

hopefully we could find the HAL implementation for the 'physical' sdio layer, i.e. hardware do all that interfacing
then we'd need to find the hooks to link sdfat or rather fatfs into the sdio hal interface

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

Re: [STM32GENERIC] SDIO DMA

Post by victor_pv » Wed May 10, 2017 8:48 pm

Just an update, I have taken Daniel's SDIO files and added a few more functions that were on the teensy files and were needed by the bench test, so hopefully the bench test will run now.
I need to still test and bugfix it, we will see where we get...
If that works, next is adding DMA capability.

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

Re: [STM32GENERIC] SDIO DMA

Post by stevestrong » Wed May 10, 2017 9:19 pm

Victor, I could test on black F4 board any bin file you post here, output on serial 1 or usb.

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

Re: [STM32GENERIC] SDIO DMA

Post by victor_pv » Thu May 11, 2017 4:37 am

stevestrong wrote:Victor, I could test on black F4 board any bin file you post here, output on serial 1 or usb.
This is the first test with bench.ino and SDIO class. I am using the SDIO files included in Daniel's repo, but with several more functions added.

Card is a class 4 micro SD. No DMA. F407VET at 168Mhz.
And I think it's using 1 data line only. I tried with 4B wide and it fails to initialize.

Code: Select all

FreeStack: 125235 
Type is FAT32
Card size: 3.95 GB (GB = 1E9 bytes)

Manufacturer ID: 0X27
OEM ID:
Product: P40DS
Version: 4.7 
Serial number: 0X15000030
Manufacturing date: 9/2165 
 
File size 5 MB 
Buffer size 512 bytes 
Starting write test, please wait. 
 
write speed and latency 
speed,max,min,avg
KB/Sec,usec,usec,usec
180.81,128637,1478,2830 
181.43,128859,1482,2820 
 
Starting read test, please wait. 
 
read speed and latency 
speed,max,min,avg 
KB/Sec,usec,usec,usec 
688.95,1325,578,742 
689.14,1317,577,742
 
Done 
Type any character to start 
I need to find how to attach the bin because is not letting me do it.

Notes:
I haven't used this same card in an spi test, so don't know how it compares.
The card was not formatted before test.
I'm almost certain the CID structure doesn't match between the HAL and the sdFat library, as the Date is wrong, the OEM shows a character I can't copy, and some of the other information fields may be wrong.
4bit wide transmit is not working at the moment.
I don't know the bus speed, whichever is set by the begin() function from Daniel, but I suspect is 24-25Mhz.

EDIT: Well looks like the forum just doesn't like .bin, so I zipped it.
Warning, this code may still corrupt the sdcard, so use at your own risk.

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

Re: [STM32GENERIC] SDIO DMA

Post by victor_pv » Fri May 12, 2017 3:40 pm

Another update.
I got the SDIO working with DMA in an F4, haven't tried an F1 yet.
The performance right now is the same as without DMA (disappointing, but could be due to the sdcard).
Next come:
Trying to find out why 4bit wide mode is not actually happening.
Since there is an SDIOEX mode for the SdFat library, finding if that improves performance in the same degree as it does in SPI.
Testing on other series.

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

Re: [STM32GENERIC] SDIO DMA

Post by Pito » Fri May 12, 2017 5:55 pm

Which Serial do you use with the above bin test file? A: USB Serial
Sandisk 16GB Ultra

Code: Select all

Manufacturing date: 5/2134
File size 5 MB
Buffer size 512 bytes
Starting write test, please wait.
write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
413.44,18504,943,1237
413.27,18861,942,1238
Starting read test, please wait.
read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
1999.07,540,252,255
1999.87,516,252,255
Promising results :)
Pukao Hats Cleaning Services Ltd.

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

Re: [STM32GENERIC] SDIO DMA

Post by victor_pv » Fri May 12, 2017 6:23 pm

Pito wrote:Which Serial do you use with the above bin test file? A: USB Serial
Sandisk 16GB Ultra

Code: Select all

Manufacturing date: 5/2134
File size 5 MB
Buffer size 512 bytes
Starting write test, please wait.
write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
413.44,18504,943,1237
413.27,18861,942,1238
Starting read test, please wait.
read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
1999.07,540,252,255
1999.87,516,252,255
Promising results :)

Is that the same card that gets around 4MB/s with SPI?
I believe the SDIO clock is set at 25Mhz, and setting it as 50Mhz could mean trouble due to the bug you listed in another thread.
But even at 25Mhz I would expect some more performance.

I think 4bit mode may be working, just the card I am using is crap. Because I get 170KB/s write in 1bit mode, and 180KB/s changing to 4bit mode without any other change, so perhaps is just the limit of the card.

EDIT:
File attached. F4, SDIO, 4bit, 25Mhz, SerialUSB output, DMA:
Release.zip
(247.48 KiB) Downloaded 9 times
And these the results I get with the microsd I had at hand, class 4 patriot:

Code: Select all

FreeStack: 125607
Type is FAT32
Card size: 3.95 GB (GB = 1E9 bytes)

Manufacturer ID: 0X27 
OEM ID:
Product: P40DS 
Version: 4.7 
Serial number: 0X15000030 
Manufacturing date: 9/2165 
 
File size 5 MB 
Buffer size 512 bytes 
Starting write test, please wait.
 
write speed and latency 
speed,max,min,avg 
KB/Sec,usec,usec,usec
180.85,128300,1483,2829 
180.85,128469,1482,2828 
 
Starting read test, please wait. 
 
read speed and latency
speed,max,min,avg 
KB/Sec,usec,usec,usec 
687.15,1341,583,744
686.96,1336,583,744

Done
 
Same card, 16KB buffer, this is more promising:

Code: Select all

Product: P40DS
Version: 4.7 
Serial number: 0X15000030 
Manufacturing date: 9/2165
 
File size 5 MB
Buffer size 16384 bytes
Starting write test, please wait.
 
write speed and latency
speed,max,min,avg 
KB/Sec,usec,usec,usec
1996.45,697012,2129,8184 
2417.57,679729,2129,6725 
 
Starting read test, please wait. 
 
read speed and latency
speed,max,min,avg 
KB/Sec,usec,usec,usec 
6988.98,3156,2223,2345 
6979.22,3151,2079,2345

Done 
Type any character to start 
Last edited by victor_pv on Fri May 12, 2017 6:42 pm, edited 1 time in total.

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

Re: [STM32GENERIC] SDIO DMA

Post by Pito » Fri May 12, 2017 6:42 pm

I doubt we will get SDIO-like speeds with 512bytes large buffer. Could you create a .bin with 32kB large buffer??
I do expect 8-10MB/sec with SDIO and F407 and 32kB large buffer.
5-6y back I did test SDIO with chibios - I got around 6MB/s with 32kB buffer, and about 400kB/s with 512b, afik.
BTW, the SDIO is the native interface for sdcards since ever, the SPI is just an "option" all vendors support luckily :)
Last edited by Pito on Fri May 12, 2017 6:45 pm, edited 1 time in total.
Pukao Hats Cleaning Services Ltd.

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

Re: [STM32GENERIC] SDIO DMA

Post by victor_pv » Fri May 12, 2017 6:44 pm

Pito wrote:I doubt we will get SDIO-like speeds with 512bytes large buffer. Could you create a .bin with 32kB large buffer??
I do expect 8-10MB/sec with SDIO and F407 and 32kB large buffer.
BTW, the SDIO is the native interface for sdcards since ever, the SPI is just an "option" all vendors support luckily :)
Done :)


And same class 4 card using the bin above:

Code: Select all

Product: P40DS 
Version: 4.7 
Serial number: 0X15000030
Manufacturing date: 9/2165

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 
3065.07,693570,3590,10638
2914.42,682667,3590,11192 
 
Starting read test, please wait.
 
read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
8692.38,4596,3645,3770
8692.38,4578,3502,3770

Done
Type any character to start 
EDIT: Just compiled and zipped it again, it works fine for me.
Bench_SDIO_F4_32KBbuf_DMA.zip
(247.48 KiB) Downloaded 18 times
Last edited by victor_pv on Fri May 12, 2017 7:00 pm, edited 1 time in total.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest