cancel
Showing results for 
Search instead for 
Did you mean: 

Why does f_write not work in CubeMX project

GreenGuy
Lead
Posted on March 18, 2018 at 18:29

I have two projects, one from the F746G-Discovery Projects repo called FatFs_uSD_RTOS, and one created from CubeMX based on the template for the F746G-Discovery board with FatFS and FreeRTOS enabled.  The CubeMX project code fails to write to the SD card with the f_write function timing out after 30 seconds.  Of course, the FatFs_uSD_RTOS example works.  I have spent a week now comparing the code execution and I am very confused about how the example project is even working at all. 

First, the CubeMX project, is timing out because the write complete callback is not being called and that is because the os message for the call back is not being set.

Second, in the example project (FatFs_uSD_RTOS), the SD card is not being initialized as it is in the Cube project with MX_SDMMC1_SD_Init.  However, it appears that as a result of the example project call to link the SD card to Fatfs the SDMMC_Init call in the stm32f7xx_ll_sdmmc.c seems to do the same thing.  But if I comment out the the MX_SDMMC1_SD_Init in the Cube project then the f_open call fails.  Odd since f_open also calls the HAL SDMMC_Init function. 

I am not sure the timeout issue is related to the init function difference. 

Has anyone successfully built code using CubeMX based on the F476G discovery board template that uses FreeRTOS, FatFS, SDMMC that writes and reads files to the SD card on the discovery board?

This post is a continuation of one I made a couple of weeks back but that post seems to be corrupted as it keeps crashing the web server with a 409 permissions issue.

#micro-sd-card #freertos+fat
3 REPLIES 3
Clive1 (HNL)
Senior II
Posted on March 18, 2018 at 19:20

>>This post is a continuation of one I made a couple of weeks back but that post seems to be corrupted as it keeps crashing the web server with a 409 permissions issue.

It's you not me..

This post flags up a red line, and when I first clicked on the thread it locked me out of two browser sessions, with an 'Access Denied' message. Something weird with your account metadata me thinks.

I'm not using CubeMX, but have observed very similar behaviour on the F4 and F7 boards when doing sporadic writes and close/open of log files at the top-of-hour. I instrument the fail paths in diskio layer for the media level read/write. What I see is a write failure due an TX UNDERRUN on the SDMMC. You need to use DMA because the system is unforgiving, and the LTDC/DSI soak significant bandwidth.

https://community.st.com/community/stm32-community/blog/2018/03/12/stm32439i-eval2-sdio-experiments

 

DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)

{

  DRESULT res = RES_ERROR;

...

    if (res!= RES_OK) printf('W %9d %3d %d (%08X)\n', sector, count, res, uSdHandle.ErrorCode);

    

  return res;

}

From 2-years ago

https://community.st.com/message/3665

 
Posted on March 18, 2018 at 19:23

0690X0000060A9lQAE.png

Cariati.Francesco

Posted on March 19, 2018 at 05:02

I've pinged Jive/Aurea on this, sorry for the annoyance this issue is causing to you all