cancel
Showing results for 
Search instead for 
Did you mean: 

SDIO not mounting/opening file using HAL on STM32F4-Discovery

zachary
Associate
Posted on June 03, 2015 at 21:46

The original post was too long to process during our migration. Please click on the attachment to read the original post.
3 REPLIES 3
markb
Associate II
Posted on June 03, 2015 at 22:42 Hi, It's my belief that the HAL SDIO cannot be used reliably without DMA and the supplied FF code does not use DMA. So it fails. Why do you need to use DMA? Well, the SD HW flow control is unusable and so you have to ensure that data can be read/written from the SDIO in a timely fashion otherwise you get overruns. Enable SD DMA and modify sd_diskio.c as shown in the following snippet.

/**
* @brief Reads Sector(s)
* @param *buff: Data buffer to store read data
* @param sector: Sector address (LBA)
* @param count: Number of sectors to read (1..128)
* @retval DRESULT: Operation result
*/
DRESULT SD_read(BYTE *buff, DWORD sector, UINT count)
{
DRESULT res = RES_OK;
if(BSP_SD_ReadBlocks_DMA((uint32_t*)buff, 
(uint64_t)sector * BLOCK_SIZE, 
BLOCK_SIZE, 
count) != MSD_OK)
{
res = RES_ERROR;
}
return res;
}
/**
* @brief Writes Sector(s)
* @param *buff: Data to be written
* @param sector: Sector address (LBA)
* @param count: Number of sectors to write (1..128)
* @retval DRESULT: Operation result
*/
#if _USE_WRITE == 1
DRESULT SD_write(const BYTE *buff, DWORD sector, UINT count)
{
DRESULT res = RES_OK;
if(BSP_SD_WriteBlocks_DMA((uint32_t*)buff, 
(uint64_t)sector * BLOCK_SIZE, 
BLOCK_SIZE, count) != MSD_OK)
{
res = RES_ERROR;
}
return res;
}
#endif /* _USE_WRITE == 1 */

markb
Associate II
Posted on June 03, 2015 at 22:43

Err, that should have said underuns.

zachary
Associate
Posted on June 03, 2015 at 23:35

Hi Mark,

Thank you for the reply.

I actually saw your post in another thread and attempted to do that (even though my current project does not show it). I went to STM32CubeMX and edited the DMA settings to match those you listed in your HAL_SD_MspInit() function. For some reason, the same errors were returned; I couldn't get past either the mounting or opening stages, dependent on whether or not I was linking the drivers.

I can definitely believe that SD doesn't work well without DMA though; it seems as if it would be a good way of making sure data gets transferred in a timely fashion.

Just to make sure, I did run it again. I get the error of FR_INVALID_DRIVE.