cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX v4.26 SD Card Problem Continues [STM32F4 Discovery]

Ogulcan Ariyurek
Associate II
Posted on June 19, 2018 at 14:21

Hi,

I've been dealing with the SD card problem since the CubeMX version 4.

Here are the corresponding parts of my code:

...

...

...

/* USER CODE BEGIN PV */

/* Private variables ---------------------------------------------------------*/

FATFS myFATFS = {0};

FIL myFILE;

UINT testByte;

/* USER CODE END PV */

...

...

...

/* USER CODE BEGIN 2 */

if(f_mount(&myFATFS, SDPath, 1) == FR_OK){

char myPath[] = 'WRITE1.TXT\0';

f_open(&myFILE, myPath, FA_WRITE | FA_OPEN_ALWAYS);

char myData[] = 'Hello World\0';

f_write(&myFILE, myData, sizeof(myData), &testByte);

f_close(&myFILE);

HAL_Delay(1000);

}

/* USER CODE END 2 */

...

...

...

Here, the problem is in f_mount, it doesn't go forward. Debugging further, the code stucks in 'ff.c' file at the following bold line (line 3050):

/* Find an FAT partition on the drive. Supports only generic partitioning rules, FDISK and SFD. */

bsect = 0;

fmt = check_fs(fs, bsect); /* Load sector 0 and check if it is an FAT-VBR as SFD */

if (fmt == 2 || (fmt < 2 && LD2PT(vol) != 0)) { /* Not an FAT-VBR or forced partition number */

for (i = 0; i < 4; i++) { /* Get partition offset */

pt = fs->win + (MBR_Table + i * SZ_PTE);

br[i] = pt[PTE_System] ? ld_dword(pt + PTE_StLba) : 0;

}

This problem continues in the last 4 version, and still not fixed. Can someone try to create a project from scratch with STM32CubeMX version 4.26 and FW F4 v1.21 which are both the lastest versions by the moment?

Here are few extra notes:

- I set minimum heap and stack size as 0x2000 and 0x4000.

- I'm using Keil uVision MDK v5.15 with compiler v5.05 update 2 (build 169).

- My operating system is Windows 7 Pro SP1 64 bits.

- I'm sure that there is no hardware issue as I was able to run the SD card with a example project.

Regards,

Ogulcan

#f_mount #stm32cube-fw_f4-v1.0 #cubemx-4.26 #fw_f4-v1.0 #sd-card #cubemx #stm32f4 #fatfs #sdcard-fatfs

Note: this post was migrated and contained many threaded conversations, some content may be missing.
26 REPLIES 26
Altamash Abdul Rahim
Associate II
Posted on June 28, 2018 at 11:03

Hello,

 I also encountered issues with FATFS and SD-CARD a while ago. Code failed at fmount() and it was because SD-CARD was not initialised in SD_initialize() function.(Note: This function is genrated by Cube)  I have attached the link to the issue below.

https://community.st.com/0D50X00009XkX10SAF

 
Posted on July 11, 2018 at 09:00

Please can you post the Image of other side of the sdcard board for Soldering reference .also please share the working code since i have been trying from past 3 weeks.(STM cubemx+Truestudio9.1)

Thank you

Ashwinraj

Posted on July 11, 2018 at 09:53

Dear Ashwinraj,

Please refer to following URL and picture.

https://github.com/jason0627/STM32F4-Discovery_SDIO_4bit_OK

 0690X00000604YmQAI.jpg

Best regards,

Jason

Posted on July 11, 2018 at 10:02

Hi,

I've spent months on the issue and thanks to Jason, I've managed to make it work. I've found out that I actually need to set DMA and NVIC in the versions after 4.21, so I suggest you to look at the DMA and NVIC setttings.

Cheers,

Ogulcan

Posted on July 12, 2018 at 09:41

Thank you very much. but i figured out solution for few latest cubeMX4.26

1) Enable DMA

2) use 22 ohm series resistor

3) In cubemx change the application structure to Advanced(check attach image) or else in truestudio you will get path entry warning 0690X0000060M8YQAU.png0690X0000060M8dQAE.png

URane
Associate II

Dear Ashwinraj,

can you share complete project along with cubemx ioc file to understand it completely?

mhal
Associate II

Hi,

My problem was slightly different. 1 bit mode with DMA worked but 4-Bit mode did not. In 4-Bit mode f_mount was hanging.

I'm using the STM32F769NI discovery board and the system clock needed to be higher than the SD card clock. Originally had SDMMC clock set to divider of 0 but it was flacky. Changed system clock to run faster than SDMMC clock and used PLL48MHz as input clock to SD module. After this change no problems with f_mount or reading or writing.