2014-07-09 02:09 AM
Hello,
I'm trying to make working the fatFS thought SDIO-4bits but I have the same problem on 2 different boards (devkit and custom board with STM32F437).All the code is generated by cubeMX (v4.3, firmware 1.3).The MX_SDIO_SD_Init(); function executes with no errors. Before the init the clock is 400kHz and then 25MHz. I modified a #define to reduce the clock speed to 400kHz to remove potential signal integrity errors.After the init the HAL_SD_GetStatus(&hsd); returns SD_TRANSFER_OK.But all others functions (HAL_SD_GetCardStatus(), HAL_SD_ReadBlocks(), HAL_SD_WriteBlocks(), f_mount()) loop indefinitely in a while : HAL_SD_SendSDStatus(...){... /* Get status data */ while(!__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND | SDIO_FLAG_STBITERR)) { if (__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_FLAG_RXFIFOHF)) { for (count = 0; count < 8; count++) { *(pSDstatus + count) = SDIO_ReadFIFO(hsd->Instance); } pSDstatus += 8; } } }...}I have also tried to make the SDIO 1 bit wide only, the problem persist. Optimisations are desactivated.Any ideas ?2014-07-09 02:46 AM
Below is what I get when halting the CPU in the infinite while() :
POWER.POWERCTL = 3 - Power-on: the card is clocked.CLKCR.WIDBUS = 0 - Default bus mode: SDIO_D0 usedCLKCR.CLKEN = 1 - SDIO_CK is enabled and visible at scopeDTIMER = 0xFFFFFFFF - max value - The timeout doesn't decrement ?!DLEN = 64DCTRL.SDIOEN = 0DCTRL.DBLOCKSIZE = 64DCTRL.DTDIR = 1 - From card to controller.DCTRL.DTEN = 1DCOUNT = 64STA.RXFIFOE = 1 - FIFO emptySTA.RXACT = 1 - data receive in progressFIFOCNT = 162014-07-09 03:12 AM
Note that on my custom design, there is no pull-up on the board for D0-D3 and CMD lines. I use the STM32 internal pull-up instead.
I dont't think the problem come from theses pull-up since I have the same issue with the devkit.2014-07-09 03:24 AM
Hi eigerMount,
Which ST board are you working with ? EVAL or Discovery ? Why you're configuring the SDIO in 1bit wide all time ? It's used only for initialization process. Please provide as a little more information about the issue you’re experiencing.With regards.2014-07-09 10:03 AM
Well!
Everything is working fine. The EMI protection (EMIF06-MSD02N16) was soldered in the wrong way. The SDIO module works definitely better with the EMIF righlty connected :)Some benchmarks:Core@96MHz, SDIO@24MHz, Write test (I'am not interested by reading performance). f_sync to be sure that there is no pending FIFO and all data is written. HAL_GPIO_WritePin(GPIOE, LED_ORANGE, GPIO_PIN_SET); for(i = 0; i < nbBlocs; i++) { fres = f_write(&file, txBuf, blocSize, (UINT*)&len); } fres = f_sync(&file); HAL_GPIO_WritePin(GPIOE, LED_ORANGE, GPIO_PIN_RESET); SD card = 2GB ''Dane elec'', formated with SDformater (clusters 32k)blocSize nbBlocs kBps512 32 95 1024 32 1682048 16 1414096 16 5368192 8 88316384 8 129232768 8 1747SD card = 2GB ''taiwan'', formated with SDformater (clusters 32k)blocSize nbBlocs kBps512 32 58 1024 32 1682048 16 4744096 16 8648192 8 135616384 8 113632768 8 1413SD card = 8GB transcend class 10, formated with SDformater (clusters 32k)blocSize nbBlocs kBps512 32 145 1024 32 2772048 16 4614096 16 7898192 8 110816384 8 171132768 8 18602014-07-09 10:22 AM
1.8 MBps seems a bit on the sad side, the cheap 128MB SD card supplied with ST's EVAL boards should be able to do that, I'd expect a decent 16GB SDHC card to post >7MBps writing and >10MBps reading
32MB written as 32KB blocks, FatFs, 4-bit SDIO, interface clock 24 MHz, SDIOCLK 48 MHz2014-07-10 07:33 AM
One more benchmark:
SD card = 8GB varbatim class 4, formated with SDformater (clusters 32k)blocSize nbBlocs kBps512 32 199 1024 32 3172048 16 6174096 16 10178192 8 139416384 8 200432768 8 1614I was also expecting some better results, even if it will be enough for the most of my applications. Now I'm going to use DMA, I hope it will speed up the transfert.Note I also updated the ff.c/ff.h from 1.0 to 1.0b, adding some #defines it compile and works fine (all the previous benchmarks have been done with fatfs 1.0b)2017-03-13 01:29 AM
Hi
I know this has been a while but I want to open this case up again as I am experiencing the same issue.
After performing the following:
/* StartDefaultTask function */
void StartDefaultTask(void const * argument)
{
for(;;) {
/*##-1- Link the micro SD disk I/O driver ##################################*/
if(FATFS_LinkDriver(&SD_Driver, (char *)SD_Path) == 0) {
/*##-2- Register the file system object to the FatFs module ##############*/
if(f_mount((FATFS *)&SDFatFs, (TCHAR const*)SD_Path, 0) == FR_OK) {
for(;;) {
fr = WriteSDCard();
osDelay(1000);
if(fr) {
f_mount(NULL,'',1);
break;
}
}
/*##-11- Unlink the micro SD disk I/O driver ###############################*/
FATFS_UnLinkDriver((char *)SD_Path);
}
}
}
}
FRESULT WriteSDCard() {
char * filename = 'TEST.txt';
char Buf[7] = {'H','e','l','l','o','
','
'};
uint8_t BufLen = 7;
FRESULT fr;
fr=f_open((FIL *)&MyFile, (char *)filename, FA_OPEN_ALWAYS | FA_READ | FA_WRITE);
if(fr){
return fr;
}
fr = f_lseek((FIL *)&MyFile,MyFile.fsize);
if(fr){
return fr;
}
fr= f_write((FIL *)&MyFile, (uint8_t *)Buf, BufLen, (void *)&BytesWritten);
if(fr){
return fr;
}
fr=f_close((FIL *)&MyFile);
if(fr){
return fr;
}
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
If WriteSDCard returns anything but FR_OK then when it unlinks the driver/unmounts and tries to link/mount again i get stuck in this while loop forever looking for the start bit:
#ifdef SDIO_STA_STBITERR
while(!__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND | SDIO_FLAG_STBITERR))
#else /* SDIO_STA_STBITERR not defined */
while(!__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND))
#endif /* SDIO_STA_STBITERR */
{
if(__HAL_SD_SDIO_GET_FLAG(hsd, SDIO_FLAG_RXDAVL))
{
*(tempscr + index) = SDIO_ReadFIFO(hsd->Instance);
index++;
}
}�?�?�?�?�?�?�?�?�?�?�?�?
I am using CubeMx 4.0 STM32Cube V1.0, RTOS is also enabled.
Am I possibly seeing WriteSDCard return an error if the task has context switched during an f_*** operation?
Thanks
2017-03-13 03:11 AM
A new thread would have made more sense after 3 years.
I'm pretty sure that the SDIO and FATFS are not thread safe. I'd lean to having IO in a single thread, as you would need to serialize access to the peripheral / card.
I would generally try to avoid repetitively mounting and unmounting the card, f_sync or f_close should be sufficient to push all file system structures onto the media
2017-03-13 05:11 AM
Hi
Thank you for your reply, It is all within one thread (task), the task calls the WriteSDCard function which is in the same thread isn't it? It only really ever unmounts if an error occurs.
Ryan