cancel
Showing results for 
Search instead for 
Did you mean: 

microSD on Nucleo-144 STM32H723ZG - Can't make SDIO work.

elso
Associate III

Hi All,

I am trying to use microSD on Nucleo-144 STM32H723ZG(T6U) by using an external microSD module called "Pmod MicroSD" by digilent Pmod microSD Card Slot. The SD card I am using is this one: Trancend 4GB MicroSD . I am able to use the SD card with SPI, but struggle with SDIO (which the slot and card is supposed to support, not SDMMC).

I have connected the slot as following:

D0(Pin 3) to PC8, D1(Pin 7) to PC9, D2(Pin 8) to PC10, D3(Pin 1) to PC11, SCK(Pin 4) to PC12, CMD(Pin 2) to PD2

GND - GND, and VCC - 3.3V

In STM32CubeIDE I set SDIO by choosing SDMMC1 in connectivity, then "SD 4 bits Wide bus". I make sure the pins correspond to how I have connected. Everything else is set default here.

Then I choose FATFS, SD Card. Here we have one thing called Detect_SDIO: I dont know what this is, and what I need to connect there from the Pmod, or if that is needed. I need at least to choose a GPIO input, and chose it as PA3.

Then I choose Automatic clock resolver. (SDMMC1 is set to 96MHz).

Then I added this code + the declaration.

 

 

 

/* USER CODE BEGIN 2 */

if(f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) != FR_OK){

 myPrint("Mount Failed\r\n");

 }else{

 myPrint("Mount Success\r\n");

 }

if(f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, rtext, sizeof(rtext)) != FR_OK){

 myPrint("Make of filesystem Failed\r\n");

 }else{

 myPrint("Make of filesystem Success\r\n");

 }

if(f_open(&SDFile, "test.txt", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK){

 myPrint("File open/make Failed\r\n");

 }else{

 myPrint("File open/make Success\r\n");

 res = f_write(&SDFile, wtext, strlen((char *)wtext), (void *)&byteswritten);

if((byteswritten == 0) || (res != FR_OK))

 {

 myPrint("Write Failed\r\n");

 }

else

 {

 myPrint("Write Success\r\n");

 f_close(&SDFile);

 }

 }

/* USER CODE END 2 */

 

 

Still not working. Tried to change clock divider to 100, no change. 

Mount Success
Make of filesystem Failed
File open/make Failed

Any inputs on what I am doing wrong?

Do I need to configure anything else?

Thanks for all future answers!

 

1 ACCEPTED SOLUTION
4 REPLIES 4
AScha.3
Chief III

mount with parameter 0 does nothing. use "1" . then you see result ...if no success, sd-card access not working.

dont try mkfs...never write, as long not sure, access is working fine. only read ! set fatfs to read-only , to be sure, no write will happen. only enable write/mkfs , when mount+read files working perfect !

check card in pc/laptop , put a file on it. (new cards are formatted , fat32 or exfat for > 8 GB cards, you cannot do better , just not format. enable exfat in fatfs settings, if using big cards.)

+ at first: set pins to the state, a sd-card is expecting: pullup on all pins, speed medium. clock 50M . (100MHz + div 1 , i use)

If you feel a post has answered your question, please click "Accept as Solution".

Thanks, This worked! I configured the board as 1 bit wide, and wrote this code as in the link:

static void MX_SDMMC1_SD_Init(void)
{

  /* USER CODE BEGIN SDMMC1_Init 0 */

  /* USER CODE END SDMMC1_Init 0 */

  /* USER CODE BEGIN SDMMC1_Init 1 */

  /* USER CODE END SDMMC1_Init 1 */
  hsd1.Instance = SDMMC1;
  hsd1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
  hsd1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
  hsd1.Init.BusWide = SDMMC_BUS_WIDE_1B;
  hsd1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;
  hsd1.Init.ClockDiv = 4;
  /* USER CODE BEGIN SDMMC1_Init 2 */
  if (HAL_SD_Init(&hsd1) != HAL_OK)
    {
      Error_Handler();
    }
    if (HAL_SD_ConfigWideBusOperation(&hsd1, SDMMC_BUS_WIDE_4B) != HAL_OK)
    {
      Error_Handler();
    }
  /* USER CODE END SDMMC1_Init 2 */

}

This mean that it is a 4 bit wide bus right?

Thanks! I realized that my SD card is a class 10 (4GB), which should in theory be able to do speeds of 50 MHz, but at 100 MHz I needed a clock divide factor of 4 to make it work, probably because of my setup with longer wires. It didn't work before I put the 2nd ground pin from the SD card into the PA3. 

I commented out the mkfs as you said too.