Hello, I'm trying to setup the flash-fs library with SPI SD-card on STM32F100 device. I've modified the SPI_STM32F100x.c driver to match with SPI2 device and needed I/O (CS, SD detect..)
The finit(), fformat() and fopen() functions are working. I'm able to format the card, create new files or open an existing file.
The problem comes when I try to write data into a file : nothing is written on the file. However, the fputs() function I'm using is returning 0 (OK).
I'm using RTX and the flash-fs library is used in a task :
/* Wait until the Card is ready*/ retv = finit ("M0:"); if(retv == 0) { // Card initialized sucessfully // Open/create output file fout = fopen("M0:\\test.txt","w"); if (fout != NULL) { // Write text in the file salut = fputs("fhghr", fout); // Close file fclose (fout); } } else if (retv == 1) { // Card not initialized } else if(retv == 2) { // Card is not formatted retv = fformat ("M0:Breitling /FAT32"); if (retv == 0) { // Format OK } else { // Cannot format }
Can someone try to help me?
Thanks and bests regards
Michaël
Keil example. Notice the difference from yours:
#include <rtl.h> #include <stdio.h> void tst_fputs (void) { FILE *fout; fout = fopen ("Test.txt","w"); if (fout != NULL) { fputs("This is an example for fputs.\n", fout); fclose (fout); } }
Thank's for your help. But this doesn't change anything and the return code of fputs is always 0, what means that the function terminates correctly... When I look on SPI signals, this is no activity during fputs() function execution. On fclose() function, some frames are sent but I don't see any data stream with expected content. I think the library is not writting anything on the SD card during fputs() execution..
Bests regards
In addition, the fgets() function is also returning 0 in case the file exists on SD-Card. But I'm not able to read any content of this file (I've created the file using a PC), the returned string is null.
Note that your test string:
// Write text in the file salut = fputs("fhghr", fout);
does not have one specific addition that the Keil string has:
fputs("This is an example for fputs.\n", fout);
i might be off base here, but as I remember it all strings need to either be flushed or terminated with the carrage return to be written to memory. When I tested this is a subtle distinction that is not highlighted...