[STM32GENERIC] SDIO DMA

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


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
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
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
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.

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.

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
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

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
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

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 :)

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 :)

Pito
Fri May 12, 2017 6:48 pm
Use a freshly formatted SD for best performance.

Type any character to start
FreeStack: 93351


stevestrong
Fri May 12, 2017 6:58 pm
Can’t SDIO be combined with SdFatEX?

victor_pv
Fri May 12, 2017 7:02 pm
stevestrong wrote:Can’t SDIO be combined with SdFatEX?

Pito
Fri May 12, 2017 7:10 pm
I had a discussion with BillG on SDIO and what he indicated:
..On Teensy 3.6 an errata prevented use of DMA in EX mode.
Teensy 3.6 has a 512 byte FIFO in the SDIO controller so I used program I/O.
Notice Teensy 3.6 results for 512 byte buffer size. Write: DMA 598 KB/sec, EX mode FIFO 18820 KB/sec..

victor_pv
Fri May 12, 2017 7:16 pm
Pito wrote:I had a discussion with BillG and what he indicated:
..On Teensy 3.6 an errata prevented use of DMA in EX mode.
Teensy 3.6 has a 512 byte FIFO in the SDIO controller so I used program I/O.
Notice Teensy 3.6 results for 512 byte buffer size. Write: DMA 598 KB/sec, EX mode FIFO 18820 KB/sec..

Pito
Fri May 12, 2017 7:30 pm
With my above results: I have 4bit SDIO socket on the Black F407 and I got 4.7MB/s write (with 250ms max latency!) and 10MB/s read with an 8y old card.
So with a good card it could be 68/10MB/s. That is close to the expected max at 24MHz SDIO clock.
But there is still a mess with the reading the Sdcard’s info data, so maybe that should be fixed first.
The EX mode might not be easy to get working, and the gain will not be high with 24MHz SDIO clock. EDIT: it might be “high” when you get 8/10MB/s with 512b large buffer :)
The above Bill’s results are with 50MHz SDIO clock, sure.
Update: Here after a few more runs with the old CL4 Sandisk 4GB:
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
8662.15,9753,3554,3767
8165.14,13336,3555,3995
Starting read test, please wait.
read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
10333.48,3523,3143,3169
10333.48,3524,3140,3168

victor_pv
Fri May 12, 2017 7:49 pm
Pito wrote:With my above results: I have 4bit SDIO socket on the Black F407 and I got 4.7MB/s write (with 250ms max latency) and 10MB/s read with an 8y old card.
So with a good card it could be 68/10MB/s. That is close to the expected max at 24MHz SDIO clock.
But there is still a mess with the reading the Sdcard’s info data, so maybe that should be fixed first.
The EX mode might not be easy to get working, and the gain will not be high with 24MHz SDIO clock. EDIT: it might be “high” when you get 8/10MB/s with 512b large buffer :)
The above Bill’s results are with 50MHz SDIO clock, sure.
Update: Here after a few more runs with the old CL4 Sandisk 4GB:
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
8662.15,9753,3554,3767
8165.14,13336,3555,3995
Starting read test, please wait.
read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
10333.48,3523,3143,3169
10333.48,3524,3140,3168

ag123
Fri May 12, 2017 9:15 pm
wow reaches 5 figures (80 mbps minimum!), that blow most benchmarks & u’d need USB 2.0 High Speed ULPI if you want to send data to the PC (i think even fast ethernet 100mbps may not be sufficient with the overheads) :lol:
http://www.ebay.com/sch/i.html?_odkw=ul … 0&_sacat=0

at the rate we’re going 1 day we’d stream HD videos on HDMI connector (gbps) :lol:


Pito
Fri May 12, 2017 9:42 pm
ag123 wrote:wow reaches 5 figures (80 mbps minimum!)..

ag123
Fri May 12, 2017 10:01 pm
then it’d seem we’ve ‘reached the limit’ maybe, APB1 is 42mhz, so assuming that we can transceive at 21mbps per pin 21×4 = 84mbps ~ 10MBps :lol:

Pito
Fri May 12, 2017 10:01 pm
@victor – with my CL10 UHS-I Samsung it stops after Freestack. It seems it cannot recognize other card type than CL4.. So there is an issue in the sdcard init probably..

victor_pv
Fri May 12, 2017 10:51 pm
Pito wrote:@victor – with my CL10 UHS-I Samsung it stops after Freestack. It seems it cannot recognize other card type than CL4.. So there is an issue in the sdcard init probably..

Pito
Sat May 13, 2017 8:38 am
The first and second bin the same – the card’s info is not read properly.
I’ve tried with Samsung 8GB and 16GB, both EVO CL10, UHS-I. Info is a garbage and it does not start the bench.
With Sandisk CL4 the card info is garbage too, but it performs the benchmark as above.

ag123
Sat May 13, 2017 10:22 am
oops, hopefully not ‘garbage in garbage out’ at 10MBps :lol:

Pito
Sat May 13, 2017 10:30 pm
Is this setting ok in SDIO.cpp?
hsd.Init.ClockDiv = 0; // <<<<< should be max 400kHz

error = HAL_SD_Init(&hsd, &SDCardInfo);
if (error != SD_OK) {
return false;
}


victor_pv
Sun May 14, 2017 12:28 am
Pito wrote:Is this setting ok in SDIO.cpp?
hsd.Init.ClockDiv = 0; // <<<<< should be max 400kHz

error = HAL_SD_Init(&hsd, &SDCardInfo);
if (error != SD_OK) {
return false;
}


Pito
Sun May 14, 2017 7:56 am
While debugging your HAL_SD_Init() I see all the CID data read off the sdcard in the SDCardInfo.SD_cid structure are correct (at least I see the correct info inside the structure).
The “info” inside this “SDCardInfo.SD_cid” structure is identical to the cid info printed out by SdFat bench run with SPI for the given card.
It seems to me the “conversion/mapping” between your SD_cid structure and SdFat’s “cid” table in SDIO.cpp has got a bug, however..
bool SDIOClass::readCID(void* cid) {
memcpy(cid, &SDCardInfo.SD_cid, 16);
return true;
}

Pito
Sun May 14, 2017 3:32 pm
The printing of SDIO’s CID shows good results too
bool SDIOClass::readCID(void* cid) {
memcpy(cid, &hsd.CID, 16); //&SDCardInfo.SD_cid, 16);
Serial.println(hsd.CID[0], HEX);
Serial.println(hsd.CID[1], HEX);
Serial.println(hsd.CID[2], HEX);
Serial.println(hsd.CID[3], HEX);
return true;
}

victor_pv
Sun May 14, 2017 4:00 pm
Pito wrote:The printing of SDIO’s CID shows good results too
bool SDIOClass::readCID(void* cid) {
memcpy(cid, &hsd.CID, 16); //&SDCardInfo.SD_cid, 16);
Serial.println(hsd.CID[0], HEX);
Serial.println(hsd.CID[1], HEX);
Serial.println(hsd.CID[2], HEX);
Serial.println(hsd.CID[3], HEX);
return true;
}

stevestrong
Sun May 14, 2017 5:55 pm
ProdName1 from first picture is uint32_t (4 bytes), the corresponding pnm from the second picture is char [5] (5 bytes).
Isn’t this a mismatch?

Pito
Sun May 14, 2017 6:09 pm
ManufID is 0x3
OEMID is “SD” for Sandisk
REV is 0x80 = 8.0
ProdName = ProdName1 + ProdName2 = 5bytes = “SU04G”
ManufactDate is 0xC7 = 12 + 7 = July/2012

@Victor: I watched the CSD and it showed 50 the max speed. The card is Sandisk CL4 4GB (it does 8MB/s write! while max is 4). And because the Samsung CL10 cards do not pass the init yet, it seems we have got the card types reversed somehow.


stevestrong
Sun May 14, 2017 6:19 pm
Then it seems that the element alignment of those 2 arrays is different, that is why to use memcpy does not do what one would expect.
Just check the sizes of those arrays.

ag123
Sun May 14, 2017 10:06 pm
OT: oh wow, this slides on sd card is pretty ‘technical’ but it reads almost as exciting as a spy suspense thriller novel :lol:
http://bunniefoo.com/bunnie/sdcard-30c3-pub.pdf

victor_pv
Mon May 15, 2017 4:21 am
stevestrong wrote:ProdName1 from first picture is uint32_t (4 bytes), the corresponding pnm from the second picture is char [5] (5 bytes).
Isn’t this a mismatch?

Pito
Mon May 15, 2017 7:43 am
Both CID and CSD are 16bytes long tables. Sdfat or HAL reads them as 16bytes long chunk during card’s init.
The tables are packed without any padding.

SdFat maps a “cid” structure onto the CID table such the information is available via cid.xyz.
HAL does the same via “SD_cid” structure.

The HAL’s “internal types setup” of the CID/CSD mapping structure differs from the SdFat’s one, but the resulting “extracted” information is the same as the underlying 16bytes long CID/CSD table is the same.
So the memcpy should work.

As you may see above it seems like the SdFat’s “cid” structure gets broken somehow.


stevestrong
Mon May 15, 2017 8:37 am
stevestrong wrote:Then it seems that the element alignment of those 2 arrays is different, that is why to use memcpy does not do what one would expect.
Just check the sizes of those arrays.

Pito
Mon May 15, 2017 11:28 am
Here
http://www.stm32duino.com/viewtopic.php … =20#p28025
I memcopied “hsd.CID”, which is the raw CID table, into the SdFat’s “cid”.
I printed out hsd.CID content as well.
The Sdfat’s “cid” is still broken (but in different pattern).
PS: mind some of the SdFat’s cid table elements are mapped to CID’s nibbles.

Pito
Mon May 15, 2017 12:07 pm
I added a print out of the CID/CSD into the SDFat’s SdSpiCard.cpp:
/** read CID or CSR register */
bool SdSpiCard::readRegister(uint8_t cmd, void* buf) {
..
if (!readData(dst, 16)) {
goto fail;
}
// ##Pito - printing out the CID/CSD
int i;
for (i=0; i<16; i++){
Serial.print(dst[i],HEX);
Serial.print("-");
}
Serial.println();
..

Pito
Mon May 15, 2017 12:30 pm
And the same card with SDIO (F407) while doing
bool SDIOClass::readCID(void* cid) {
memcpy(cid, &hsd.CID, 16); //&SDCardInfo.SD_cid, 16);
Serial.println(hsd.CID[0], HEX);
Serial.println(hsd.CID[1], HEX);
Serial.println(hsd.CID[2], HEX);
Serial.println(hsd.CID[3], HEX);
return true;
}

Pito
Mon May 15, 2017 12:56 pm
And the CID printed out in SDIO with the same routine as with SPI
bool SDIOClass::readCID(void* cid) {
memcpy(cid, &SDCardInfo.SD_cid, 16);
// ##Pito - printing out the CID/CSD
int i;
char *buf = (char*)(cid);
for (i=0; i<16; i++){
Serial.print(buf[i],HEX);
Serial.print("-");
}
Serial.println();
return true;
}

Pito
Mon May 15, 2017 1:01 pm
The CID printed out in SPI version (correct one)
3-53-44-53-55-30-34-47-80-2-F1-B6-DF-0-C7-69- <<<<<<< CID

stevestrong
Mon May 15, 2017 1:05 pm
Did you add the pragma “__attribute__((packed))” to the CID structure in SDIO?
Also, be aware of endianess when transforming uin32_t to array[n].
You can easily check the structure mismatch by printing out the “sizeof(cid_struct)” for both SPI and SDIO.

Pito
Mon May 15, 2017 1:24 pm
Here I copy the hsd.CID (SDIO) which is the raw 16bytes table:
ool SDIOClass::readCID(void* cid) {
memcpy(cid, &hsd.CID, 16);
// ##Pito - printing out the CID/CSD
int i;
char *bufs = (char*) hsd.CID;
for (i=0; i<16; i++){
Serial.print(bufs[i],HEX);
Serial.print("-");
}
Serial.println();
char *bufd = (char*)(cid);
for (i=0; i<16; i++){
Serial.print(bufd[i],HEX);
Serial.print("-");
}
Serial.println();
return true;
}

stevestrong
Mon May 15, 2017 1:36 pm
Memcpy and byte-by-byte copying should be of course identical, which is also demonstrated by your test.

But the issue is which parameter you use with the SDIO::readCID() function.

If the structure, of which pointer is passed, is not “packed” and has different byte distribution than the SPI cid structure, then you have this problem.
To have the input parameter a void pointer can be dangerous when the pointers point to different data structures.


stevestrong
Mon May 15, 2017 1:44 pm
Source and destination change?
void * memcpy ( void * destination, const void * source, size_t num );

Pito
Mon May 15, 2017 1:45 pm
With /** @defgroup SD_Exported_Types_Group3 Card Identification Data: CID Register
* @{
*/
typedef struct
{
__IO uint8_t ManufacturerID; /*!< Manufacturer ID */
__IO uint16_t OEM_AppliID; /*!< OEM/Application ID */
__IO uint32_t ProdName1; /*!< Product Name part1 */
__IO uint8_t ProdName2; /*!< Product Name part2 */
__IO uint8_t ProdRev; /*!< Product Revision */
__IO uint32_t ProdSN; /*!< Product Serial Number */
__IO uint8_t Reserved1; /*!< Reserved1 */
__IO uint16_t ManufactDate; /*!< Manufacturing Date */
__IO uint8_t CID_CRC; /*!< CID CRC */
__IO uint8_t Reserved2; /*!< Always 1 */

} __attribute__((packed)) HAL_SD_CIDTypedef;


stevestrong
Mon May 15, 2017 1:47 pm
Endianess from
uint32_t to char[4] and
uint32_t+uint8 to char[5]

Pito
Mon May 15, 2017 1:54 pm
Now – where to make changes??
In the HAL or in the SdFat??
Or, we may use an item by item copy instead of memcpy..
The same issue might be we other tables, ie. CSD.
Also the HAL_SD_CSDTypedef is about 60bytes large..

victor_pv
Mon May 15, 2017 1:56 pm
Pito wrote:And the CID printed out in SDIO with the same routine as with SPI
bool SDIOClass::readCID(void* cid) {
memcpy(cid, &SDCardInfo.SD_cid, 16);
// ##Pito - printing out the CID/CSD
int i;
char *buf = (char*)(cid);
for (i=0; i<16; i++){
Serial.print(buf[i],HEX);
Serial.print("-");
}
Serial.println();
return true;
}

Pito
Mon May 15, 2017 2:06 pm
1. cid – the original memcpy results in mess because
a. the HAL table is not packed
b. “endianess” – or better to say the Sdfat interprets/prints out uint16/32/strings from the other end :)

2. csd – I have not elaborated it yet, but
a. the HAL table is not packed
b. the HAL table is about 41bytes
c. “endianess” – or better to say the Sdfat may interpret/print out uints16/32/strings from the other end :)

It seems to me the copy with a transformation would be needed in SDIO.h :(

The raw data is available in hsd.CID[] and probably hsd.CSD[] in SDIO.


victor_pv
Mon May 15, 2017 2:22 pm
Pito wrote:1. cid – the original memcpy results in mess because
a. the HAL table is not packed
b. “endianess” – or better to say the Sdfat interprets/prints out uint16/32/strings from the other end :)

2. csd – I have not elaborated it yet, but
a. the HAL table is not packed
b. the HAL table is about 41bytes
c. “endianess” – or better to say the Sdfat may interpret/print out uints16/32/strings from the other end :)

It seems to me the copy with a transformation would be needed in SDIO.h :(

The raw data is available in hsd.CID[] and probably hsd.CSD[] in SDIO.


Pito
Mon May 15, 2017 3:46 pm
This is something which works:
#define SWAP_UINT32(x) (((x)>>24) | (((x) & 0x00FF0000)>>8) | (((x) & 0x0000FF00)<<8) | ((x)<<24))

bool SDIOClass::readCID(void* cid) {
// Pito 5/2017
cid_t* cidi = reinterpret_cast<cid_t *>(cid);
cidi->mid = SDCardInfo.SD_cid.ManufacturerID;
cidi->oid[0] = SDCardInfo.SD_cid.OEM_AppliID >> 8;
cidi->oid[1] = SDCardInfo.SD_cid.OEM_AppliID;
cidi->pnm[0] = SDCardInfo.SD_cid.ProdName1 >> 24;
cidi->pnm[1] = SDCardInfo.SD_cid.ProdName1 >> 16;
cidi->pnm[2] = SDCardInfo.SD_cid.ProdName1 >> 8;
cidi->pnm[3] = SDCardInfo.SD_cid.ProdName1;
cidi->pnm[4] = SDCardInfo.SD_cid.ProdName2;
cidi->prv_n = (SDCardInfo.SD_cid.ProdRev >> 4) & 0xF;
cidi->prv_m = (SDCardInfo.SD_cid.ProdRev) & 0xF;
cidi->psn = SWAP_UINT32(SDCardInfo.SD_cid.ProdSN);
cidi->mdt_year_high = (SDCardInfo.SD_cid.Reserved1) & 0xF;
cidi->mdt_year_low = (SDCardInfo.SD_cid.ManufactDate >> 4) & 0xF;
cidi->mdt_month = (SDCardInfo.SD_cid.ManufactDate) & 0xF;
cidi->crc = (SDCardInfo.SD_cid.CID_CRC >> 7) & 0x7F;
return true;
}


Pito
Mon May 15, 2017 3:58 pm
In Teensy Bill does:
//-----------------------------------------------------------------------------
// Read 16 byte CID or CSD register.
static bool readReg16(uint32_t xfertyp, void* data) {
uint8_t* d = reinterpret_cast<uint8_t*>(data);
if (!cardCommand(xfertyp, m_rca)) {
return false; // Caller will set errorCode.
}
uint32_t sr[] = {SDHC_CMDRSP0, SDHC_CMDRSP1, SDHC_CMDRSP2, SDHC_CMDRSP3};
for (int i = 0; i < 15; i++) {
d[14 - i] = sr[i/4] >> 8*(i%4);
}
d[15] = 0;
return true;
}

Pito
Mon May 15, 2017 4:54 pm
Another optimized :) version which works as well:
#define SWAP_UINT32(x) (((x)>>24) | (((x) & 0x00FF0000)>>8) | (((x) & 0x0000FF00)<<8) | ((x)<<24))
bool SDIOClass::readCID(void* cid) {
// Pito 5/2017
uint32_t s[4];
s[0] = SWAP_UINT32(hsd.CID[0]);
s[1] = SWAP_UINT32(hsd.CID[1]);
s[2] = SWAP_UINT32(hsd.CID[2]);
s[3] = SWAP_UINT32(hsd.CID[3]);
//Serial.println(s[0], HEX);
//Serial.println(s[1], HEX);
//Serial.println(s[2], HEX);
//Serial.println(s[3], HEX);
memcpy(cid, &s, 16); //&SDCardInfo.SD_cid, 16);
return true;
}

bool SDIOClass::readCSD(void* csd) {
// Pito 5/2017
uint32_t s[4];
s[0] = SWAP_UINT32(hsd.CSD[0]);
s[1] = SWAP_UINT32(hsd.CSD[1]);
s[2] = SWAP_UINT32(hsd.CSD[2]);
s[3] = SWAP_UINT32(hsd.CSD[3]);
//Serial.println(hsd.CSD[0], HEX);
//Serial.println(hsd.CSD[1], HEX);
//Serial.println(hsd.CSD[2], HEX);
//Serial.println(hsd.CSD[3], HEX);
memcpy(csd, &s, 16); //&SDCardInfo.SD_csd, 16);
return true;
}


victor_pv
Mon May 15, 2017 5:23 pm
Pito wrote:Another optimized :) version which works as well:
#define SWAP_UINT32(x) (((x)>>24) | (((x) & 0x00FF0000)>>8) | (((x) & 0x0000FF00)<<8) | ((x)<<24))
bool SDIOClass::readCID(void* cid) {
// Pito 5/2017
uint32_t s[4];
s[0] = SWAP_UINT32(hsd.CID[0]);
s[1] = SWAP_UINT32(hsd.CID[1]);
s[2] = SWAP_UINT32(hsd.CID[2]);
s[3] = SWAP_UINT32(hsd.CID[3]);
//Serial.println(s[0], HEX);
//Serial.println(s[1], HEX);
//Serial.println(s[2], HEX);
//Serial.println(s[3], HEX);
memcpy(cid, &s, 16); //&SDCardInfo.SD_cid, 16);
return true;
}

bool SDIOClass::readCSD(void* csd) {
// Pito 5/2017
uint32_t s[4];
s[0] = SWAP_UINT32(hsd.CSD[0]);
s[1] = SWAP_UINT32(hsd.CSD[1]);
s[2] = SWAP_UINT32(hsd.CSD[2]);
s[3] = SWAP_UINT32(hsd.CSD[3]);
//Serial.println(hsd.CSD[0], HEX);
//Serial.println(hsd.CSD[1], HEX);
//Serial.println(hsd.CSD[2], HEX);
//Serial.println(hsd.CSD[3], HEX);
memcpy(csd, &s, 16); //&SDCardInfo.SD_csd, 16);
return true;
}


Pito
Mon May 15, 2017 6:18 pm
Yes, the solution is to swap the endianess of the four uint32 in the hsd.CID[] and hsd.CSD[].
I can try with 1bit mode, sure.
As of today my two Sammies CL10 UHS-I either freeze at sd.begin() or throw an error “card not formatted” with 4bit mode.

Pito
Mon May 15, 2017 7:08 pm
This is SDIO in 1bit mode with Sammy 8GB CL10 (and the same with 16GB CL10):
File size 5 MB
Buffer size 65536 bytes
Starting write test, please wait.

write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
2666.35,51553,23531,24512
2720.23,34257,23539,24020

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
2889.06,24517,22623,22687
2890.73,23701,22624,22666


victor_pv
Mon May 15, 2017 7:48 pm
Pito wrote:This is SDIO in 1bit mode with Sammy 8GB CL10 (and the same with 16GB CL10):
File size 5 MB
Buffer size 65536 bytes
Starting write test, please wait.

write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
2666.35,51553,23531,24512
2720.23,34257,23539,24020

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
2889.06,24517,22623,22687
2890.73,23701,22624,22666


Pito
Mon May 15, 2017 8:15 pm
This is for the Sammy CL10 16GB – CSD from SdCardInfo.SD_csd (4bit mode):

CSD Sammy 16GB.JPG
CSD Sammy 16GB.JPG (130.95 KiB) Viewed 279 times

Pito
Mon May 15, 2017 8:33 pm
While stepping through it usually stops looping here:
/* In case of single block transfer, no need of stop transfer at all */
#ifdef SDIO_STA_STBITERR
while(!__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND | SDIO_FLAG_STBITERR))
#else /* SDIO_STA_STBITERR not defined */
while(!__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND))
#endif /* SDIO_STA_STBITERR */
{
if (__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_FLAG_RXFIFOHF)) <<<<<<<<<<<<<< line 572 ..hal_cd.c

Pito
Mon May 15, 2017 10:27 pm
In meantime I copied file A to B with SDIO 4bit on Sandisk 4G CL4, 32kB buffer.
10MB A copied in 6.1secs, worked 3 times ok, the hashes matched.
100MB A copied in 45.6secs, worked only once out of 3 attempts, but the hash did not match :)

victor_pv
Mon May 15, 2017 10:44 pm
Pito wrote:While stepping through it usually stops looping here:
/* In case of single block transfer, no need of stop transfer at all */
#ifdef SDIO_STA_STBITERR
while(!__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND | SDIO_FLAG_STBITERR))
#else /* SDIO_STA_STBITERR not defined */
while(!__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND))
#endif /* SDIO_STA_STBITERR */
{
if (__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_FLAG_RXFIFOHF)) <<<<<<<<<<<<<< line 572 ..hal_cd.c

Pito
Tue May 16, 2017 8:33 am
With Hardware flow control enabled I get errors with all my cards, usually
Type any character to start
FreeStack: 60211
Invalid format, reformat SD.

victor_pv
Tue May 16, 2017 2:27 pm
Pito wrote:With Hardware flow control enabled I get errors with all my cards, usually
Type any character to start
FreeStack: 60211
Invalid format, reformat SD.

victor_pv
Wed May 17, 2017 1:54 pm
Just found the instruction to do the byte swap (for cid and csd).
In thumb assemble in REV, in gcc there is a builtin instruction that will translate to the right assembler instruction:
a = __builtin_bswap32(a);

Pito
Wed May 17, 2017 2:01 pm
I’ve tried with 1bit SDIO mode – 100MB and 1.5GB copy (Black F407ZET, the SDIO socket on the board). With Samsung CL10 it copied 1MB/s speed (24MHz SDIO clock), and the hashes match.
Now why the 4bit mode fails?

ag123
Wed May 17, 2017 2:05 pm
is this sdfat’s sdio mode? i think the f4 hardware also have hardware sdio, but i’m not too sure how that’d work, but i’d guess the ‘HAL’ libraries would be needed for that. my guess is it may be necessary to review the schematics to see if indeed the sd card slot is wired correctly for sdio

anyother way could be to see if there is a way to call the HAL sdio say from sdfat, presumbly it would be faster and if it is a bug (in sdfat), that may diagnose it. i’ve gone around the webs and find that there are indeed some codes in which it provide rather simple hooks to connect ST’s usb mass storage middle ware stack to stm32 sdio hardware via hal. hence, there may possibly be a way for sdfat to use it as well


Pito
Wed May 17, 2017 2:22 pm
@ag123 – it works with F4 HW SDIO, the Sdfat calls SDIO driver which works via HAL with HW (1bit or 4bit).

Pito
Wed May 17, 2017 2:32 pm
Pito wrote:I’ve tried with 1bit SDIO mode – 100MB and 1.5GB copy (Black F407ZET, the SDIO socket on the board). With Samsung CL10 it copied 1MB/s speed (24MHz SDIO clock), and the hashes match.
Now why the 4bit mode fails?

stevestrong
Wed May 17, 2017 2:40 pm
Extract from F4 errata sheet:
2.12 SDIO peripheral limitations
2.12.1 SDIO HW flow control
Description
When enabling the HW flow control by setting bit 14 of the SDIO_CLKCR register to ‘1’,
glitches can occur on the SDIOCLK output clock resulting in wrong data to be written into
the SD/MMC card or into the SDIO device. As a consequence, a CRC error will be reported
to the SD/SDIO MMC host interface (DCRCFAIL bit set to ‘1’ in SDIO_STA register).
Workaround
None.
Note: Do not use the HW flow control. Overrun errors (Rx mode) and FIFO underrun (Tx mode)
should be managed by the application software.

Pito
Wed May 17, 2017 2:52 pm
Pito wrote:Pito wrote:I’ve tried with 1bit SDIO mode – 100MB and 1.5GB copy (Black F407ZET, the SDIO socket on the board). With Samsung CL10 it copied 1MB/s speed (24MHz SDIO clock), and the hashes match.
Now why the 4bit mode fails?

Pito
Wed May 17, 2017 2:54 pm
stevestrong wrote:Extract from F4 errata sheet:
..
Conclusion: Do not use the HW flow control.

racemaniac
Wed May 17, 2017 2:59 pm
did you configure the pullups on the pins for the 4 bit communication? (or do you have external pullups?)

Pito
Wed May 17, 2017 3:05 pm
There are external 10k pullups at all signals, socket on the board.
Black F407ZET board: http://www.stm32duino.com/viewtopic.php … =30#p22456

danieleff
Wed May 17, 2017 3:15 pm
In SDIO.cpp, does the line
error = HAL_SD_WideBusOperation_Config(&hsd, SDIO_BUS_WIDE_4B);

Pito
Wed May 17, 2017 3:24 pm
Black F407ZET board

SDIO 1bit Copy.JPG
SDIO 1bit Copy.JPG (32.87 KiB) Viewed 278 times

Pito
Wed May 17, 2017 3:29 pm
danieleff wrote:In SDIO.cpp, does the line
error = HAL_SD_WideBusOperation_Config(&hsd, SDIO_BUS_WIDE_4B);

danieleff
Wed May 17, 2017 3:59 pm
It would be helpful to put into SDIO.cpp after every `if (error != SD_OK) {` a Serial.print(error), because it can give you a bunch of codes https://github.com/danieleff/STM32GENER … _sd.h#L221
Instead of a generic “error: open failed”

Pito
Wed May 17, 2017 4:17 pm
I added the printing out of the error codes into SDIO.cpp.
Here is the error I get with 2x CL10 Samsungs when the 4bit mode is enabled (HW flow ctrl disabled) :
Use a freshly formatted SD for best performance.
Type any character to start

HAL_SD_ReadBlocks Error: 2
Invalid format, reformat SD.


Pito
Wed May 17, 2017 5:36 pm
I added a loop counter inside the SDIOClass::readBlocks and for example I get a bit different sequence (the file to be opened is on the card), Samsung CL10:
Use a freshly formatted SD for best performance.
Type any character to start

Loop: 0
Loop: 1
Opening the read file..
Loop: 2
HAL_SD_ReadBlocks Error: 2
error: opening test_in.bin for Read failed

Use a freshly formatted SD for best performance.
Type any character to start

HAL_SD_Init Error: 3
Can't access SD card. Do not reformat.
SD errorCode: 0X64,0X0


Pito
Wed May 17, 2017 7:27 pm
With the Sandisk CL10 it works “somehow” in 4bit mode so I added the first 4bits copy test result:

SDIO 1bit and 4bit Copy.JPG
SDIO 1bit and 4bit Copy.JPG (59.61 KiB) Viewed 781 times

victor_pv
Wed May 17, 2017 8:45 pm
stevestrong wrote:Extract from F4 errata sheet:
2.12 SDIO peripheral limitations
2.12.1 SDIO HW flow control
Description
When enabling the HW flow control by setting bit 14 of the SDIO_CLKCR register to ‘1’,
glitches can occur on the SDIOCLK output clock resulting in wrong data to be written into
the SD/MMC card or into the SDIO device. As a consequence, a CRC error will be reported
to the SD/SDIO MMC host interface (DCRCFAIL bit set to ‘1’ in SDIO_STA register).
Workaround
None.
Note: Do not use the HW flow control. Overrun errors (Rx mode) and FIFO underrun (Tx mode)
should be managed by the application software.

victor_pv
Wed May 17, 2017 11:00 pm
Pito wrote:
With 42MHz SDIO clk it throws errors:
Use a freshly formatted SD for best performance.
Type any character to start

Opening the read file..
Opening the write file..
Reading and Writing..
HAL_SD_WriteBlocks Error: 5
HAL_SD_WriteBlocks Error: 3
HAL_SD_WriteBlocks Error: 16
HAL_SD_WriteBlocks Error: 5
HAL_SD_WriteBlocks Error: 3
HAL_SD_WriteBlocks Error: 16
HAL_SD_WriteBlocks Error: 3
HAL_SD_WriteBlocks Error: 3
..
HAL_SD_WriteBlocks Error: 3


danieleff
Thu May 18, 2017 4:03 am
victor_pv wrote:From what I have read, I think we need to confirm before reads or writes that the card is ready to actually accept data. And once a write is completed, read the card status and confirm there were no errors, and retry if needed.
But perhaps SDFat already provides for some retry. It’s kind of complicated to track it all with so many layers.

victor_pv
Thu May 18, 2017 4:33 am
danieleff wrote:victor_pv wrote:From what I have read, I think we need to confirm before reads or writes that the card is ready to actually accept data. And once a write is completed, read the card status and confirm there were no errors, and retry if needed.
But perhaps SDFat already provides for some retry. It’s kind of complicated to track it all with so many layers.

danieleff
Thu May 18, 2017 5:27 am
OK I see what you mean. Yes, copy parts of HAL code, and use that. As you said it might break different series, so as default use `#define sdioex sdio`, and for F4 use parts of the F4 HAL. This way it will work. And for other series, only do this is somebody can actually test.

But first concentrate on the error.


Pito
Thu May 18, 2017 9:00 am
It would be great if someone else did the tests with SDIO too.
Here is the “COPY TEST” I published on this forum a year back – here the version with SDIO.
Simply copy a file of “any size” to the Sdcard, rename it to “test_in.bin”. After the running the sketch it copies the test_in.bin into the “test_out.bin”.
Compare the hashes to check whether the copy went well.
Note: you want Victor’s SDIO lib files from here
https://github.com/victorpv/STM32GENERI … s/SDIO/src
https://github.com/victorpv/STM32GENERI … 07VE/Bench
Also you need SdFat lib too.

/*
SDcard SDIO example - Copy Test - copy binaries
Buffer of BUFSIZE bytes is used for writing.
You have to place a binary called "test_in.bin" on the SDcard and run the sketch.
You will get the "test_out.bin" after the copy finishes.
Pito 5/2016, no warranties of any kind
Pito 5/2017, no warranties of any kind
*/
#include "SDIO.h"
#include "STM32SdFatSdio.h"

STM32SdFatSdio sd;
SdFile myFileIn;
SdFile myFileOut;

#define BUFSIZE 32*1024

// Serial output stream
ArduinoOutStream cout(Serial);

void setup() {
Serial.begin(115200);
delay(1000);
cout << F("\nUse a freshly formatted SD for best performance.\n");
// Discard any input.
do {
delay(10);
} while (Serial.available() && Serial.read() >= 0);

Serial.println("Type any character to start\n");
while (!Serial.available()) {
SysCall::yield();
}

if (!sd.begin()) {
sd.initErrorHalt();
}
Serial.println("*************************************************");
Serial.println("Opening the read file..");
// open the file for Read
if (!myFileIn.open("test_in.bin", O_RDONLY)) {
sd.errorHalt("opening test_in.bin for Read failed");
}

Serial.println("Opening the write file..");
// open the file for Write
if (!myFileOut.open("test_out.bin", O_WRITE | O_CREAT)) {
sd.errorHalt("opening test_out.bin for Write failed");
}

// Read from myFileIn and write to myFileOut via a Buffer
Serial.println("Reading and Writing..");
uint8_t buf[BUFSIZE];
uint32_t nr;
uint32_t t = millis();
while ((nr = myFileIn.read(buf, BUFSIZE)) > 0) {
if (nr < BUFSIZE){
myFileOut.write(buf, nr); }
else {
myFileOut.write(buf, BUFSIZE); }
}
t = millis() - t;
// close the files
myFileIn.close();
myFileOut.close();
Serial.println("*************************************************");
Serial.print("Done in ");
Serial.print(t);
Serial.print(" msecs");
}

void loop() {
}


stevestrong
Thu May 18, 2017 9:42 am
Can someone please provide a binary file for black F407VE board? Then I would test it, too.

stevestrong
Thu May 18, 2017 9:47 am
Btw, in the errata sheet there are several other SDIO-related issues which would force the software to:
Workaround
The CCRCFAIL bit in the SDIO_STA register shall be ignored by the software. CCRCFAIL
must be cleared by setting CCRCFAILC bit of the SDIO_ICR register after reception of the
response to the CMD5 command.

danieleff
Thu May 18, 2017 10:26 am
Given that for example readBlocks just calls HAL_SD_ReadBlocks and thats it, I hope those issues are fixed in HAL. (except maybe clock setup).

Which reminds me, there are actually newer HAL firmware versions for the series, so I will upgrade them when I get home; that may help too.


Pito
Thu May 18, 2017 10:37 am
stevestrong wrote:Can someone please provide a binary file for black F407VE board? Then I would test it, too.

victor_pv
Thu May 18, 2017 2:08 pm
Error 2 is a CRC one.
The error codes are defined as HAL_SD_ErrorTypedef, which is in f4xx_hal_sd.h

I have been doing some testing, but bench doesn’t fail on me.
Now, I have been going thru the HAL calls to see what checks and timeouts are there.

Once the DMA transfer has started, the next thing is wait on this to return ok or an error: HAL_SD_CheckWriteOperation
On that function the valid outcomes are a timeout, an error, or OK. I suspect the timeouts are probably reported by that one.
The one called before that, so start the DMA, may error out before starting the actual transfer if the card is not in a valid state for it.

So I suspect when a transfer goes wrong because it takes too long or something, you may be getting the timeout, and next the illegal command.

I have run the bench a bunch of times, but it just doesn’t fail with my cl4 card, so I can’t see where any error comes from. I need to find a cl10 so I can repeat the tests.

The new test sketch from Pito should help. I will post my current code to github so we are all in sync for a start.

Regarding the HAL updates. The core F4 HAL is from 2016. The new HAL from April 2017 has a lot of changes. Different functions, function names, returns. There must be a reason for such major changes. Most likely will result in breaking compatibility with the F1 or others that have not been updated in a while, but if we need to write 2 libraries to get them stable, then better than a single one with issues.

I have some F3 chips waiting for bluepills to arrive to do a transplant, once done I can test F3.


Pito
Thu May 18, 2017 2:11 pm
Do we use DMA? Based on the Copy results it seems to me we do not (doubling the clock results in 1.6x only).

victor_pv
Thu May 18, 2017 2:12 pm
Pito wrote:Do we use DMA? Based on the Copy results it seems to me we do not.

Pito
Thu May 18, 2017 2:22 pm
victor_pv wrote:..
I have run the bench a bunch of times, but it just doesn’t fail with my cl4 card, so I can’t see where any error comes from. I need to find a cl10 so I can repeat the tests…

victor_pv
Thu May 18, 2017 2:26 pm
Pito wrote:victor_pv wrote:..
I have run the bench a bunch of times, but it just doesn’t fail with my cl4 card, so I can’t see where any error comes from. I need to find a cl10 so I can repeat the tests…

danieleff
Thu May 18, 2017 5:13 pm
victor_pv wrote:
Regarding the HAL updates. The core F4 HAL is from 2016. The new HAL from April 2017 has a lot of changes. Different functions, function names, returns. There must be a reason for such major changes. Most likely will result in breaking compatibility with the F1 or others that have not been updated in a while, but if we need to write 2 libraries to get them stable, then better than a single one with issues.

victor_pv
Thu May 18, 2017 6:14 pm
danieleff wrote:victor_pv wrote:
Regarding the HAL updates. The core F4 HAL is from 2016. The new HAL from April 2017 has a lot of changes. Different functions, function names, returns. There must be a reason for such major changes. Most likely will result in breaking compatibility with the F1 or others that have not been updated in a while, but if we need to write 2 libraries to get them stable, then better than a single one with issues.

victor_pv
Thu May 18, 2017 6:23 pm
Pito wrote:victor_pv wrote:..
I have run the bench a bunch of times, but it just doesn’t fail with my cl4 card, so I can’t see where any error comes from. I need to find a cl10 so I can repeat the tests…

stevestrong
Fri May 19, 2017 12:46 pm
Just found it on the net, maybe this helps somehow:
https://blog.frankvh.com/2011/09/04/stm … interface/

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/
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


Pito
Fri May 19, 2017 3:25 pm
Great! So typical errors are 2, 3, 5, 16.

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
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
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:

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
Fri May 19, 2017 4:16 pm
why not trying to copy the ESP8266 Teensy driver of the SdFat beta lib?

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?

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


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.

ag123
Fri May 19, 2017 5:23 pm
i think the simplified specs and available docs ‘out there’ makes SD over SPI and 1 pin sdio works, somehow the 4 pins ‘high speed’ variety which according to the simplified specs is ‘mandatory’ isn’t public, we could only assume that 4 pins would work the same way as 1 pin, i guess that is a possible ‘catch’ about it

i think one of the better sites about the 4 pin sdio is this
https://yannik520.github.io/sdio.html
i’m yet to find any better resource for it on google


victor_pv
Fri May 19, 2017 7:13 pm
stevestrong wrote:Victor, can you provide the black F407VET board BIN file for testing? I have a 16GB CL10 card.

stevestrong
Fri May 19, 2017 8:18 pm
First attempt:
FreeStack: 125615
Type is FAT32
Card size: 15.93 GB (GB = 1E9 bytes)

Manufacturer ID: 0X3
OEM ID: SD
Product: SL16G
Version: 8.0
Serial number: 0X72F2CA43
Manufacturing date: 8/2015

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
336.72,58116,888,1519
425.03,76534,888,1203

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
2187.09,3711,216,233
2190.92,442,216,233

Done
Type any character to start


victor_pv
Fri May 19, 2017 8:45 pm
stevestrong wrote:First attempt:
FreeStack: 125615
Type is FAT32
Card size: 15.93 GB (GB = 1E9 bytes)

Manufacturer ID: 0X3
OEM ID: SD
Product: SL16G
Version: 8.0
Serial number: 0X72F2CA43
Manufacturing date: 8/2015

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
336.72,58116,888,1519
425.03,76534,888,1203

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
2187.09,3711,216,233
2190.92,442,216,233

Done
Type any character to start


Pito
Sat May 20, 2017 6:38 am
You must have 32kB buffer with SDIO to see higher speeds.

Pito
Sat May 20, 2017 9:59 am
With CL10 Samsung and Sandisk:
Use a freshly formatted SD for best performance.

Type any character to start
FreeStack: 125615
Can't access SD card. Do not reformat.
SD errorCode: 0X64,0X0


victor_pv
Sat May 20, 2017 2:05 pm
Pito wrote:With CL10 Samsung and Sandisk:
Use a freshly formatted SD for best performance.

Type any character to start
FreeStack: 125615
Can't access SD card. Do not reformat.
SD errorCode: 0X64,0X0


Pito
Sat May 20, 2017 4:29 pm
Where did you add the code to show the error codes? let’s add that to the bench test to see what kind of errors are we getting.
http://www.stm32duino.com/viewtopic.php … =90#p28184

victor_pv
Sat May 20, 2017 10:58 pm
Pito wrote:Where did you add the code to show the error codes? let’s add that to the bench test to see what kind of errors are we getting.
http://www.stm32duino.com/viewtopic.php … =90#p28184

danieleff
Sun May 21, 2017 6:35 am
It it strange but it only works if I set _useDMA = true;
with _useDMA = false;, I get write errors:

FreeStack: 125619
Type is FAT32
Card size: 7.78 GB (GB = 1E9 bytes)

Manufacturer ID: 0X2
OEM ID: TM
Product: SA08G
Version: 2.2
Serial number: 0XD1C17F26
Manufacturing date: 6/2010

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
HAL_SD_WriteBlocks error, hsd.ErrorCode: 4
error: write failed
HAL_SD_WriteBlocks error, hsd.ErrorCode: 4
Type any character to start


Pito
Sun May 21, 2017 6:58 am
victor_pv wrote:Pito wrote:Where did you add the code to show the error codes? let’s add that to the bench test to see what kind of errors are we getting.
http://www.stm32duino.com/viewtopic.php … =90#p28184

danieleff
Sun May 21, 2017 6:59 am
If I put `while (HAL_SD_GetCardState(&hsd) == HAL_SD_CARD_PROGRAMMING);` into the no-dma part of `SDIOClass::writeBlocks` (just like the dma part), noDMA also works:

FreeStack: 93359
Type is FAT32
Card size: 7.78 GB (GB = 1E9 bytes)

Manufacturer ID: 0X2
OEM ID: TM
Product: SA08G
Version: 2.2
Serial number: 0XD1C17F26
Manufacturing date: 6/2010

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
4552.77,295514,4348,6926
6623.32,12115,4344,4685

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
8617.19,4376,3763,3803
8602.31,4372,3673,3804

Done
Type any character to start


Pito
Sun May 21, 2017 8:21 am
useDMA true (Samsung CL10 16GB):
Use a freshly formatted SD for best performance.

Type any character to start
FreeStack: 60907
Invalid format, reformat SD.

Use a freshly formatted SD for best performance.

Type any character to start
FreeStack: 60907
HAL_SD_WideBusOperation_Config Error: 1
Can't access SD card. Do not reformat.
SD errorCode: 0X64,0X0


victor_pv
Sun May 21, 2017 10:16 pm
Pito wrote:useDMA true (Samsung CL10 16GB):
Use a freshly formatted SD for best performance.

Type any character to start
FreeStack: 60907
Invalid format, reformat SD.

Use a freshly formatted SD for best performance.

Type any character to start
FreeStack: 60907
HAL_SD_WideBusOperation_Config Error: 1
Can't access SD card. Do not reformat.
SD errorCode: 0X64,0X0


danieleff
Mon May 22, 2017 7:26 am
victor_pv wrote:
Daniel, if you want to merge the SDIO files to your branch we can do that too. I haven’t sent a PR because I have not looked yet and what you did for the F7, so I din’t want to overwrite anything with my changes that may be needed for the F7, and I’m working off the version that was not split in series yet.

victor_pv
Mon May 22, 2017 5:15 pm
danieleff wrote:victor_pv wrote:
Daniel, if you want to merge the SDIO files to your branch we can do that too. I haven’t sent a PR because I have not looked yet and what you did for the F7, so I din’t want to overwrite anything with my changes that may be needed for the F7, and I’m working off the version that was not split in series yet.

victor_pv
Wed May 24, 2017 3:37 pm
danieleff wrote:victor_pv wrote:
Daniel, if you want to merge the SDIO files to your branch we can do that too. I haven’t sent a PR because I have not looked yet and what you did for the F7, so I din’t want to overwrite anything with my changes that may be needed for the F7, and I’m working off the version that was not split in series yet.

danieleff
Wed May 24, 2017 4:42 pm
victor_pv wrote:
Can we check in begin() whether the card is already in the right state before trying? either that, or send the go_idle command at the start, which is the closest to a rest that I find in the specifications.

victor_pv
Wed May 24, 2017 6:59 pm
danieleff wrote:victor_pv wrote:
Can we check in begin() whether the card is already in the right state before trying? either that, or send the go_idle command at the start, which is the closest to a rest that I find in the specifications.

victor_pv
Thu May 25, 2017 5:53 am
Updated a few things in the SDIO files, and added CRC calculation to the copytest sketch from Pito, so it reads back and calculates the CRC of the In and Out files and compares them.
It also runs in a loop now, so if you dont get an error, you can run it again and again.
I took the serial read out, to let the test repeat over and over and run about 10 times in a 15MB file with no errors.

Would be great if anyone that had errors so far gave it a shot.
The files are in my branch, in the first post of the thread.


danieleff
Thu May 25, 2017 6:23 am
victor_pv wrote:
The files are in my branch, in the first post of the thread.

Pito
Thu May 25, 2017 8:13 am
Use SdFat from github
https://github.com/greiman/SdFat
instead of the SdFat-beta. The beta is old and has been merged to SdFat a month ago.

stevestrong
Thu May 25, 2017 8:14 am
Pito wrote:Use SdFat from github instead of the SdFat-beta. The beta is old and has been merged to SdFat a month ago.

victor_pv
Thu May 25, 2017 1:19 pm
danieleff wrote:victor_pv wrote:
The files are in my branch, in the first post of the thread.

Pito
Thu May 25, 2017 2:02 pm
Interesting reading on some SDIO issues and workarounds:
https://blog.frankvh.com/2011/09/04/stm … interface/
https://blog.frankvh.com/2011/12/30/stm … ce-part-2/

victor_pv
Thu May 25, 2017 3:22 pm
Pito wrote:Interesting reading on some SDIO issues and workarounds:
https://blog.frankvh.com/2011/09/04/stm … interface/
https://blog.frankvh.com/2011/12/30/stm … ce-part-2/

danieleff
Thu May 25, 2017 3:30 pm
(SDIO/examples/copytest does not have the STM32SdFatSdio.h, and Arduino IDE somehow does not want to compile CRC32 subdirectory)
Otherwise, 100mb test_in.bin seems ok:

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

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

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

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

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

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

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

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

*************************************************
Opening the read file..
Opening the write file..
Reading and Writing..
*************************************************
Done in 44626 msecs
*************************************************
Running CRC calculations...


victor_pv
Thu May 25, 2017 5:37 pm
danieleff wrote:(SDIO/examples/copytest does not have the STM32SdFatSdio.h, and Arduino IDE somehow does not want to compile CRC32 subdirectory)
Otherwise, 100mb test_in.bin seems ok:

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

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

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

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

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

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

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

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

*************************************************
Opening the read file..
Opening the write file..
Reading and Writing..
*************************************************
Done in 44626 msecs
*************************************************
Running CRC calculations...


ag123
Fri May 26, 2017 9:42 am
do you happen to have a binary of it? i’d try it out as well ;)

victor_pv
Fri May 26, 2017 1:31 pm
This is the copy test sketch including CRC calculations.
If you press a key it will run, and at the end you can press a key again and run another pass.
In each pass will delete the output file and create a new one.

sdio_bin_test.zip
(22.42 KiB) Downloaded 13 times

ag123
Fri May 26, 2017 2:21 pm
thanks victor,

100 megs (102400000 bytes) test_in.bin
strontium branded uSD card class 10 16GB
http://www.strontium.biz/products/memor … ory-cards/
Reading, Writing and calculating CRC of In file...
*************************************************
Done in 61185 msecs
*************************************************
Running CRC calculation on Out file...
File in CRC: 638C64C3
File out CRC: 638C64C3
*************************************************
Done in 33304 msecs


victor_pv
Fri May 26, 2017 2:35 pm
ag123 wrote:thanks victor,

100 megs (102400000 bytes) test_in.bin
strontium branded uSD card class 10 16GB
http://www.strontium.biz/products/memor … ory-cards/
Reading, Writing and calculating CRC of In file...
*************************************************
Done in 61185 msecs
*************************************************
Running CRC calculation on Out file...
File in CRC: 638C64C3
File out CRC: 638C64C3
*************************************************
Done in 33304 msecs


ag123
Fri May 26, 2017 2:37 pm
oops, it seemed the card is corrupted, this is caught in my linux dmesg system log
[ 4085.713867] sdc: sdc1
[ 4087.396831] FAT-fs (sdc1): error, invalid access to FAT (entry 0x0f006300)
[ 4087.396837] FAT-fs (sdc1): Filesystem has been set read-only
[ 4098.257323] FAT-fs (sdc1): error, invalid access to FAT (entry 0x0f006300)
[ 4098.257327] FAT-fs (sdc1): Filesystem has been set read-only
[ 4104.627274] FAT-fs (sdc1): error, invalid access to FAT (entry 0x0f006300)
[ 4104.627277] FAT-fs (sdc1): Filesystem has been set read-only
[ 4117.426892] sd 6:0:0:0: [sdc] 31211520 512-byte logical blocks: (15.9 GB/14.8 GiB)
[ 4117.430519] sdc: sdc1
[ 4119.329292] FAT-fs (sdc1): error, invalid access to FAT (entry 0x0f006300)
[ 4119.329295] FAT-fs (sdc1): Filesystem has been set read-only

victor_pv
Fri May 26, 2017 2:41 pm
ag123 wrote:oops, it seemed the card is corrupted, this is caught in my linux dmesg system log
[ 4085.713867] sdc: sdc1
[ 4087.396831] FAT-fs (sdc1): error, invalid access to FAT (entry 0x0f006300)
[ 4087.396837] FAT-fs (sdc1): Filesystem has been set read-only
[ 4098.257323] FAT-fs (sdc1): error, invalid access to FAT (entry 0x0f006300)
[ 4098.257327] FAT-fs (sdc1): Filesystem has been set read-only
[ 4104.627274] FAT-fs (sdc1): error, invalid access to FAT (entry 0x0f006300)
[ 4104.627277] FAT-fs (sdc1): Filesystem has been set read-only
[ 4117.426892] sd 6:0:0:0: [sdc] 31211520 512-byte logical blocks: (15.9 GB/14.8 GiB)
[ 4117.430519] sdc: sdc1
[ 4119.329292] FAT-fs (sdc1): error, invalid access to FAT (entry 0x0f006300)
[ 4119.329295] FAT-fs (sdc1): Filesystem has been set read-only

ag123
Fri May 26, 2017 2:43 pm
there may be some prior fat errors on the card. hence, we’d ignore it for now, going to re-run a new test
100 megs (102400000 bytes) test_in.bin
strontium branded uSD card class 10 16GB
*************************************************
Opening the read file..
Opening the write file..
Reading, Writing and calculating CRC of In file...
*************************************************
Done in 60094 msecs
*************************************************
Running CRC calculation on Out file...
File in CRC: 94130507
File out CRC: 94130507
*************************************************
Done in 33315 msecs

ag123
Fri May 26, 2017 3:11 pm
victor_pv wrote:
Can you run it a few times in a row to see if it fails any time?
I have also discovered that if I let the sketch waiting for a few minutes, the card seems to go to idle, which would need another command to get it in transfer mode again. If you could test that, would be good to confirm it is normal behavior. Just leave the sketch waiting for a key for a while, maybe 10-15 minutes, then press a key and see if it throws error messages.

BTW, Copy speed is double that, since it’s reading from a file, calculating the CRC of that block, and writing it to the other file.
Since reading and calculating take 33seconds in the second file, we can subtract that from the first time to estimate the time spent writing, so about 102,400,000 /28 ~ 3.67 MB writing speed :)


Pito
Fri May 26, 2017 3:54 pm
I do not know how it is with SDIO, but in SPI the SDcard goes in idle immediately after deselected (CS=1) and then it takes 200uA current typically.

victor_pv
Fri May 26, 2017 4:02 pm
Pito wrote:I do not know how it is with SDIO, but in SPI the SDcard goes in idle immediately after deselected (CS=1) and then it takes 200uA current typically.

victor_pv
Fri May 26, 2017 4:03 pm
ag123 wrote:victor_pv wrote:
Can you run it a few times in a row to see if it fails any time?
I have also discovered that if I let the sketch waiting for a few minutes, the card seems to go to idle, which would need another command to get it in transfer mode again. If you could test that, would be good to confirm it is normal behavior. Just leave the sketch waiting for a key for a while, maybe 10-15 minutes, then press a key and see if it throws error messages.

BTW, Copy speed is double that, since it’s reading from a file, calculating the CRC of that block, and writing it to the other file.
Since reading and calculating take 33seconds in the second file, we can subtract that from the first time to estimate the time spent writing, so about 102,400,000 /28 ~ 3.67 MB writing speed :)


Pito
Fri May 26, 2017 4:06 pm
First attempt with your latest binary above, Sammy 16GB, CL10, UHS-I card, formatted, no file on sdcard:
Use a freshly formatted SD for best performance.
Type any character to start

State value (HAL_SD_STATE...): 1
Errorcode value (HAL_SD_ERROR...): 2
R1 value: 100100000000
HAL Return value (HAL_...): 0
C:\Users\Victor\Documents\Arduino\Hardware\STM32GENERIC\STM32\libraries\SDIO\src\SDIO.cpp
168
readBlocks
Timeout on Read, over 100ms
Invalid format, reformat SD.


ag123
Fri May 26, 2017 6:16 pm
i think i must have mixed up sequences while i test, testing with a 32 megs file class 10 strongtium branded uSD card, the board tested with is black stm32f407vet6 using the on board uSD slot :P
i waited for a while between runs but did not reproduce the error i got earlier.Use a freshly formatted SD for best performance.
Type any character to start

*************************************************
Opening the read file..
error: opening test_in.bin for Read failed
*************************************************
Opening the read file..
Opening the write file..
Reading, Writing and calculating CRC of In file...
*************************************************
Done in 19895 msecs
*************************************************
Running CRC calculation on Out file...
File in CRC: 9D29D540
File out CRC: 9D29D540
*************************************************
Done in 10897 msecs
Type any character to start

*************************************************
Opening the read file..
Opening the write file..
Reading, Writing and calculating CRC of In file...
*************************************************
Done in 19139 msecs
*************************************************
Running CRC calculation on Out file...
File in CRC: 9D29D540
File out CRC: 9D29D540
*************************************************
Done in 10885 msecs


victor_pv
Fri May 26, 2017 6:41 pm
(HAL_SD_ERROR…):
#define SDMMC_ERROR_NONE 0x00000000U /*!< No error */
#define SDMMC_ERROR_CMD_CRC_FAIL 0x00000001U /*!< Command response received (but CRC check failed) */
#define SDMMC_ERROR_DATA_CRC_FAIL 0x00000002U /*!< Data block sent/received (CRC check failed) */
#define SDMMC_ERROR_CMD_RSP_TIMEOUT 0x00000004U /*!< Command response timeout */
#define SDMMC_ERROR_DATA_TIMEOUT 0x00000008U /*!< Data timeout */
#define SDMMC_ERROR_TX_UNDERRUN 0x00000010U /*!< Transmit FIFO underrun */
#define SDMMC_ERROR_RX_OVERRUN 0x00000020U /*!< Receive FIFO overrun */
#define SDMMC_ERROR_ADDR_MISALIGNED 0x00000040U /*!< Misaligned address */
#define SDMMC_ERROR_BLOCK_LEN_ERR 0x00000080U /*!< Transferred block length is not allowed for the card or the
number of transferred bytes does not match the block length */
#define SDMMC_ERROR_ERASE_SEQ_ERR 0x00000100U /*!< An error in the sequence of erase command occurs */
#define SDMMC_ERROR_BAD_ERASE_PARAM 0x00000200U /*!< An invalid selection for erase groups */
#define SDMMC_ERROR_WRITE_PROT_VIOLATION 0x00000400U /*!< Attempt to program a write protect block */
#define SDMMC_ERROR_LOCK_UNLOCK_FAILED 0x00000800U /*!< Sequence or password error has been detected in unlock
command or if there was an attempt to access a locked card */
#define SDMMC_ERROR_COM_CRC_FAILED 0x00001000U /*!< CRC check of the previous command failed */
#define SDMMC_ERROR_ILLEGAL_CMD 0x00002000U /*!< Command is not legal for the card state */
#define SDMMC_ERROR_CARD_ECC_FAILED 0x00004000U /*!< Card internal ECC was applied but failed to correct the data */
#define SDMMC_ERROR_CC_ERR 0x00008000U /*!< Internal card controller error */
#define SDMMC_ERROR_GENERAL_UNKNOWN_ERR 0x00010000U /*!< General or unknown error */
#define SDMMC_ERROR_STREAM_READ_UNDERRUN 0x00020000U /*!< The card could not sustain data reading in stream rmode */
#define SDMMC_ERROR_STREAM_WRITE_OVERRUN 0x00040000U /*!< The card could not sustain data programming in stream mode */
#define SDMMC_ERROR_CID_CSD_OVERWRITE 0x00080000U /*!< CID/CSD overwrite error */
#define SDMMC_ERROR_WP_ERASE_SKIP 0x00100000U /*!< Only partial address space was erased */
#define SDMMC_ERROR_CARD_ECC_DISABLED 0x00200000U /*!< Command has been executed without using internal ECC */
#define SDMMC_ERROR_ERASE_RESET 0x00400000U /*!< Erase sequence was cleared before executing because an out
of erase sequence command was received */
#define SDMMC_ERROR_AKE_SEQ_ERR 0x00800000U /*!< Error in sequence of authentication */
#define SDMMC_ERROR_INVALID_VOLTRANGE 0x01000000U /*!< Error in case of invalid voltage range */
#define SDMMC_ERROR_ADDR_OUT_OF_RANGE 0x02000000U /*!< Error when addressed block is out of range */
#define SDMMC_ERROR_REQUEST_NOT_APPLICABLE 0x04000000U /*!< Error when command request is not applicable */
#define SDMMC_ERROR_INVALID_PARAMETER 0x08000000U /*!< the used parameter is not valid */
#define SDMMC_ERROR_UNSUPPORTED_FEATURE 0x10000000U /*!< Error when feature is not insupported */
#define SDMMC_ERROR_BUSY 0x20000000U /*!< Error when transfer process is busy */
#define SDMMC_ERROR_DMA 0x40000000U /*!< Error while DMA transfer */
#define SDMMC_ERROR_TIMEOUT 0x80000000U /*!< Timeout error */

ag123
Fri May 26, 2017 6:56 pm
well, it seem the crc error is alleviated? that’s a pretty good achievement :D
i took a look at pito’s last post, it seem there isn’t CRC errors in those copies
the command timeouts seemed somewhat harder to solve and some of the logics may seem to be needed in the sketch/app itself. e.g. i’m not sure if there may be some commands to probe if the card is idle and redo initialization. but i’d guess that’d need to be done by the sketch/app itself

Pito
Fri May 26, 2017 7:06 pm
I think there is something missing with init sequence. Those crc errors are not because of the wiring, but missing init commands. I would recommend to compare all the commands required with other implementations – like chibios sdio, or others. It has to be done step by step. Also mind the above links – they also mention crc errors as a result of wrong handling.
For example it may happen the Sammy requires CMD6 speed mode to be set properly, while Sandisk maybe not.
So let us compare with other working implementation first, to avoid try-and-error-approach..

victor_pv
Fri May 26, 2017 7:12 pm
Pito wrote:I think there is something missing with init sequence. Those crc errors are not because of the wiring, but missing init commands. I would recommend to compare all the commands required with other implementations – like chibios sdio, or others.

Pito
Fri May 26, 2017 7:24 pm
The fact we have a problem to init the Samsung EVO card is a clear indication there is still a problem..

victor_pv
Fri May 26, 2017 7:24 pm
BTE this R1 response indicates the card is in receive mode, but not ready to get data:
R1 value: 110000000000

victor_pv
Fri May 26, 2017 7:27 pm
Pito wrote:The fact we have a problem to init the Samsung EVO card is a clear indication there is still a problem..

Pito
Fri May 26, 2017 7:29 pm
The timeouts of 100ms is not enough. Let us do 500ms.
The gpio settings must be the highest speed.
I would follow the voltage settings and CMD6 as well, even 50MHz speed is max for 3.3V signalling. The High Speed mode also sets the i/o of the sdcard to a faster setting. Moreover, it seems the 24MHz is high speed already (SDR25).

Here is the quick hack how to put the card into high speed mode via CMD6:
http://www.stm32duino.com/viewtopic.php?t=1053#p12809

CMD6.JPG
CMD6.JPG (85.48 KiB) Viewed 813 times

victor_pv
Fri May 26, 2017 8:24 pm
Pito wrote:The timeouts of 100ms is not enough. Let us do 500ms.
The gpio settings must be the highest speed.
I would follow the voltage settings and CMD6 as well, even 50MHz speed is max for 3.3V signalling. The High Speed mode also sets the i/o of the sdcard to a faster setting. Moreover, it seems the 24MHz is high speed already (SDR25).


ag123
Fri May 26, 2017 8:34 pm
off-topic: in a way perhaps 1 day we could just get nand flash & hack our own SD cards (maybe with stm32 f1-f7 as its controller, no crc errors) :lol:
http://bunniefoo.com/bunnie/sdcard-30c3-pub.pdf
surprisingly u could actually get those nand flash & even some proprietary programmers on ebay :lol:
http://www.ebay.com/sch/i.html?_from=R4 … +&_sacat=0

Pito
Fri May 26, 2017 8:42 pm
@victor – the most of the CMD6 settings works with SDIO and 1.8V signalling only. AFIK the only setting applicable for 3.3V signalling is the High Speed mode setting. The CMD6 reads 64bytes where you get some information.

Max speed – you can set here is 50MHz, as the 25 and 50 are the only supported with 3.3V signalling (we do not have 1.8V signalling with stm32f407).

Power – it is the max power the card may take out of the socket – 0.36W – 2.88Watt, basically it is the current taken from the sdcard’s Vcc source, measured at 3.6V. The SD Spec says the speeds 50MHz and above may require higher max power settings to be set (default for our typical cards is 0.36W/0.72W =100mA/200mA).

Driver strength – the driver strength is applicable for 1.8V signalling only.


victor_pv
Sat May 27, 2017 2:13 pm
Pito wrote:@victor – the most of the CMD6 settings works with SDIO and 1.8V signalling only. AFIK the only setting applicable for 3.3V signalling is the High Speed mode setting. The CMD6 reads 64bytes where you get some information.

Max speed – you can set here is 50MHz, as the 25 and 50 are the only supported with 3.3V signalling (we do not have 1.8V signalling with stm32f407).

Power – it is the max power the card may take out of the socket – 0.36W – 2.88Watt, basically it is the current taken from the sdcard’s Vcc source, measured at 3.6V. The SD Spec says the speeds 50MHz and above may require higher max power settings to be set (default for our typical cards is 0.36W/0.72W =100mA/200mA).

Driver strength – the driver strength is applicable for 1.8V signalling only.


stevestrong
Mon May 29, 2017 9:38 am
A factor of instability, in my experience so far with F4, can be caused by the power supply. SD cards can consume more than 100..150 mA peak value when used in high speed mode (50MHz).

My activity during SPI test with SD cards showed that the results are much more stable if you use a separate 5V power supply for the board, not the one from USB host. Or, you connect to a USB hub supplied by an external adapter. Feeding with external 3.3V (200mA) directly can also improve stability.


ag123
Mon May 29, 2017 9:11 pm
i’m thinking that if the crc errors did not result in data loss, it possibly mean that nak’s and retransmit is done in the protocol & algorithm.
that would still be ok.

but if the crc errors result in data loss, something is wrong in the protocol / algorithm perhaps.

crc errors can happen if either the sd card is ‘too slow’ or that stm32 gets interrupted while some data has overrun the buffer. there could be stalls between interrupts. and issue is that detailed specs of ‘high speed’ sdio is apparently not publicly published. hence, we can only make do and make a best guess based on available info and the HAL implementation

in terms of command timeout, it could perhaps mean that the app need to ‘ping’ the card periodically perhaps? or perhaps do a check if the card is idle and if needed restart initialization


Pito
Tue May 30, 2017 10:23 am
Sammy 16GB CL10 – connected to a different USB port and added an additional power 5V from serial dongle (above binary):
Use a freshly formatted SD for best performance.
Type any character to start

*************************************************
Opening the read file..
Opening the write file..
Reading, Writing and calculating CRC of In file...
State value (HAL_SD_STATE...): 1
Errorcode value (HAL_SD_ERROR...): 0
R1 value: 101100000000
HAL Return value (HAL_...): 0
C:\Users\Victor\Documents\Arduino\Hardware\STM32GENERIC\STM32\libraries\SDIO\src\SDIO.cpp
168
readBlocks
Timeout on Read, over 6400ms

Type any character to start

State value (HAL_SD_STATE...): 1
Errorcode value (HAL_SD_ERROR...): 4
R1 value: 100100000000
HAL Return value (HAL_...): 1
C:\Users\Victor\Documents\Arduino\Hardware\STM32GENERIC\STM32\libraries\SDIO\src\SDIO.cpp
158
readBlocks
error: opening test_out.bin for delete failed


Pito
Wed May 31, 2017 7:37 am
Compiled with Victor’s latest SDIO lib and sdcopytest, Samsung 16GB CL10, 2x10u decoupling, 3.3+5V USB
Use a freshly formatted SD for best performance.
Type any character to start

*************************************************
Opening the read file..
Opening the write file..
Reading and Writing..
State value (HAL_SD_STATE...): 1
Errorcode value (HAL_SD_ERROR...): 0
R1 value: 101100000000
HAL Return value (HAL_...): 0
C:\Users\pito\MyCode\Arduino\hardware\Arduino_STM32\STM32DE\libraries\SDIO\src\SDIO.cpp
199
readBlocks
Timeout on Read, over 12800ms

Use a freshly formatted SD for best performance.
Type any character to start

State value (HAL_SD_STATE...): 1
Errorcode value (HAL_SD_ERROR...): 2
R1 value: 100100000000
HAL Return value (HAL_...): 0
C:\Users\pito\MyCode\Arduino\hardware\Arduino_STM32\STM32DE\libraries\SDIO\src\SDIO.cpp
199
readBlocks
Timeout on Read, over 200ms
Invalid format, reformat SD.


danieleff
Wed May 31, 2017 9:08 am
It would be good to see if it can successfully read / write a few blocks, and then stops, or cannot even read/write the first block.

stevestrong
Wed May 31, 2017 2:59 pm
Pito wrote:R1 value: 101100000000

Pito
Wed May 31, 2017 8:26 pm
All timeouts increased 10x
#define sdRdTimeout 2000
#define sdWrTimeout 5000
#define sdBsyTimeout 5000
#define sdErTimeout 2500
#define sd_timeout 2500 // timeout in ms in the new HAL API

Pito
Wed May 31, 2017 10:21 pm
Samsung EVO 16GB CL10, 4bit SDIO, 168/24MHz, 102MB file
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 47545 msecs
*************************************************
Running CRC calculations...
File in CRC: 22483A52
File out CRC: 22483A52
*************************************************
Done in 68002 msecs


Pito
Wed May 31, 2017 10:25 pm
The problem is in ..STM32DE\cores\arduino\stm32\stm32_gpio_af_F0F2F3F4F7L0L1L4.c:
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = pin;
GPIO_InitStruct.Mode = mode;
GPIO_InitStruct.Pull = pull;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM; //GPIO_SPEED_FREQ_VERY_HIGH; <<<<<<<<<<< THE PROBLEM
GPIO_InitStruct.Alternate = stm32AfGet(list, size, instance, port, pin);
HAL_GPIO_Init(port, &GPIO_InitStruct);

Pito
Thu Jun 01, 2017 6:39 am
Samsung EVO 16GB CL10, SDIO 4bit, 200/33.3MHz
File size 5 MB
Buffer size 65536 bytes
Starting write test, please wait.

write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
10574.81,27066,5642,6140
10574.81,21555,5642,6140

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
14030.24,6463,4629,4671
14069.88,5345,4627,4655

Done
Type any character to start


ag123
Thu Jun 01, 2017 7:34 pm
Wow 14 MB per secs, you are reaching the bottleneck of even 100mbps fast ethernet, you’d need USB 2.0 *high speed* to talk to the desktop :lol:

victor_pv
Fri Jun 02, 2017 12:50 am
stevestrong wrote:Pito wrote:R1 value: 101100000000

victor_pv
Fri Jun 02, 2017 12:55 am
Pito wrote:Samsung EVO 16GB CL10, 4bit SDIO, 168/24MHz, 102MB file
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 47545 msecs
*************************************************
Running CRC calculations...
File in CRC: 22483A52
File out CRC: 22483A52
*************************************************
Done in 68002 msecs


Pito
Fri Jun 02, 2017 6:45 am
Did you make any change to get it working in 4bit mode this time? was this changing anything in the gpio port settings?
Yes, I did, see my above post about the slew rate.

ag123
Fri Jun 02, 2017 1:36 pm
if GPIO_SPEED_FREQ_MEDIUM is for sammy class 10, what would fit GPIO_SPEED_FREQ_VERY_HIGH? Gbps? :lol:
^^^ btw is GPIO_SPEED_FREQ_MEDIUM the speed that’s working to use with the current SDIO driver?

Pito
Fri Jun 02, 2017 3:46 pm
ag123 wrote:if GPIO_SPEED_FREQ_MEDIUM is for sammy class 10, what would fit GPIO_SPEED_FREQ_VERY_HIGH? Gbps? :lol:
^^^ btw is GPIO_SPEED_FREQ_MEDIUM the speed that’s working to use with the current SDIO driver?

danieleff
Fri Jun 02, 2017 4:53 pm
Well then MEDIUM it will be.

Given that in current master the SDIO does not even compile, I would be happy to pull the current state. And create a SdFat/src/SdCard/SdioSTM32.cpp, so that the current STM32SdFatSdio.h can be deleted from everywhere, and I will make sure that the included SdFat will compile whether the chip has SDIO or not.
(BTW there is no need to create different code for F1, as I think that F1 HAL will also be updated to new style SDIO)


danieleff
Sat Jun 03, 2017 7:32 am
Pito wrote:
I do not know whether the slew rate is the only cause of the issue. When browsing sdio stuff with F4 you may see the most recommended setting is the MEDIUM. And that is the only setting which works with Samsung at 24-33MHz here.
The clocks above 33MHz do not work here either, so still it might be a different issue there as well..

ag123
Sat Jun 03, 2017 8:22 am
the little secret here is f4 runs at 240mhz (vs ‘official’ 168mhz) just as capable as the f7, preferably add some vaporizing liquid nitrogen for stability :lol:
http://www.stm32duino.com/viewtopic.php … 160#p26942

Pito
Sat Jun 03, 2017 9:46 am
danieleff wrote:Pito wrote:
I do not know whether the slew rate is the only cause of the issue. When browsing sdio stuff with F4 you may see the most recommended setting is the MEDIUM. And that is the only setting which works with Samsung at 24-33MHz here.
The clocks above 33MHz do not work here either, so still it might be a different issue there as well..

Pito
Sat Jun 03, 2017 10:42 am
This is with Samsung EVO 16GB CL10 and 240MHz_FCPU/34.3MHz_SDIO (all below with the Black F407ZET board):
File size 5 MB
Buffer size 65536 bytes
Starting write test, please wait.

write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
10376.53,27872,5529,6249
10851.28,17714,5529,5971

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
14395.19,6292,4515,4557
14395.19,5229,4515,4543

Done
Type any character to start


Pito
Sat Jun 03, 2017 3:48 pm
Sandisk Ultra 16GB CL10, 240/34.3MHz, 1.513GB large file (CRC32 = 06172c89):
Use a freshly formatted SD for best performance..
*************************************************
Opening the read file..
Opening the write file..
Reading and Writing..
*************************************************
Done in 493254 msecs
*************************************************
Running CRC calculations...
File in CRC: 6172C89
File out CRC: 6172C89
*************************************************
Done in 715025 msecs

zmemw16
Sat Jun 03, 2017 4:21 pm
any chance of printing the split times separately for the read and write operations?

another – for us plodders with 8MHz and/or 25MHz boards, any chance of a bullet proof slower/much slower set of files ?
some of us don’t have the go faster stripes, just your basic blue cz ministm32 f103vet/zet, black 407vet/zet/zgt :roll:
srp


victor_pv
Sat Jun 03, 2017 5:19 pm
Pito wrote:My feeling is it should work at 50MHz SDIO when the Sdcard set to HighSpeed mode (CMD6), and maybe the “gpio loading cell” activated.. We work here with overclocked stuff so the stm experts will not help with that, sure :)

Pito
Sat Jun 03, 2017 5:34 pm
For experimental purposes the High speed mode with CL10 card is set as follows (in slow clock mode):
1. issue the CMD6 with the argument 0x80000001
SDMMC_CmdSwitchFunction(SDIO, 0x80000001);

ag123
Sat Jun 03, 2017 9:17 pm
Wow, 16 MB per secs & it copies 1.5GB in below 8 & 1/3 minutes, fast ethernet definitely cannot catch up u’d need USB 2.0 *high speed* to transceive with the host :lol:

Pito
Tue Jun 13, 2017 6:51 am
Not sure where to place this but let me start here:
I spent last night messing with following issue – Black F407ZET with 512kB External Sram, Heap in the External Sram, SdCard via SDIO, SdFat, basic frequencies.

The “mbmp” allocated in the Heap via malloc(), allocation went fine.

This does not work, it hangs inside the write:
if (myFile.write(mbmp.data, mbmp.size) != mbmp.size) {
Serial.println(F("### Error writing the file.."));
return 1;
}


danieleff
Tue Jun 13, 2017 10:50 am
I can only test external ram + sdio on F7, but in that branch SDIO does not compile. I will merge the SDIO branch to master, and fix it to work with F7, fix other stuff, merge STM32SdFatSdio.h into SdFat, etc…

Pito
Tue Jun 13, 2017 6:49 pm
I’ve started with debugger, and it stops here – SDIO.cpp line 221:

uint8_t SDIOClass::writeBlocks(uint32_t block, const uint8_t* src, size_t nb) {
if (((uint32_t)src & 0x3) !=0){
// Serial.println("### Not aligned src in SDIO.cpp line 221"); // Added by Pito
while (1); //Hang here, src was not aligned to word, this is a problem
}


stevestrong
Tue Jun 13, 2017 7:46 pm
Missing ALIGN(4) ?

Pito
Tue Jun 13, 2017 7:51 pm
in the ld script?

stevestrong
Tue Jun 13, 2017 7:53 pm
common.inc for libmaple

danieleff
Wed Jun 14, 2017 3:36 am
I merged SDIO to master. Works on F4/F7. Does not work on F1 due to HAL mismatch, but it will be updated soon. DMA is now managed centrally.
Changed gpio skew speed to medium. Fixed SdFat, examples etc… (unrelated: F407 SPI is now on PA5/PA6/PA7)

malloc is alignign to 8, so probably the data in mbmp struct is not the first member. (Can you print the adress of mbmp, and show the structure of mbmp)


Pito
Wed Jun 14, 2017 7:29 am
This is the structure:
typedef struct tagBitmap {
size_t width;
size_t height;
size_t size;
unsigned char *data;
} Bitmap;

zmemw16
Wed Jun 14, 2017 7:53 am
when using a call to a function/procedure with defaulted values, aren’t there are some rules on how to set the parameter list.
is this something similar ?

my syntax is all wrong, i read about it awhile back and thought it might be useful ( how?)
void fred ( int a=0, int b=1, int c=2);

fred ( 2,3,4);
fred ( c=5);
fred ( b=2, 5);


stevestrong
Wed Jun 14, 2017 8:14 am
Define mbmp or the data pointer alone as aligned
Bitmap mbmp __attribute__((aligned(4)));

Pito
Wed Jun 14, 2017 8:27 am
Nope..
It could be the myFile.write() or STM32SdFatSdio.h supplies wrong params to the SDIO driver.
The block=20289, src=0x680001d2, nb=63 .. that is weird, isn’t it?

danieleff
Wed Jun 14, 2017 8:43 am
Yes it is weird. Where did the first 0x680001d2 – 0x68000008 = 458 bytes go.
Anyhow when not aligned we can just do a regular write instead of dma write.

Pito
Wed Jun 14, 2017 8:50 am
It worked with F103ZET and the Heap in External Sram and with SPI.
http://www.stm32duino.com/viewtopic.php … 140#p22415

danieleff
Wed Jun 14, 2017 10:20 am
Then it is probably correct. Try with _useDMA = false;, and remove the alignment check.

Pito
Wed Jun 14, 2017 10:38 am
With _useDMA=false, and while(1) in the alignment check commented out I get (the 3 numbers at the end there are: block, src, nb)
Writing the .bmp to SDcard..
### Not aligned SDIO.cpp writeBlocks line 221 20289 680001D2 63
### Not aligned SDIO.cpp writeBlocks line 221 20352 68007FD2 64
### Not aligned SDIO.cpp writeBlocks line 221 20416 6800FFD2 64
### Not aligned SDIO.cpp writeBlocks line 221 20480 68017FD2 64
### Not aligned SDIO.cpp writeBlocks line 221 20544 6801FFD2 64
### Not aligned SDIO.cpp writeBlocks line 221 20608 68027FD2 64
### Not aligned SDIO.cpp writeBlocks line 221 20672 6802FFD2 64
### Not aligned SDIO.cpp writeBlocks line 221 20736 68037FD2 64
### Not aligned SDIO.cpp writeBlocks line 221 20800 6803FFD2 64
### Not aligned SDIO.cpp writeBlocks line 221 20864 68047FD2 64
### Not aligned SDIO.cpp writeBlocks line 221 20928 6804FFD2 64
### Not aligned SDIO.cpp writeBlocks line 221 20992 68057FD2 64
### Not aligned SDIO.cpp writeBlocks line 221 21056 6805FFD2 64
### Not aligned SDIO.cpp writeBlocks line 221 21120 68067FD2 64
### Not aligned SDIO.cpp writeBlocks line 221 21184 6806FFD2 41
Done..

Pito
Wed Jun 14, 2017 12:50 pm
When stepping through, the first 4 passes go via
int FatFile::write(const void* buf, size_t nbyte) {
// convert void* to uint8_t* - must be before goto statements
const uint8_t* src = reinterpret_cast<const uint8_t*>(buf);
cache_t* pc;
uint8_t cacheOption;
// number of bytes left to write - must be before goto statements
size_t nToWrite = nbyte;
size_t n;

Pito
Wed Jun 14, 2017 4:04 pm
As a proof I commented out the writing of the 54bytes of the bmp header, with __useDMA=true, and added a print out of addresses when aligned:
Writing the .bmp to SDcard..
### Aligned SDIO.cpp writeBlocks line 221 20288 68000008 64
### Aligned SDIO.cpp writeBlocks line 221 20352 68008008 64
### Aligned SDIO.cpp writeBlocks line 221 20416 68010008 64
### Aligned SDIO.cpp writeBlocks line 221 20480 68018008 64
### Aligned SDIO.cpp writeBlocks line 221 20544 68020008 64
### Aligned SDIO.cpp writeBlocks line 221 20608 68028008 64
### Aligned SDIO.cpp writeBlocks line 221 20672 68030008 64
### Aligned SDIO.cpp writeBlocks line 221 20736 68038008 64
### Aligned SDIO.cpp writeBlocks line 221 20800 68040008 64
### Aligned SDIO.cpp writeBlocks line 221 20864 68048008 64
### Aligned SDIO.cpp writeBlocks line 221 20928 68050008 64
### Aligned SDIO.cpp writeBlocks line 221 20992 68058008 64
### Aligned SDIO.cpp writeBlocks line 221 21056 68060008 64
### Aligned SDIO.cpp writeBlocks line 221 21120 68068008 64
### Aligned SDIO.cpp writeBlocks line 221 21184 68070008 41
Close file:
### Aligned SDIO.cpp writeBlocks line 221 21225 200000F8 1
### Aligned SDIO.cpp writeBlocks line 221 16384 200000F8 1
### Aligned SDIO.cpp writeBlocks line 221 8790 20000304 1
### Aligned SDIO.cpp writeBlocks line 221 12587 20000304 1
Done..

Pito
Thu Jun 15, 2017 6:03 am
This is a small modification in SDIO.cpp which runs with aligned and misaligned, it does not solve the DMA for misaligned, however:

uint8_t SDIOClass::readBlocks(uint32_t block, uint8_t* dst, size_t nb) {
if (((uint32_t)dst & 0x3U) != 0){
// while (1); //Hang here, dst was not aligned to word, this is a problem
_useDMA = false;
} else {
_useDMA = true;
}


danieleff
Thu Jun 15, 2017 6:29 am
I committed this to master to fix it: https://github.com/danieleff/STM32GENER … 11f6f9def1

As you can see, just like with SPI, blocking SDIO DMA is not that faster than blocking SDIO non-DMA, so I would not worry about performance.


Pito
Thu Jun 15, 2017 6:53 am
And the misaligned write result :) at Seahorse Valley

UPDATE: with a Rainbow ColorWheel

Mandel 400x400x1024col SingleP FPU 7secs.JPG
Mandel 400x400x1024col SingleP FPU 7secs.JPG (102.26 KiB) Viewed 273 times

victor_pv
Thu Jun 15, 2017 9:18 pm
danieleff wrote:Yes it is weird. Where did the first 0x680001d2 – 0x68000008 = 458 bytes go.
Anyhow when not aligned we can just do a regular write instead of dma write.

Pito
Fri Jun 16, 2017 4:47 pm
Still, in about 20% of cases, while opening the card (after reset) I get
Opening the SDcard's bmp file..
State value (HAL_SD_STATE...): 1
Errorcode value (HAL_SD_ERROR...): 80000000
R1 value: 0
HAL Return value (HAL_...): 1
C:\Users\pito\MyCode\Arduino\hardware\Arduino_STM32\STM32DE\libraries\SDIO\src\SDIO.cpp
121
begin
### Error opening the SDcard's file..

danieleff
Fri Jun 16, 2017 6:06 pm
I get the same.
It seems to be stuck in:
HAL_SD_Init -> HAL_SD_InitCard -> SD_PowerON -> SDMMC_CmdGoIdleState -> SDMMC_GetCmdError

Basically it sends CMD0, and then timeouts there, waiting for SDIO_FLAG_CMDSENT (The problem is already there in HAL_SD_Init, and not in HAL_SD_ConfigWideBusOperation)


stevestrong
Fri Jun 16, 2017 6:30 pm
I use this line to detect end of command, because also had problems with the CMDEND flag:
while ( (SDIO->STA&SDIO_STA_CMDACT) ) ; // wait for actual command to be sent

danieleff
Fri Jun 16, 2017 6:49 pm
Yes it seems to be stuck waiting for the command to be sent, so it is not properly initialized.
If you have SdFat, can you just use the bench example?

If I put `HAL_Delay(1);` between `SDIO_PowerState_ON` and `__HAL_SD_ENABLE`, I get way better results (seems to always initialize): https://github.com/danieleff/STM32GENER … _sd.c#L379


stevestrong
Fri Jun 16, 2017 6:56 pm
danieleff wrote:If you have SdFat, can you just use the bench example?

Pito
Fri Jun 16, 2017 7:49 pm
@Steve: If you want a misaligment of a block of data, simply do myFile.write(‘X’) before you start to write the block with myFile.write(block, size).
It writes byte X and the first 511 bytes from the block into the cache and onto the card, then it starts to write the block via DMA from block’s address 511 (misaligned). There is now the fix in SDIO.cpp such you will not see an error, it will write without DMA instead. You have to uncomment the while(1) there such it Hangs with misaligned (see above).
I will prepare the Mandelbrot demo soon.

@Daniel: I’ve done some reading on “sdio problem stm32f407” and found a lot of desperate topics at community.st.com. Frankly, I am quite surprised our SDIO works so well :)
I’ve seen somewhere in that forum they inserted delay(10) somewhere in init and then before CMD55 and before CMD10, as I can remember. I have to find that discussion again :roll:


Pito
Fri Jun 16, 2017 9:13 pm
danieleff wrote:If I put `HAL_Delay(1);` between `SDIO_PowerState_ON` and `__HAL_SD_ENABLE`, I get way better results (seems to always initialize): https://github.com/danieleff/STM32GENER … _sd.c#L379

stevestrong
Sat Jun 17, 2017 8:03 am
Pito wrote:@Steve: If you want a misaligment of a block of data, simply do myFile.write(‘X’) before you start to write the block with myFile.write(block, size).
It writes byte X and the first 511 bytes from the block into the cache and onto the card, then it starts to write the block via DMA from block’s address 511 (misaligned).

Pito
Sat Jun 17, 2017 1:05 pm
When you are DMAing the block you read from block’s direct ram address – therefore the alignment matters. You do not write via cache when doing DMA.

Pito
Sun Jun 18, 2017 4:43 pm
While working with the Zmodem example, I rarely (2x out of maybe 20 transfers) got following error (168/24MHz, Samsung CL10):
State value (HAL_SD_STATE...): 1
Errorcode value (HAL_SD_ERROR...): 10
R1 value: 100100000000
HAL Return value (HAL_...): 1
C:\Users\pito\MyCode\Arduino\hardware\Arduino_STM32\STM32DE\libraries\SDIO\src\SDIO.cpp
270
writeBlocks

Leave a Reply

Your email address will not be published. Required fields are marked *