This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SD Card - unmount/remount

Hello,

i have tried to hook up a SD card to the launchpad, SD FAT demo works flawlessly. However, i would like to swap the cards while the program is running. I have not found any solution nor any hint in the specifications so far.

Fistly, i have tried to unmount an sd card before it is removed:

f_mount(0,NULL);

Then, i tried to perform the initialization that is done when program starts:

MAP_PRCMPeripheralClkEnable(PRCM_SDHOST,PRCM_RUN_MODE_CLK);
MAP_PRCMPeripheralReset(PRCM_SDHOST);
MAP_SDHostInit(SDHOST_BASE);
MAP_SDHostSetExpClk(SDHOST_BASE, MAP_PRCMPeripheralClockGet(PRCM_SDHOST),15000000);

But, when i try to mount the new card after it is replaced, the f_opendir call returns FR_NO_FILESYSTEM error. I tried to debug the issue, and it seems that only zero values are read from the card after media change, thus the lib thinks there is no filesystem. When i reset the board and keep the new card in the sd slot, everything works.

Is there any documentation/example on this procedure (media change)?

 

Thank you

  • Hi Martin,

    There were few known issue in SDK 1.0.0 : processors.wiki.ti.com/.../CC32xx_Summary_of_Known_Issues
    Can you please confirm you have taken in the suggested changes.

    I tried re-running the SDHost_FatFs application removing/re-inserting the SD Card without resetting the LP . But I am not able to recreate your issue.

    Thanks and Regards,
    Praveen
  • I haven't tried it before, but i did today; i modified the SDK files according to the errata but nothing changed.

    My test program is as follows; i modified the SD FAT example to respond to the two SW2&3 buttons:

    Button_IF_Init(SW2Handler, SW3Handler);  just before the final while in the program.

    My SW2 handler is meant to be something like unmount/remount button; i'm not sure what should i do in this situation and this is the core of my question.

    The SW3 button is list directory routine taken from the main() body of this program, it prints the dir listing to the UART.

    This modified example works (i get multiple dir listings on the push of the SW3 button), but if i remove and reinsert the card, the dir listings do not work anymore. It returns FR_NO_FILESYSTEM error from the open dir routine.

    For reference, i include my SW3 Handler here.

    void SW3Handler()
    {
        FATFS fs;
        FRESULT res;
        DIR dir;
    f_mount(0,&fs); res = f_opendir(&dir,"/"); if( res == FR_OK) { Message("Opening root directory.................... [ok]\n\n\r"); Message("/\n\r"); ListDirectory(&dir); } else { Message("Opening root directory.................... [Failed]\n\n\r"); } Button_IF_EnableInterrupt(SW3); }

     

  • Martin,

    Going through the diskio.c, you will see the initialization status is stored in a global structure variable g_sDisk.bStatus. This is used to check the card initialization status.

    You will need to restore the structure to its default value before re-mounting the SD Card.

    DSTATUS disk_initialize ( BYTE bDrive )

    {

     unsigned long ulRet;

     unsigned long ulResp[4];

     //

     // Check the drive No.

     // Only 1 drive is supported

     //

     if (bDrive == 0)

     {

       if( g_sDisk.bStatus == 0)

       {

         return g_sDisk.bStatus;

       }

    ....

    }

    Thanks and Reagrds,

    Praveen

  • That was it, thanks!