cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with FatFs and STM32Cube_FW_F7_V1.6.0 (Possible STM32Cube Bug)

Lori B.
Associate III
Posted on January 30, 2017 at 15:59

Hi all! I'm trying to interface a STM32F7 with an 32 GB SDHC card, using the latest firmware libraries.

I'm using a STM32f746G DISCO and I started from the project under STM32746G-Discovery/Appllications/FatFs/FatFs_uSD..

I wrote a simple function and I executed it in the main after linking the driver and mounting the disk, to test reliability. The function is the following, where I write 1000 files in a loop..

ErrorStatus Test(void) { FIL MyFile; FRESULT res;  uint32_t byteswritten;  TCHAR StringPath[100] = {0};  cont=0;  while(cont < 1000) { sprintf((char*)StringPath,'File%d.fil', cont);  res = f_open(&MyFile, StringPath, FA_CREATE_ALWAYS | FA_WRITE); if(res !=FR_OK) return ERROR;  res = f_write(&MyFile, (void*)TempBuffer, sizeof(TempBuffer), (void *)&byteswritten); if((byteswritten == 0) || (res != FR_OK)) { return ERROR; }  f_close(&MyFile);  cont++; }  return SUCCESS; }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

TempBuffer is a global uint8_t buffer of size 51

The problem is that after correctly writing some files, f_write returns 'FR_DISK_ERR' and I can't understand why..

Decreasing the buffer's size seems to allow a bigger number of files to be written before the error, but it doesn't solve it...

Actually the problem is part of a much bigger project, but since I'm trying to understand what's wrong, I'm trying to keep things as simple as possible. That's why I took a STM32Cube project and left it untouched apart from the function I wrote.. But I really can't get the point of this problem anymway..Any idea?

I'm not using DMA, nor SD peripheral interrupt (as in the example).. The file ffconf.h is left untouched with_USE_LFN = 0, _USE_STRFUNC=2,_MIN_SS=__MAX_SS=5. Systick priority is as low as possible (0x0F)..

#sd #fatfs #sd-card #stm32f7 #stm32 #stm32cube

Note: this post was migrated and contained many threaded conversations, some content may be missing.
18 REPLIES 18
Posted on February 20, 2017 at 10:02

Hi Nemui,

Thanks for your posts ! I'm very grateful !

I tried your code spirit in order to make my Micron 32Gb eMMC work correctly.

However , I get some strange behavior. In fact, when powering on the eMMC  a CMD_RSP_TIMEOUT error occurs 

randomly ( sometimes I get no error ) . I checked my Initialization clock frequency and was set to be less than 400KHz.

This same error ( 

CMD_RSP_TIMEOUT ) occurs also when I try to process write operation ( sometimes it doesn't occur ) !

If a SW command passes one time why it'snt the case all the time ? 

What could be the problem ?

please I need help

:(

 
Posted on February 20, 2017 at 12:11

Hi Elliot,

I found

an interesting

solution to my problem

with the

SD

card on

STM32F7

.

I changed the

settings

edges of the

CLK

signal.

STM32CubeMX

generates

automatically the

rising edge

. I used the

falling edge

. It is necessary to change the settings

in two files main.c and stm32f7xx_hal_sd.c. I use the STM32Cube_FW_F7_V1.5.1.

main.c

static void MX_SDMMC1_SD_Init(void)

{

  hsd1.Instance = SDMMC1;

  hsd1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;   // <<<< change to SDMMC_CLOCK_EDGE_FALLING

....

stm32f7xx_hal_sd.c

HAL_SD_ErrorTypedef HAL_SD_Init(SD_HandleTypeDef *hsd, HAL_SD_CardInfoTypedef *SDCardInfo)

{

  __IO HAL_SD_ErrorTypedef errorstate = SD_OK;

  SD_InitTypeDef tmpinit;

 

  /* Allocate lock resource and initialize it */

  hsd->Lock = HAL_UNLOCKED;

 

  /* Initialize the low level hardware (MSP) */

  HAL_SD_MspInit(hsd);

 

  /* Default SDMMC peripheral configuration for SD card initialization */

  tmpinit.ClockEdge           = SDMMC_CLOCK_EDGE_RISING;  // <<<< change to SDMMC_CLOCK_EDGE_FALLING

........

Petr

Posted on February 20, 2017 at 12:23

Hi Petr,

thanks for your response ! I will implement it then I will be back to give my feedback.

Otherwise , concerning the CMD_RSP_TIMEOUT error isn't a recurrent issue ? I didn't find a lot of information about it .

thanks,

Elliot

Posted on February 21, 2017 at 01:39

Dear Eliot,

You said 'sometimes it doesn't occur'...

Same situation I met,it doesn't match 'clock line impedance'.

STM32 can goes up to about 50MHz SDIO clock by ultra-fast rizing/falling toggling,

thus often generates tremendous ringing despite any clock frequency for unmached impedance pcb.

To suppress ringings,insert series resistor(22~47ohm) on nearby STM32's SDIO_CK.

See also attached application note for more detail.

Best regards,

Nemui.

________________

Attachments :

tnfc35_emmc_pcb_design_guide.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HyuE&d=%2Fa%2F0X0000000bDj%2FUzH2U2i_wIDpkZrxRbRlZmCbRaU0mjx6zR3eezMovzU&asPdf=false
Posted on February 22, 2017 at 10:17

Hi Nemui ,

Thanks a lot for your response !

I go back to check and I will let you what have been changed .

Thanks again  !

kind and best regards,

Posted on February 23, 2017 at 15:23

Hi 

Nemui,

I have checked my SDMMC_CLK line and I found that there's a 22 Ohm resistance . Is it enough ? Should I add another serial resistance?

I have to mention that with the STM32L486RG microcontroller, the max SDMMC_CK frequency I can get is 40MHz ( if I enable bypass mode and I put the CLKDIV to 0 ) . Now , I'm only working with 20 MHz frequency which isn't  too high I think .

Posted on March 01, 2017 at 02:16

Dear eliot,

Series resistor for impedance matching can set upto 47Ohm(must set nearby signal source).

I also use 47Ohm resistor on STM32F746G-discovery forcelly, it works well even 50MHz SDMMC Clock!

Best regards,

Nemui.

Lori B.
Associate III
Posted on April 21, 2017 at 09:50

FYI: The issue seems to be fixed in STM32CubeF7 V1.6.1, finally.

Posted on April 22, 2017 at 00:09

Nemui,

May I ask, how/where did you install the resistor in the clock line?

Do you have a picture?

-Bill