Skip to main content
Parmin Nayani
Associate III
September 17, 2022
Question

About SDIO. I am using SDIO on STM32F407 for SD card. Though I am enabling 4-bit mode after initialization, I am not sure if it is going into 4-bit mode. Is there any way we can detect the enabled bus width of SDIO? Thank you.

  • September 17, 2022
  • 3 replies
  • 2923 views

..

This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
September 17, 2022

You can unpack the width register in the SDIO peripheral, or you can time the transfers, should be apparent form the speed / throughput. ​

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Parmin Nayani
Associate III
September 17, 2022

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

Tesla DeLorean
Guru
September 17, 2022
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

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Parmin Nayani
Associate III
September 19, 2022

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.

AScha.3
Super User
September 17, 2022

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.

0693W00000SvcQIQAZ.png

"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
September 17, 2022

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

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