Skip to main content
electronic
Visitor II
July 20, 2017
Question

STM32F103 FATFS with SDIO

  • July 20, 2017
  • 1 reply
  • 645 views
Posted on July 20, 2017 at 17:37

Hello everyone,

I'm trying to make this code works :

/*♯♯-1- Link the micro SD disk I/O driver ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/

if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)

{

    /*♯♯-2- Register the file system object to the FatFs module ♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/

    if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK)

   {

       /* FatFs Initialization Error */

       Error_Handler();

    }

    else

    {

       /*♯♯-3- Create a FAT file system (format) on the logical drive ♯♯♯♯♯♯♯♯♯*/

       /* WARNING: Formatting the uSD card will delete all content on the device */

       if(f_mkfs((TCHAR const*)SDPath, 0, 0) != FR_OK)

       {

          /* FatFs Format Error */

          Error_Handler();

       }

    }

 }

The fm_mkfs function gets out at that line in the ff.c file of the FatFs library:

 if (disk_write(pdrv, tbl, b_vol, 1)) /* Write it to the VBR sector */

    return FR_DISK_ERR;

To be precise it gets out in the SD_WriteMultiBlocks (custom disk_write function) function :

SD_Error SD_WriteMultiBlocks(const uint8_t *writebuff, uint64_t WriteAddr, uint16_t BlockSize, uint32_t NumberOfBlocks)

{

   SD_Error errorstatus = SD_OK;

   TransferError = SD_OK;

   TransferEnd = 0;

   StopCondition = 1;

   SDIO->DCTRL = 0x0;

   SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND |    /*SDIO_IT_RXOVERR*/SDIO_IT_TXUNDERR | SDIO_IT_STBITERR, ENABLE);

   SD_LowLevel_DMA_TxConfig((uint32_t *)writebuff, (NumberOfBlocks * BlockSize));

   SDIO_DMACmd(ENABLE);

   if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)

   {

      BlockSize = 512;

      WriteAddr /= 512;

   }

   /* Set Block Size for Card */

   SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;

   SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;

   SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;

   SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;

   SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;

   SDIO_SendCommand(&SDIO_CmdInitStructure);

   errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);

   if (SD_OK != errorstatus)

   {

      return(errorstatus);

   }

   ..... /* Other commands in the function...*/

   ......

}

It returns : SD_CMD_RSP_TIMEOUT.

I can't figure out why all the previous commands worked but this one (which also worked on previous calls).

Any clue will be appreciated.

Thank you.

Mathias

#fatfs-sdio #stm32f103
This topic has been closed for replies.

1 reply

Tesla DeLorean
Guru
August 8, 2018

Bumping to remove from the home page (No Answer Posts)

Writes might fail in ST's assorted models if code hasn't waited for prior read/write operations to have completed properly. Check IRQHandlers and callbacks

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..