Spark Logic

[libmaple] SDIO

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:
#elif defined(__STM32F4__)
#define ENABLE_SDIO_CLASS 1

Replies

stevestrong Wed Jul 05, 2017 9:52 am

Pito, as you can see in my first post, I refer to the SdFat lib.

You suggested to decrease the SDIO frequency for CL4 cards. And I do not see (yet) any reason for that, because from stephen’s log obviously 2kB buffer works well @24MHz, it only generates 0x60 (SD_CARD_ERROR_DMA) error when using 4kB buffer. That’s why I asked for more information from stephen, to understand and localize the issue.

Pito Wed Jul 05, 2017 9:57 am

Ah, ok, as I could not find any info on the 2k/4k buffer size issue in the posts above.. :?
So you do refer this, right?
2048,344.94,1623.80
4096,file.write returned: 4294967295
error: write failed
SD errorCode: 0X60,0X0

zmemw16 Wed Jul 05, 2017 11:20 am

i think sleep intervened around 0400

steve – oh thank you for this and anyone else

what extra info do you want from me ?
changed the card from a whatever 4gb to 8gb, labelled ultra, 2 colour, red & silver, with a 1 inside a U
how high do you want to go, try 16G, 32G ? couple or three of those.
sdformat – if that’s the official one, i don’t think it’s a linux port, dd +fdisk+mkfs.vfat is best i’ve got.
typical, win+mac
i’ll go looking though.

Type any character to start.

size,write,read
bytes,KB/sec,KB/sec
512,321.57,1078.55
1024,738.05,2124.35
2048,1250.39,3516.35
4096,2070.08,5286.28
8192,2439.10,5278.28
16384,2424.50,5270.61
32768,2356.58,5282.14

totalMicros 79140057
yieldMicros 46090617
yieldCalls 67753
yieldMaxUsec 193440
kHzSdClk 24000
Done

stevestrong Wed Jul 05, 2017 11:47 am

@stephen,
I wanted to know whether successive test with the same card, which showed the error, will show similar/identical error on the following test as well.
[zmemw16 – Wed Jul 05, 2017 11:20 am] –
in fsmc.h i see ‘See ../notes/fsmc.txt for more info’
is this a hang over from original sources or yours ?

That is just part of original source.
Further supported features and development status can be found here: viewtopic.php?f=39&t=1976
(yes, FSMC for 16bit parallel LCDs works already ;) )

The official (Roger’s) repo is also almost up to date with my one.

@Pito

[Pito – Wed Jul 05, 2017 9:57 am] – and also set the SDIO gpio’s output driver strength to MEDIUM!

Nope, this libmaple SDIO lib works (at least for my CL10 card on generic black F407VET board) @24MHz only if the SDIO pins are set to output PP + PU at HIGH (50MHz) frequency.
I tried with MEDIUM strength and got errors at the very first card access after switching the SDIO clk from 400kHz to 24MHz…
Pito wrote:Also Serial1 is something you would need handy, definitely..

Pito Wed Jul 05, 2017 1:15 pm

Nope, this libmaple SDIO lib works (at least for my CL10 card on generic black F407VET board) @24MHz only if the SDIO pins are set to output PP + PU at HIGH (50MHz) frequency.
Interestingly all my CL10 cards work @24-44MHz SDIO only with MEDIUM (Black 407ZET, STM32GENERIC) :D
So maybe there is a subtle difference in card’s inits in the cores somewhere :)

stevestrong Wed Jul 05, 2017 1:23 pm

[Pito – Wed Jul 05, 2017 1:15 pm] –
So maybe there is a subtle difference in card’s inits in the cores somewhere :)

I would rather think on any difference in the F4 register settings, or any hardware issue, power supply decoupling.
Would a register dump make sense to find out the diff? Is there any reg-dumping sketch available?

zmemw16 Wed Jul 05, 2017 1:25 pm

i returned to the 4gb card, there is a press reset after each of the fails, surprisingly it seems to work after a warm up :o
Type any character to start.
size,write,read
bytes,KB/sec,KB/sec
512,149.78,695.32
1024,227.49,840.88
2048,348.16,1633.62
4096,file.write returned: 4294967295

Type any character to start.
size,write,read
bytes,KB/sec,KB/sec
512,145.10,678.64
1024,224.82,847.31
2048,352.94,1664.60
4096,file.write returned: 4294967295

Type any character to start.
size,write,read
bytes,KB/sec,KB/sec
512,147.60,695.28
1024,231.63,872.22
2048,369.86,1719.74
4096,511.46,3556.26
8192,504.41,3560.83
16384,504.36,3562.77
32768,504.39,3569.58

totalMicros 218005614
yieldMicros 197107630
yieldCalls 60881
yieldMaxUsec 138343
kHzSdClk 24000
Done

Type any character to start.
size,write,read
bytes,KB/sec,KB/sec
512,147.33,695.80
1024,231.72,866.54
2048,369.51,1732.84
4096,511.83,3561.75
8192,504.74,3565.14
16384,504.56,3563.90
32768,504.45,3560.40

totalMicros 218100065
yieldMicros 200466135
yieldCalls 60934
yieldMaxUsec 146788
kHzSdClk 24000
Done

Type any character to start.
size,write,read
bytes,KB/sec,KB/sec
512,147.35,694.99
1024,231.79,867.61
2048,369.98,1727.27
4096,512.14,3564.36
8192,504.50,3568.53
16384,504.86,3557.19
32768,504.43,3563.17

totalMicros 218056619
yieldMicros 200422778
yieldCalls 60902
yieldMaxUsec 136086
kHzSdClk 24000
Done

Type any character to start.
size,write,read
bytes,KB/sec,KB/sec
512,147.39,695.88
1024,231.84,865.06
2048,369.89,1729.93
4096,512.36,3560.81
8192,504.73,3560.76
16384,504.18,3524.25
32768,504.84,3522.68

totalMicros 218097836
yieldMicros 200400149
yieldCalls 60909
yieldMaxUsec 145093
kHzSdClk 24000
Done

Pito Wed Jul 05, 2017 1:40 pm

[stevestrong – Wed Jul 05, 2017 1:23 pm] –
[Pito – Wed Jul 05, 2017 1:15 pm] –
So maybe there is a subtle difference in card’s inits in the cores somewhere :)

I would rather think on any difference in the F4 register settings, or any hardware issue, power supply decoupling.
Would a register dump make sense to find out the diff? Is there any reg-dumping sketch available?

I think Black’s 407VET and 407ZET boards are from the HW point almost identical, on my board I replaced the 100nF sdcard decoupling capacitor with 2x10u ceramic multilayer with no visible impact.
The F4 registers are set by sdcard’s inits() so the diff has to be in sources somewhere.. Or, do you mean there is a difference in F4VET vs. F4ZET silicon ?

@stephen: except your temperature dependency it seems to me your write speed is suspiciously low – should be close to read speed.

stevestrong Wed Jul 05, 2017 1:49 pm

[zmemw16 – Wed Jul 05, 2017 1:25 pm] –
i returned to the 4gb card, there is a press reset after each of the fails, surprisingly it seems to work after a warm up :o

Is it maybe a power supply stability issue?
I power my board over USB, via a USB-hub, I sometimes use for the USB hub an extra power adapter.

Pito wrote:The F4 registers are set by sdcard’s inits() so the diff has to be in sources somewhere..

Pito Wed Jul 05, 2017 2:01 pm

But it can also be a difference between the boards, since your board is not the “generic black F4VET” one. Is the difference only in the chip or are there other differences?
The only difference is the chip and maybe +/- 1-3cm in SDIO’s signal wires length.
The same vendor, similar layout..
My board: http://www.stm32duino.com/viewtopic.php … =30#p22456

PS: why the write speed in above benchmark is 1/7 of the read speed?
4096,512.36,3560.81
8192,504.73,3560.76
16384,504.18,3524.25
32768,504.84,3522.68

stevestrong Wed Jul 05, 2017 2:21 pm

[Pito – Wed Jul 05, 2017 2:01 pm] –
PS: why the write speed in above benchmark is 1/7 of the read speed?
4096,512.36,3560.81
8192,504.73,3560.76
16384,504.18,3524.25
32768,504.84,3522.68

zmemw16 Wed Jul 05, 2017 3:33 pm

on my hub i’ve replaced the wimpy supplied walwart with a 5V 4A capable one
although just about everything hangs off the hub, ols,2x usb serial, stlink and the board.

stephen

stevestrong Wed Jul 05, 2017 3:48 pm

I updated the first post with two attachments, one INO example and the corresponding BIN file.
The results today are similar to what I have measured that time (SanDisk Ultra 16GB CL10 card)
Type any character to start.

size,write,read
bytes,KB/sec,KB/sec
512,352.13,1855.96
1024,615.75,2573.66
2048,1273.42,3993.01
4096,3232.87,6568.02
8192,5171.66,8589.67
16384,6754.45,9880.24
32768,8231.03,10657.71

totalMicros 64281101
yieldMicros 44535132
yieldCalls 53279
yieldMaxUsec 134928
kHzSdClk 24000
Done

Type any character to start.

size,write,read
bytes,KB/sec,KB/sec
512,430.66,2197.68
1024,684.68,2444.70
2048,1424.19,4174.99
4096,3339.52,6118.28
8192,5012.46,8629.27
16384,6870.03,9874.56
32768,8144.14,10624.18

totalMicros 57296702
yieldMicros 38051319
yieldCalls 51383
yieldMaxUsec 116471
kHzSdClk 24000
Done

Pito Wed Jul 05, 2017 5:36 pm

I’ve decided to risk :) and I’ve tried with your binary on Black F407ZET6 board (cards not formatted before the test):
Samsung EVO CL10 8GB
SdFatSdio uses a traditional DMA SDIO implementation.

Type any character to start.

size,write,read
bytes,KB/sec,KB/sec
512,268.75,1186.61
1024,578.31,2013.27
2048,902.17,3499.82
4096,2799.68,5325.05
8192,4729.74,7705.77
16384,7165.14,9325.13
32768,8636.38,10346.14

totalMicros 79935842
yieldMicros 56356622
yieldCalls 114859
yieldMaxUsec 199834
kHzSdClk 24000
Done

Type any character to start.

stevestrong Wed Jul 05, 2017 10:39 pm

I updated the first post with new BIN and INO files, a fix was necessary for CL4 cards to work with buffers greater or equal than 4kB.
Additionally I added to monitor log info about the SD card.
And, as requested, the user gets warned about the time to wait.

Pito Wed Jul 05, 2017 10:50 pm

Kingston CL4 4GB (formatted)
######################################################
This sketch demonstrates STM32F4 SDIO (DMA) implementation.
######################################################

init time: 7 ms

Card type: SDHC

Manufacturer ID: 2
OEM ID: TM
Product: SA04G
Version: 0.6
Serial number: 289b4188
Manufacturing date: 3/2011

cardSize: 3951.03 MB (MB = 1,000,000 bytes)
flashEraseSize: 128 blocks
eraseSingleBlock: true
OCR: c0ff8000

Volume is FAT32
blocksPerCluster: 64
clusterCount: 120320
freeClusters: 120193
freeSpace: 3938.48 MB (MB = 1,000,000 bytes)
fatStartBlock: 14502
fatCount: 2
blocksPerFat: 941
rootDirStart: 2
dataStartBlock: 16384

FreeStack: 84095
######################################################

Type any character to start

Test started - please wait, it may take up to 3 minutes

size, write, read
bytes, KB/sec, KB/sec
512,

stevestrong Wed Jul 05, 2017 10:55 pm

@Pito, did you wait 3 minutes?

Pito Wed Jul 05, 2017 10:59 pm

Nope, I started to panic.. I’ll try again..

Kingston CL4 4GB
Test started - please wait, it may take up to 3 minutes :)

size, write, read
bytes, KB/sec, KB/sec
512, 45.45, 482.42 in T=00:03:15
1024, 24.92, 693.02 in T=00:06:05
2048, 25.21, 1286.25 in T=00:15:00
4096, 1337.13, 2271.51
8192, 1702.51, 3916.33
16384, 3012.27, 5492.42
32768, 3638.46, 7413.43 in T=00:15:20

totalMicros 914714129 => 15.5minutes
yieldMicros 867872714
yieldCalls 84774
yieldMaxUsec 150782
kHzSdClk 24000
Done

Type any character to start

stevestrong Wed Jul 05, 2017 11:01 pm

I might have not attached the very latest BIN previously, so I updated the first post again.
######################################################
Demo sketch of STM32F4 SDIO (DMA) implementation.
######################################################

init time: 8 ms

Card type: SD2

Manufacturer ID: 27
OEM ID: PH
Product: SD02G
Version: 3.0
Serial number: 97bdbf7c
Manufacturing date: 8/2011

cardSize: 1969.23 MB (MB = 1,000,000 bytes)
flashEraseSize: 128 blocks
eraseSingleBlock: true
OCR: 80ff8000

Volume is FAT16
blocksPerCluster: 64
clusterCount: 60086
freeClusters: 59578
freeSpace: 1952.25 MB (MB = 1,000,000 bytes)
fatStartBlock: 138
fatCount: 2
blocksPerFat: 235
rootDirStart: 608
dataStartBlock: 640

FreeStack: 84095
######################################################

Type any character to start
Test started - please wait, it may take up to 3 minutes

size, write, read
bytes, KB/sec, KB/sec
512, 191.49, 872.32
1024, 359.56, 1059.29
2048, 661.10, 2100.89
4096, 1133.47, 4102.19
8192, 1612.33, 5705.51
16384, 1965.11, 7776.31
32768, 2231.90, 9110.85

totalMicros 127501398
yieldMicros 94566913
yieldCalls 87120
yieldMaxUsec 151458
kHzSdClk 24000
Done

Type any character to start

Pito Wed Jul 05, 2017 11:36 pm

Tried with latest bin again, but got the first result after about 6 minutes
Kingston CL4 4GB
size, write, read
bytes, KB/sec, KB/sec
512, 24.00, 485.60
1024,

Sign in to reply