[libmaple] SDIO

Limited support for STM32F4 Discovery, Nucleo and custom F4 boards
Post Reply
stevestrong
Posts: 1521
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

[libmaple] SDIO

Post by stevestrong » Sun Jun 18, 2017 5:20 pm

Hi all,

I finally managed to bring the SDIO files in an acceptable form to be published.

It works with 24MHz clock and 4bits wide bus, and tested only for the generic F407VET6 board.

I have committed 2 files to libmaple core directory, and 2 files to a new SDIO lib under STM32F4/libraries.

Usage:
- get the master branch from my repo
- get the SdFat lib from https://github.com/greiman/SdFat
- insert into line 164 of SdFatConfig:

Code: Select all

#elif defined(__STM32F4__)
#define ENABLE_SDIO_CLASS 1
- use in example sketches

Code: Select all

#include "SdioF4.h" // instead of #include "SdFat"
- insert in your sketch the function

Code: Select all

void yield() {}
- do not use the "SdFatSdioEX" class, it will destroy the Fat structure on your card.
Note:
This is due to the EX class way of working, and NOT because the SDIO driver writes wrong data.
I have tested intensively, and the reads were always identical with the writes.


Current benchmarks:
- using bench.ino -- buffer size 512 bytes

Code: Select all

write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
439.69,18756,870,1163
433.55,117741,865,1180

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
2353.90,1252,211,216
2353.90,440,211,216
These is actually the best ever result, the read speed for 512 byte buffer is average 2.1MB, varying +/-10%, the write speed is only varying ~3%.

- using STM32F4SdioDemo.ino (see attached binary and INO files): (DO NOT USE the SdFatSdioEX" class!!!) - this has the "yield()" function already included.

Code: Select all

size,write,read
bytes,KB/sec,KB/sec
512,432.94,2069.58
1024,710.33,2451.21
2048,1510.87,4270.57
4096,3418.99,5956.09
8192,5170.13,8611.31
16384,6654.81,9750.35
32768,8493.92,10667.59

totalMicros  56530544
yieldMicros  37059984
yieldCalls   51335
yieldMaxUsec 87835
kHzSdClk     24000
Done
Disclaimer:
- Use it on you own risk!

Although I tested as much as I could, and all examples worked, I cannot exclude that bugs are still in the software, so don't blame me if data gets lost from the card.

Just post here if you encounter any problem, or make a PR on github if you find a bug.
Attachments
STM32SdioDemo.ino
(8.45 KiB) Downloaded 18 times
STM32SdioDemo.ino.bin.txt
(41.19 KiB) Downloaded 7 times
Last edited by stevestrong on Wed Jul 05, 2017 10:58 pm, edited 23 times in total.

User avatar
RogerClark
Posts: 6726
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: [libmaple] SDIO

Post by RogerClark » Sun Jun 18, 2017 9:31 pm

Thanks

When I have enough time, I will pull you F4 changes

acronis
Posts: 107
Joined: Thu Mar 02, 2017 12:32 pm

Re: [libmaple] SDIO

Post by acronis » Mon Jun 19, 2017 8:24 am

Hello. Will this work on version 1.8.2 or 1.8.3 ?

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

Re: [libmaple] SDIO

Post by stevestrong » Mon Jun 19, 2017 8:26 am

I tested it with 1.6.12 - I kept this version based on "never change a running system"- but I assume it should work with the latest versions as well.
If not, please post here any problems.

acronis
Posts: 107
Joined: Thu Mar 02, 2017 12:32 pm

Re: [libmaple] SDIO

Post by acronis » Mon Jun 19, 2017 8:29 am

OK.
Thank YOU very much for YOUR work !

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

Re: [libmaple] SDIO

Post by stevestrong » Mon Jun 19, 2017 9:13 am

RogerClark wrote:
Sun Jun 18, 2017 9:31 pm
Thanks

When I have enough time, I will pull you F4 changes
I have to first merge the latest commits from your master to my branch, I hope I manage it today in the evening.
I'll let you know.

User avatar
RogerClark
Posts: 6726
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: [libmaple] SDIO

Post by RogerClark » Mon Jun 19, 2017 10:37 am

stevestrong wrote:
Mon Jun 19, 2017 9:13 am
RogerClark wrote:
Sun Jun 18, 2017 9:31 pm
Thanks

When I have enough time, I will pull you F4 changes
I have to first merge the latest commits from your master to my branch, I hope I manage it today in the evening.
I'll let you know.
OK

I think it may be OK without doing this.

But don't rush, I have so many other things I need to do.

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

Re: [libmaple] SDIO

Post by stevestrong » Mon Jun 19, 2017 5:50 pm

I have tested the reading/writing/CRC calculating sketch from Daniel (test file of 102.4MB), and this is the result:

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 24063 msecs
*************************************************
Running CRC calculations...
File in CRC:  22BCDBEC
File out CRC: 22BCDBEC
*************************************************
Done in 70620 msecs

Type any character to start
#################################################
Opening the read file..
Opening the write file..
Reading and Writing..
*************************************************
Done in 34167 msecs
*************************************************
Running CRC calculations...
File in CRC:  22BCDBEC
File out CRC: 22BCDBEC
*************************************************
Done in 70937 msecs

Type any character to start
#################################################
Opening the read file..
Opening the write file..
Reading and Writing..
*************************************************
Done in 37755 msecs
*************************************************
Running CRC calculations...
File in CRC:  22BCDBEC
File out CRC: 22BCDBEC
*************************************************
Done in 70910 msecs

Type any character to start
#################################################
Opening the read file..
Opening the write file..
Reading and Writing..
*************************************************
Done in 36741 msecs
*************************************************
Running CRC calculations...
File in CRC:  22BCDBEC
File out CRC: 22BCDBEC
*************************************************
Done in 70734 msecs

Type any character to start
It is interesting to see that the first run (after reset) the reading/writing is always much less (30%!) than the following read/writes.

When I activated the debug output I saw that the first run involves much less block reads than the following ones, which are again all comparable.

There was no block number difference on CRC calculation.

Does anyone else experienced the same issue?
I think it has something to do with the SdFat lib, because the files system is the same after 5 runs than at the very first run. The difference is only the software reset.

Also interesting to see that, compared to the result for GENERIC core, the read/write takes here much less time (~37secs vs. 47secs), but CRC calculation lasts in average ~3 seconds more. Is that due to the different compiler versions?

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: [libmaple] SDIO

Post by danieleff » Wed Jun 21, 2017 5:03 am

100MB F407
I get with my:

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 61039 msecs
*************************************************
Running CRC calculations...
File in CRC:  DE9D6BE7
File out CRC: DE9D6BE7
*************************************************
Done in 71259 msecsType any character to start

*************************************************
Opening the read file..
Opening the write file..
Reading and Writing..
*************************************************
Done in 60230 msecs
*************************************************
Running CRC calculations...
File in CRC:  DE9D6BE7
File out CRC: DE9D6BE7
*************************************************
Done in 71251 msecsType any character to start

*************************************************
Opening the read file..
Opening the write file..
Reading and Writing..
your:

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 34231 msecs
*************************************************
Running CRC calculations...
File in CRC:  DE9D6BE7
File out CRC: DE9D6BE7
*************************************************
Done in 71164 msecsType any character to start

*************************************************
Opening the read file..
Opening the write file..
Reading and Writing..
*************************************************
Done in 58237 msecs
*************************************************
Running CRC calculations...
File in CRC:  DE9D6BE7
File out CRC: DE9D6BE7
*************************************************
Done in 71207 msecsType any character to start

*************************************************
All in all it seems to work pretty stable.

BTW I always get slower speeds than you all, even if the microSD has ⑩ written on it.

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

Re: [libmaple] SDIO

Post by stevestrong » Wed Jun 21, 2017 6:49 am

OK, so you could reproduce my issue.
For libmaple core, the first read and write takes a lot less time (34231 msecs) than the following read writes (58237 msecs).
Your core seems not to show this issue.

Hmmm.

Post Reply