[STM32GENERIC] SDIO DMA

Discussions about the STM32generic core
User avatar
Pito
Posts: 1498
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [STM32GENERIC] SDIO DMA

Post by 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
I mean in the source code, so I can add it to the code.
There is the source code - SDIO.cpp.
Pukao Hats Cleaning Services Ltd.

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

Re: [STM32GENERIC] SDIO DMA

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

Code: Select all

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 
Edit:
and an 1GB copy with DMA, and good CRC check

Code: Select all

*************************************************
Opening the read file..
Opening the write file..
Reading and Writing..
*************************************************
Done in 449879 msecs
Copy without DMA still freezes somehow on the first block write

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

Re: [STM32GENERIC] SDIO DMA

Post by Pito » Sun May 21, 2017 8:21 am

useDMA true (Samsung CL10 16GB):

Code: Select all

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

Code: Select all

Use a freshly formatted SD for best performance.

Type any character to start
FreeStack: 60907
HAL_SD_ReadBlocks Error: 1
Invalid format, reformat SD.
Almost the same with Sandisk CL10.
Note: printing "state" as the error in the latest SDIO.cpp

Code: Select all

Serial.print("HAL_SD_ReadBlocks Error: "); Serial.println(state);
Pukao Hats Cleaning Services Ltd.

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

Re: [STM32GENERIC] SDIO DMA

Post by victor_pv » Sun May 21, 2017 10:16 pm

Pito wrote:useDMA true (Samsung CL10 16GB):

Code: Select all

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

Code: Select all

Use a freshly formatted SD for best performance.

Type any character to start
FreeStack: 60907
HAL_SD_ReadBlocks Error: 1
Invalid format, reformat SD.
Almost the same with Sandisk CL10.
Note: printing "state" as the error in the latest SDIO.cpp

Code: Select all

Serial.print("HAL_SD_ReadBlocks Error: "); Serial.println(state);
Seems like we need to work on better CL10 support, and better 4bit wide support.
If you send me a PR to include the error code printing I'll merge it.

For 4bit mode: It should be supported by the card according to the standard, but I wonder if we need to adjust any timing setting.
For readblocks error, we can try increasing the timeout to a considerable amount just to see if the errors come from timeout's expiring.
If you are using the debugger, you can try also to set a breakpoint at the "if" clause that checks for the timeout to expire, and see if it ever gets there.
I initially was getting some of those, and extended the timeouts, but I think we need to use a timeout value that's a multiple of the number of blocks read for better accuracy.
What size of buffer where you using during those tests?

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
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: [STM32GENERIC] SDIO DMA

Post by 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.
I see that you added SdFat into the libraries. STM32SdFatSdio.h (or cpp) can go there.
But can it work in both SDIO and SPI mode, without manually changing the config file? If it can, I am ok pulling it.
(Also somehow I thought only SdFat-beta had the sdio code. Seems I was wrong).

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

Re: [STM32GENERIC] SDIO DMA

Post by 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.
I see that you added SdFat into the libraries. STM32SdFatSdio.h (or cpp) can go there.
But can it work in both SDIO and SPI mode, without manually changing the config file? If it can, I am ok pulling it.
(Also somehow I thought only SdFat-beta had the sdio code. Seems I was wrong).
My latest commit also included changing some int to uint in a few files due to warnings in for loops, because of comparing int to uint. Those are unrelated, I just didn't want to send a bunch of separate commits and wanted to have something people can download and start testing.

About STM32SdFatSdio.h yes I agree would be better to move it to sdfat folder, since that's a very specific one, but we will need to add some conditional compiling.
Perhaps the best solution for that is modify the sdfat files so it works like for the teensy, without having to include anything extra in the sketch itself.

We need to figure out a way to make the library more reliable with the Class 10 cards. I have been thinking on 2 fronts.
1.-Timeouts that depend on the number of blocks.
2.-Sending pre-erase commands when writing more than 1 block. It's an additional command that can be sent to a card before a multiblock write, and allows the card to erase all the affected blocks at once, rather than 1 by 1. That's supposed to speed up the writes.
3.-Adding more status checks after a write to confirm the card was able to actually write.

The specs has some information on how to detect if a write failed, but not very clear.
Basically if the write goes well, the card mode goes like this: Transfer(getting data) -> Programming (writing the data) -> Transfer (waiting for a new transfer).

If it fails it goes like this: Transfer(getting data) (there is some problem, like a bad CRC) -> Transfer (waiting for a new transfer, but with a flag set indicating a failure). But apparently after the failed write the card still needs to get a Command12 to indicate the previous transfer is over, otherwise any new write command is just ignored.
We need to check and confirm the data was good, and if so we keep going, but if not, we do X numbers of retries and if they fail we return an error to the library.
But at this point I do not know if the HAL checks for CRC in incoming data (hopefully), and if it checks for confirmation from the card that it accepted the data as good.

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

Re: [STM32GENERIC] SDIO DMA

Post by 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.
I see that you added SdFat into the libraries. STM32SdFatSdio.h (or cpp) can go there.
But can it work in both SDIO and SPI mode, without manually changing the config file? If it can, I am ok pulling it.
(Also somehow I thought only SdFat-beta had the sdio code. Seems I was wrong).
Daniel, I am making some modifications to the SDIO files to better manage the timeouts, at least in DMA mode, but while testing, every once in a while the bench sketch will fail after the first test is completed.
The bench loop calls sd.begin every single time before starting a test, and with the debugger I see that some times when the begin() method is trying to initialize the card, at the point of switching to 4 bit mode, it just hangs waiting for some flags from the sdio peripheral.

bench does not call end(), so I get a feeling that trying to initialize when the peripheral and card are already initialized is not exactly a good idea.
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.

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

Re: [STM32GENERIC] SDIO DMA

Post by 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.
I do not know how to do it, but it you can figure out, then yes.

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

Re: [STM32GENERIC] SDIO DMA

Post by 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.
I do not know how to do it, but it you can figure out, then yes.
I thought you would know more about that part since you wrote the begin function. We will have to look at it them, I haven't look much at the initialization part.

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

Re: [STM32GENERIC] SDIO DMA

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest