SD card issue in SDIO peripheral in Stm32f407VET6 Black Board

962 Views Asked by At

I have Stm32f407VET6 Black Board, cant connect the MicroSD card. im using onboard SD slot and a 32GB micro SD card by PNY. The card is okay and its already in FAT32 formatted. f_mount() function returns only FR_NOT_READY. Mounting Formatting wont work.

I have been following tuts from controller tech and on SDIO it seems not work for me.

IDE: Cube IDE 1.12.1 Board: Stm32f407VET6 Black Board Driver Version: 1.27.1 for f4 SDIO Mode: SD 4bit wide bus

Clock Setup enter image description here SDIO setup , enter image description here FATFS setup, enter image description here enter image description here main.c file enter image description here

I also have extended the heap and stack size for the application to 2048. The response i found from f_mount() in ff.c used in a custom file_handling.c file used by controller tech, it only returns FR_NOT_READY

I also noticed that the MX_SDIO_SD_Init() used in main.c don't have any HAL_SD_Init() function call like other peripheral MX_init function. enter image description here

If anyone successfully did mount a card please share ur code and if possible help me out finding the mistake

3

There are 3 best solutions below

0
On

Recently, there was a bug in the auto-generated code for SD devices in CubeIDE.

/**
  * @brief SDIO Initialization Function
  * @param None
  * @retval None
  */
static void MX_SDIO_SD_Init(void)
{

  /* USER CODE BEGIN SDIO_Init 0 */

  /* USER CODE END SDIO_Init 0 */

  /* USER CODE BEGIN SDIO_Init 1 */

  /* USER CODE END SDIO_Init 1 */
  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_4B;
  hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
  hsd.Init.ClockDiv = 2;
  /* USER CODE BEGIN SDIO_Init 2 */

  // change buswide setting
  hsd.Init.BusWide = SDIO_BUS_WIDE_1B;

  /* USER CODE END SDIO_Init 2 */

}

The BusWide initialization setting for SDIO must be set to SDIO_BUS_WIDE_1B for the initialization sequence to be performed correctly and for SDIO to work properly afterwards.

It appears in many versions of CubeIDE, regardless of package, and it seems to be a mystery under what circumstances it appears. I've reached out to ST, but haven't heard back yet. :(

0
On

I've currently the same issue. If you dig a little bit deeper with the debugger through the source code you perhaps will see that you come along the file $Project/Middlewares/ThirdParty/FatFS/src/diskio.c. Inside this file the function DSTATUS disk_initialize(BYTE pdrv) is called. Inside this function another function will be called which is stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]); (pointer-to-function) and points in my case to the function DSTATUS USER_initialize (pdrv) in the file user_diskio.c or similar. The content of the latest function is not complete and returns always STA_NOINIT (= 0x01) which leads to an f_mount() = not ready error because you have to add your own stuff here. I'm currently busy with it and in an earlier project where I've done this with a µSDcard with SPI-interface that works after hours of try and error.

Some information how to use the driver can be found at the beginning of the driver files like stm32f4xx_hal_sd.c and sd_diskio.c. Search for it in STM32Cube_FW_F4_V1.27.*.zip/Drivers/STM32F4_HAL_Driver/Src.

Take also a look in the firmware package to STM32Cube_FW_F4_V1.27.*.zip/Projects/STM32F446ZE-Nucleo/Demonstration/sd_diskio.c to get an example what you have to do. Hope it helps.

PS: I'm using a STM32F4-DISCOVERY board for my development.

1
On

I have the same F407VET6 device. It does not implement the 10 K pull up resistors.

You have to use software pull up in the gpio initialization.

You have also to change hsd.Init.BusWide = SDIO_BUS_WIDE_4B; to 1B.

After doing so. It works.