2022-09-16 10:55 PM
2022-09-17 02:46 AM
You can unpack the width register in the SDIO peripheral, or you can time the transfers, should be apparent form the speed / throughput.
2022-09-17 05:42 AM
Hello Tesla DeLorean,
Thank you for the reply, but I don't understand "unpack the width register"? Can you please post a few lines of code on how to do this? My code is pasted below for your reference.
Initially setting 1 bit mode.
hsd.Instance = SDIO;
hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
hsd.Init.ClockDiv = 4; // NPS lower clock speed than set by Cube (0)
Once the card is detected switching to 4-bit mode
sd_state = HAL_SD_InitCard (&hsd);
// After mounting the SD card change the bus width to 4 bit mode.
if (sd_state == HAL_OK)
{
if (HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B) != HAL_OK)
{
CMES ("SDIO 4 bit configuration error");
sd_state = HAL_ERROR;
}
else
CMES ("SDIO 4 bit mode done - OK");
}
return sd_state;
}
I get "SDIO 4 bit mode done - OK" this message but there is no apparent speed change when I used only 1 bit mode. Can you help please? Thank you.
NPS
2022-09-17 07:02 AM
switch((SDIO->CLKCR >> 11) & 3) // Unpack the width settings from peripheral register
{
case 0 : puts("1-Bit"); break;
case 1 : puts("4-Bit"); break;
case 2 : puts("8-Bit"); break;
default : puts("Unknown");
}
Speed is measurable from large, aligned, multi-block reads and writes over the interface.
Small unaligned interactions via f_read/ f_write will be very slow due to excessive interactions and overhead.
Done properly the F4 can work at several MB/s, reads into the 10's of MB/s. Done poorly perhaps several hundred KB/s
2022-09-17 07:35 AM
i test SD speed simply with a DSO on data line ; then read a 8 kB data block;
then you see the effective speed (i got about in 1ms for 8kB, so about 8 MB/s with 1bit mode)
and see, is data on line d2 or d3 , to be shure it runs in 4b mode.
+ try different cards ! some are slow or make random delays on command response.
+ without external low voltage driver , speed is limited to 25MB/s with SDHC cards.
2022-09-17 08:04 AM
All MicroSD cards were supposed to be clockable at 50 MHz, since inception. Likely needs an aware/attentive design on the host side. Certainly a lot that can get into the 60's and beyond without exotic drive modes/levels.
The STM32 typically runs out of bandwidth first.
Writes are usually much slower, due to the need to manage erase blocks, and rotate content.
The was an 8-bit MultiMedia Card,but that didn't gain a lot of traction, professional photographers choosing Compact Flash
2022-09-18 08:42 PM
Thank you. I will check this. But how will the SD card change to 4-bit mode without a command being sent, to change to 4-bit mode? I assume it is not automatic, cause at startup, if I initialize SDIO directly into 4-bit mode initialization never happens. So, I start with single bit mode initialize and then switch to 4-bit mode. Can you please clarify whether this is the right sequence and is there any command to be sent to SD card to change over to wide bus mode? Thank you very much.
2022-09-18 08:45 PM
Thank you Ascha.3 I will check with DSO but I still wonder how SD will switch to wide bus mode without a command from master? Any suggestions please?
2022-09-18 09:29 PM
That looks to be the correct sequence. ie bring up in 1-bit, switch to 4-bit.
The code provided earlier should confirm the peripheral side width expectations.
For speed perhaps read 32KB (64 sectors)
2022-09-18 11:46 PM
SDIO is not a simple serial data line, is more a complex bus controller you connect to a card; so at first there is some communication about the capabilities of each other, then the controller decides, what mode should be used - and this depends on its implementation. (and on errors - see F407 errata sheet ! hardware flow not working...)
on H743 init to 4 bit mode is at start: (100MHz SDMMC-clock, divide: 1 )