STM32更换SD卡后无法重新挂载SD

问题描述 投票:0回答:0

我的 STM32F410RB Nucleo 板上的 SD 卡插槽仍然有问题。重置单片机后,我又能成功挂载卡了,但一拔出SD卡,就再也挂不上了。

在移除卡后尝试安装卡时,我从 f_mount 函数收到错误消息 FR_NOT_READY。

void process_SD_card( void )
{
    if (SdCardConnected == 1)
    {
        printf("SD Card found\r\n");
        FATFS       FatFs;            //Fatfs handle
          FIL         fil;                  //File handle
          FRESULT     fres;                 //Result after operations
          char        buf[100];

          do
          {
            //Mount the SD Card
            fres = f_mount(&FatFs, "", 1);    //1=mount now
            if (fres != FR_OK)
            {
                //MX_FATFS_DeInit();

              printf("No SD Card found : (%i)\r\n", fres);
              break;
            }
            printf("SD Card Mounted Successfully!!!\r\n");

            //Read the SD Card Total size and Free Size
            FATFS *pfs;
            DWORD fre_clust;
            uint32_t totalSpace, freeSpace;

            f_getfree("", &fre_clust, &pfs);
            totalSpace = (uint32_t)((pfs->n_fatent - 2) * pfs->csize * 0.5);
            freeSpace = (uint32_t)(fre_clust * pfs->csize * 0.5);

            printf("TotalSpace : %lu bytes, FreeSpace = %lu bytes\n", totalSpace, freeSpace);

            //Open the file
            fres = f_open(&fil, "Testfile.txt", FA_WRITE | FA_READ | FA_CREATE_ALWAYS);
            if(fres != FR_OK)
            {
              printf("File creation/open Error : (%i)\r\n", fres);
              break;
            }

            printf("Writing data!!!\r\n");
            //write the data
            f_puts("Welcome to EmbeTronicX", &fil);

            //close your file
            f_close(&fil);

            //Open the file
            fres = f_open(&fil, "EmbeTronicX.txt", FA_READ);
            if(fres != FR_OK)
            {
              printf("File opening Error : (%i)\r\n", fres);
              break;
            }

            //read the data
            f_gets(buf, sizeof(buf), &fil);

            printf("Read Data : %s\n", buf);

            //close your file
            f_close(&fil);
            printf("Closing File!!!\r\n");
        #if 0
            //Delete the file.
            fres = f_unlink(EmbeTronicX.txt);
            if (fres != FR_OK)
            {
              printf("Cannot able to delete the file\n");
            }
        #endif
          } while( false );

          //We're done, so de-mount the drive
          fres = f_mount(0, "", 0);

          printf("SD Card Unmounted Successfully!!!\r\n");

    }else printf("No SD Card found \r\n");

}

我已经尝试了各种方法来解决这个问题,例如在不同的插槽中测试 SD 卡并尝试不同的上拉和下拉配置,但不幸的是,到目前为止没有任何效果。

我希望重置微控制器可以永久解决问题,但它似乎只是一个临时解决方案。社区中是否有人对我可以尝试解决此问题的其他方法有任何想法?任何帮助将不胜感激。

stm32 mount spi unmount
© www.soinside.com 2019 - 2024. All rights reserved.