Skip to main content
Explorer
June 8, 2025
Question

STM32F407VET6 MicroSD initialization issue

  • June 8, 2025
  • 2 replies
  • 514 views

I am using STM32F407VE Black Board. It contains the STM32F407VET6 chip. It has a microSD slot but the slot's CD pin is not connected. Due to this f_mount() is always returning faults. I don't know if this hardware miss connection is the primary problem why f_mount() returns faults or there are more problems. Please help me out with this. I am stuck since 2-3 days. I tried modifying the dist_status and dist_initialize functions to bypass this hardware check but when I upload the code, the board does nothing for 20-30sec and f_mount again returns error. I have attached my code changes

DSTATUS disk_status (
	BYTE pdrv		/* Physical drive number to identify the drive */
)
{
// DSTATUS stat;
//
// stat = disk.drv[pdrv]->disk_status(disk.lun[pdrv]);
// return stat;
	return 0x04;
}
// Inside diskio.h:
/* Disk Status Bits (DSTATUS) */

#define STA_NOINIT		0x01	/* Drive not initialized */
#define STA_NODISK		0x02	/* No medium in the drive */
#define STA_PROTECT		0x04	/* Write protected */

0x04 indicates write protected.  

DSTATUS disk_initialize (
	BYTE pdrv				/* Physical drive nmuber to identify the drive */
)
{
 DSTATUS stat = RES_OK;

 if(disk.is_initialized[pdrv] == 0)
 {
 stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]);
 if(stat == RES_OK)
 {
 disk.is_initialized[pdrv] = 1;
 }
 }
 stat = 0x04;
 return stat;
//	return 0;
}

 

    This topic has been closed for replies.

    2 replies

    Super User
    June 8, 2025

    What is the "slot's CD pin " ?   micro SD , see ->

    AScha3_0-1749405252981.png

    ...and this is connection on F407VET black board :

    AScha3_0-1749405991851.png

     

    Explorer
    June 18, 2025

    When you use it in 4B mode, CD is being utilized as DAT3 which leaves no other pin for selecting the chip

    Super User
    June 18, 2025

    Ok, now i see: you puzzle the 2 possible interfaces : SPI (with CD/CS ) vs. SDIO (no CD, but 4 data lines) .

    See in pic of card i posted: green(SPI) or blue names for interface on card.

    So on using SDIO/SDMMC interface , as its here, there IS NO CD line !

    And SD-card always starting in 1-bit mode (= standard) , for 4-bit its - after communication SDMMC --- SDcard is working - then switched to other mode (speed setting, 4bit, voltage ...).

    > Nobody seems to be sure why this works.

    Because its standard on sdcards.

    So just begin with 1-bit mode and speed setting < 50MHz for sdmmc clock, and set cpu pin speed medium (not highest!).

    Graduate II
    June 17, 2025

    Hi @jayanth0625 ,

    Missing CD is very unlikely to be the cause of your problems. You can single step through the code to confirm this and most likely something else is going wrong. If you were to see that an expected CD GPIO is read and indicates no card present, then you can easily comment out that code (but as mentioned, I doubt this will be the issue).

    Much more likely is problems with the cache and or buffer alignment. If you search this forum for "SDMMC cache" you will find a lot of questions raised and various answers given. As a starting point I would ensure that your data cache is disabled until you have the SDMMC basically working, then consider enabling cache. Also be careful to check MX for the SD initial clock freq.

    Good luck!

    Explorer
    June 18, 2025

    I realize now that CD pin is not a problem. I read about some bugs in the automatic code generated by cubemx. Something with first using 1B bus and then switching to 4B. Nobody seems to be sure why this works. But I will look into this too and let you know. Thanks for the response.