cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX + FatFS - Keil works, TrueStudio not

jackbauer007
Associate II
Posted on June 30, 2016 at 13:02

Hello my friends,

I am new to FatFs and I want to write something on the SD-Card. I initialize SDIO and FatFs over STM32CubeMX. I am using the STM32F4 Discovery and the Baseboard which has a SD-Connector. If I create the project for Keil I can write to the SD-Card. But if I create the project for Truestudio or SW4STM32 I can not write to SD-Card.

/* USER CODE BEGIN 2 */
MX_FATFS_Init();
if (f_mount(&SDFatFs, (TCHAR const*) SD_Path, 0) != FR_OK) {
/* FatFs Initialization Error */
Error_Handler();
}
if (f_open(&MyFile, ''STMTXT'', FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) {
Error_Handler();
}
res = f_write(&MyFile, wtext, sizeof(wtext), (void *) &byteswritten);
if ((byteswritten == 0) || (res != FR_OK)) {
Error_Handler();
}
f_close(&MyFile);
/* USER CODE END 2 */

I put exact the same Code in to all three projects but only Keil works. It is not a compilation error. Mount works too but always get stucked in f_open. I have noticed thatHAL_SD_ReadBlocks returns an Error. I have created multiple project with FreeRTOS and without. Always works in Keil but not with Truestudio and SW4STM Does somebody know what I am doing wrong? Best Regards, Kevin #!stm32-!fatfs-!keil-!truestudio
5 REPLIES 5
slimen
Senior
Posted on June 30, 2016 at 13:38

Hi,

Could you please precise which version of HAL, STM32CubeMx and toolchain are you using?

Regards

jackbauer007
Associate II
Posted on June 30, 2016 at 13:47

Hello,

sorry that I have not noticed it.

I am using STM32CubeMX v4.15.1 and Firmware Package 1.12.0

TrueStudio 5.5.2 

SW4STM32 v1.8 from May 4, 2016.

Keil 5.17

Best Regards

Kevin
Posted on June 30, 2016 at 14:39

How about SDIO and DMA interrupt handlers?

Not compiler error/failure? You sure? Does behaviour change with optimization off vs on? Check also statics are being cleared.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
slimen
Senior
Posted on June 30, 2016 at 15:22

Hi lange.kevin, 

It's better to compare your generated code with one of the provided FatFS applications  working with SD-Card, as this example:

STM32Cube_FW_F4_V1.12.0\Projects\STM32F412G-Discovery\Applications\FatFs\FatFs_uSD

Regards

jackbauer007
Associate II
Posted on July 01, 2016 at 13:28

Thank you guys. You got me in the right direction. 

I have made mistakes with DMA.

Sometimes you need to talk to somebody to solve the obvious mistakes.