cancel
Showing results for 
Search instead for 
Did you mean: 

SD Card Cannot be mounted successfully using the Code generated by CubeMX

Lingjun Kong
Associate III
Posted on July 17, 2017 at 13:01

to use the FATFs on the STM32F746NG-Discovery Board, I generate the code using the CubeMX.

this is my main.c file.

during the debugging, I found that the value returned by the f_mount is FR_NOT_READY, so that the function will always fall into Error_Handle();

0690X00000607TyQAI.png

but with the same board and sd card, the demo project:

STM32Cube_FW_F7_V1.7.0\Projects\STM32746G-Discovery\Applications\FatFs\FatFs_uSD\MDK-ARM

it could work well.

I want to know whether there is any other thing I've forgot to add to the project? Or the code generator itself has a big bug?

the method i generate the code is:

  1. select the board
0690X00000607OaQAI.png

2. config the pinout

0690X00000607bhQAA.png0690X00000607WiQAI.png

and choose the FATFS

0690X00000607ZNQAY.png

3. resolve the clock

0690X00000607bmQAA.png

4.do nothing

0690X00000607bwQAA.png

5. change the heap size

0690X00000607brQAA.png

7. and generate the project

8.open project and add this line to main.c

FATFS SDFatFs; /* File system object for SD card logical drive */

FIL MyFile; /* File object */

char SDPath[4]; /* SD card logical drive path */

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

{

Error_Handler();

}

and rebuilt it, debug, falls into error_handle.

11 REPLIES 11
GreenGuy
Senior III
Posted on July 07, 2018 at 02:24

My bad for implicating the HAL code.  To be specific:

1) the stm32h743i_eval_sd.c code (used in the application example in the repo which does work) doubles with the bsp_driver_sd.c generated by CubeMX.

 There significant differences.  Notably, the handling of the detection pin unique to the 743i_eval board via the IO port expander.  The other differences are __weak   assignments that are eventually redefined.

The sd_diskio.c appears to be generated by CubeMX using the sd_diskio_dma_rtos_template (I am guessing).  I ran a diff of sd_diskio_dma_rtos_template against sd_diskio.c and they  do not contain any code differences except for the user code areas.  I did not think to do that before since the project\application example was using the template file with the 'template' removed from the file name and the #include '...h' fixed to point to the appropriate ..._eval .h.

So questions for John: 

1) is the information you show taken from code generated by CubeMX?

2) was it using the 743i_eval board?

3) does the code also open/read/write without error? (I ask because you show the result of a mount which does work for me as well.)

4) If all the above are affirmative, can you attach a CubeMX project (.ioc) and a diff file for the generated code that needed adjustment as well as adjustments to the BSP/Driver code?

Posted on July 07, 2018 at 01:37

the bsp code works.  instead of excluding the bsp code, exclude the non-working hal code

Found uSD Card

uSD file system mounted

             MicroSD Card

--------------------------------------

 Manufacturer     : SanDisk

 Product name     : SU04G

 Revision         : 0x80

 Serial number    : 0xB2D90CEA

 Manufacture date : 0x103

 Card type        : SDHC/SDXC

 Version          : 1

 Class            : 1461

 Block Number     : 7744512

 Block Size       : 512

 Capacity         : 3965190144 bytes

 Status           : TRANSFER