cancel
Showing results for 
Search instead for 
Did you mean: 

sd-card read write mode speed same in SD 1 bit mode and SD 4 bit mode?why

RShar.9
Senior

i m writing data in 1 bit mode or 4 bit both have the same speed, i m using stm32f746g discovery board. and what can be the max read write speed?

9 REPLIES 9
dbgarasiya
Senior II

Hello ,

I am using STM32F779BI controller ,

I have problem that i could be able to write sd card only sometimes otherwise i failed in f_mkfs

how you implement to write sd card

Thanks in advance

Best Regards

Dipak Garasiya

JChrist
Associate III

RShar.9

Did you ever figure out this issue?

I'm seeing the same thing.

I can read a 128k byte file from SD in 153ms and this is the same weather in 1-bit mode or 4-bit mode.

Jacob

Single block reads can have significant command/response overhead.

f_read() of small and unaligned data will also be slow.

Reading 32KB blocks, one should be able to hit many MB/s. Low effort probably looking at 8-9 MBps, so figure at least 10x the numbers you're reporting.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for your response, my concern is not actually throughput as much as total write time of small bits of data. We want to make sure we can close files as fast as possible in the event of a power failure (which we can detect) to prevent corruption of data.

Jacob

Problem here is that "writing small bits of data" and "closing files" is going to cause the read/write of quite a few sectors, probably in multiple different erase blocks.

Not something I've benchmarked.

Running an F7 part? Clocking the SDMMC how fast?

Write speeds are highly dependent on the specific card/brand.

Would highly recommend instrumenting the DISKIO layer to get a big idea of the scope of the read/write activity precipitated, and the relative timing contributions.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I understand that the writing of small bits of data will do to the SD card, we have plans to mitigate (like buffering a lot of small bit then writing at one time). As I mentioned before the primary goal is to optimize for the fastest writes possible to make sure we do not corrupt the SD card in a power failure. We have older devices that have shutdown buttons to prevent this, but we cannot always control if a user will pull power at an unexpected time.

We are using an F4 with STM32Cube and FreeRTOS, The SDIO Clock is set to 48 MHz, but I'm not sure how that translates into SD clock speed (yet). I have some SD card experience on PIC32's but this is the first time I've taken a serious look at the SD code on a STM32.

I also understand that write speed will vary from SD card to SD card (and with wear).

I appreciate the help and thoughtful insight, but really just want to know why 1-bit mode and 4-bit mode run at the same speed. I know SD cards need to start in SPI mode then can switch but have to do so after initialized. I can also see that the MX_SDIO_SD_Init() starts in 1 bit mode:

 hsd.Init.BusWide = SDIO_BUS_WIDE_1B;

I'm stepping through code now to try and figure out if at some point it switches to 4 bit mode or if this is something I have to do myself.

Jacob

JChrist
Associate III

So I've confirmed by stepping through the code that the 1 bit version of the code never attempts to change the bus width and that the 4 bit version of the code does attempt to change the bus width. Futher the SD card I'm using seems to claim that is support wide bus operation and the code attempts to put it into wide but operation in the SD_WideBus_Enable() which is called from HAL_SD_ConfigWideBusOperation()

So either my SD card does not really support "Wide" bus operation or there is a bug in the ST code.

Specifically what I see is that the the upper 32 bits of the SCR register to see if wide bus mode is supported (4 bits?) with this statement:

 if((scr[1U] & SDMMC_WIDE_BUS_SUPPORT) != SDMMC_ALLZERO)

Since

#define SDMMC_WIDE_BUS_SUPPORT       0x00040000U

And since bit 50 of the SCR register is the 4-bit wide supported bit my SD card seems to correctly claim that is supports wide mode.

Next I can see the software send the CMD55 (to use ACMD's) and ACMD6 with a parameter of 2 to set to 4-bit mode (Page 102 of the SD Card Physical Specification).

Finial I can see that the STM32 registers are adjusted to use the 4-bit mode.

Make no sense why the 1-bit mode and 4-bit mode take the same amount of time to transfer 128K of data.

Jacob

>>Make no sense why the 1-bit mode and 4-bit mode take the same amount of time to transfer 128K of data.

Pretty sure that's not the case, but not invested in proving it false. Benchmarking 1 vs 4-bit show distinct differences. 1-bit mode definitely can't hit 11 MBps reading 32KB blocks. Not using CubeMX boiler-plate here, so figure either that's delivered pre-broken, or you're yielding the core.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Totally understand, thanks for all that you have provided so far. All I did was wrap a loop that reads 128KB file with a timer. The time is the same in 1-bit or 4-bit mode. If I pursue this further the scope is coming out to see if the other data lines are actually being twiddled.