cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 and FatFS. SD Card mounting issue.

Oleg M
Associate
Posted on October 04, 2017 at 11:12

Simple issue description: f_mount function from FatFS causes stack problem .

More detailed description:

We have a project in which we use the processor STM32F407Z and we have to read files from an SD Card with using of FatFS. We have generated a test project by STM32CubeMX ( 4.21.0 ver ) and launched it on our plate with mentioned processor. The debugger which we use is SEGGER J-Link Base.

Problem description:

Right after f_mount function works out we get the following warning:

Mon Sep 25, 2017 11:47:03: The stack pointer for stack 'CSTACK' (currently 0x04F95E41) is outside the stack range (0x2000FBE0 to 0x2000FFE0)

If the program is just launched, inspite of the warning a SD Card will be mounted.

But if we debug the program step by step, we get the warning and then the program 'gets stucked'. SD Card will not be mounted in this case.

I attached the test project. Function f_mount is located at string 580 in the main.c file.

SD Card reading is initiated at string 1533 in function console_main in the main.c file. Later the function process_fs launches and calls f_mount function.

I suppose the problem doesn't break mount function itself, but it crashes something in parrallel tasks. Maybe incorrect pointer is generated somethere.

#f_mount-sdcard #stack-pointer
3 REPLIES 3
Tilen MAJERLE
ST Employee
Posted on October 04, 2017 at 13:07

Hello

oleg_m

,

FATFS and FIL structures from FATFS take more than 1kB together of memory. You placed them on stack. In this case, place them to RAM (global variable) and your issue should be resolved. If you still want them on stack, then increase thread stack which is not set to 256 bytes on line 7

Try to set stack size to 1500 bytes for test. Please make sure, your OS heap is big enough to allocate memory for it.

Best regards,

Tilen

Posted on October 04, 2017 at 17:36

Thank you for your advice, but unfortunately  it didn't help.

I declared variables

static FATFS mynewdiskFatFs;

static FIL fd;

but i'm still experiencing the same trouble. Somethimes it only gives the warning but works. But rather it 'gets stucked' after the first or the second f_mount try. If i debug step by step it always gets stucked.

Posted on October 05, 2017 at 10:13

Hello Oleg,

This sounds to small overflow of stack. Try to increase thread stack where f_mount is executed together with f_write.

Best regards,

Tilen