cancel
Showing results for 
Search instead for 
Did you mean: 

Fatfs write problem

mahmoud_dhaiwi
Associate II
Posted on May 21, 2015 at 17:59

Hello

I use STM3210e-eval.

I want to implement Fatfs for the SDcard (using SDIO interface)

Thats work !

I can create a file or a directory, read a file, write in the file, delete file, rename file.

the problem is that: when I want to write multiples line in the file. Just one line is written in the file then the system go in the infinite loop of Default_Handler !!

to write multiples line, I tried this two methods (one using f_pritnf and the other using f_write):

1) ''in a loop''

res = f_mount(0, &Fatfs);

res = f_open(&Filsd, ''0:LOG.TXT'', FA_WRITE | FA_OPEN_ALWAYS);

f_printf(&FilSD, ''ABCD\n'');

f_close(&Filsd);

f_mount(0, NULL);

2) '' in a loop''

writeTextBuff[]= ''ABCD\n''

res = f_mount(0, &Fatfs);

res = f_open(&Filsd, ''0:LOG.TXT'', FA_WRITE | FA_OPEN_ALWAYS);

res = f_lseek(&Filsd, f_size(&Filsd));

bytesToWrite =sizeof(writeTextBuff) - 1;

res = f_write(&Filsd,writeTextBuff,bytesToWrite, &bytesWritten );

f_close(&Filsd);

f_mount(0, NULL);

this first time, the code is executed normally, but the second loop the system go in Default_Handler at f_printf in method 1. and at f_lseek in method 2

Any Help please ?

Thank you

#stm32 #dma #fatfs #sdio #sd
3 REPLIES 3
Posted on May 21, 2015 at 18:09

Default_Handler suggests that you're getting an interrupt you're not servicing with a real routine.

Do you have a Hard Fault Handler?

I'm not sure of the wisdom of standing up and tearing down the file system context is this fashion, and the lack of any error handling or review of the return codes.

I would suggest you look very carefully about how your lower level code tears down the interface, and how the initialization code deals with being called multiple times.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
mahmoud_dhaiwi
Associate II
Posted on May 21, 2015 at 18:23

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6bL&d=%2Fa%2F0X0000000brY%2Fmu8w4hZOqAFolFo5ldTEXe2zj64aMGp8jqo9UGd8yPY&asPdf=false
Posted on May 21, 2015 at 18:29

Then you really need to look at what the processor is faulting on, and fix that.

Get a proper Hard Fault Handler, see the Joesph Yiu examples (books/online)

Identify where in your code it fails. Whether it's an errant pointer or a read/write to memory that doesn't exist.

You might also want to zero out the file system and file handle structures before you start each iteration, in case there are some values left in there that are no longer valid.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..