简体   繁体   中英

SD card can't read write STM32f4

I am trying to interface sd card with STM32F4 but things are not working,code was developed using cubemx

  1. Interface is sdio 1 bit mode(due to pin constraints)
  2. SD card 8 Gb formated with default allocation size

Steps taken to debug:

I single step through the code fmount is successful but when I step through fopen there a error code at find_volume() returning FR_NOT_READY .

Hardware conections:

I have arduino micro SD breakout board with SPI pins so connection are

  • DI → SDIO_CMD
  • DO → SDIO_D0
  • SCLK → SDIO_SCLK

int main(void)
{
    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();

    /* Configure the system clock */
    SystemClock_Config();

    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_SDIO_SD_Init();
    MX_FATFS_Init();

    HAL_Delay(1000);

    /* USER CODE BEGIN 2 */
    if(f_mount(&mynewdiskFatFs,(const TCHAR*)SD_Path, 0) == FR_OK)
    {
        if(f_open(&MyFile, "abc.txt",  FA_READ ) == FR_OK)
        {
            // GPIO_SetBits(GPIOD, GPIO_Pin_15);
            if(f_read(&MyFile, wtext, sizeof(wtext), (void *)&wbytes) ==FR_OK);
            {
                f_close(&MyFile);
            }
        }
    }

    while (1)
    {

    }
}
f_open(&MyFile, "abc.txt",  FA_READ )

See what are your config options in ffconf.h regarding file names.

Try using (FA_OPEN_EXISTING | FA_READ) flags.

Use f_open() repeatedly with 100ms interval, say 5 times, till it returns FR_OK.

嗨turboJ,我正在使用1位宽的SDIO模式连接SD卡,所以我猜没有用CS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM