cancel
Showing results for 
Search instead for 
Did you mean: 

SDIO and SD fat access example?

natblist
Associate
Posted on February 09, 2012 at 01:06

Hi Chaps,

Going slowly mad trying to get Chan Fat working with the sdio libs on a stm32f4.

I'm using the most recent (1.0.0) library for the F4, and the low level access demo within that library builds and (at least appears to ) work OK. 

I've spent many, many hours attempting to patch in 0.9 version of fatfs from chan (thks chan, you're a hero) - but I can't get it to work.

If possible, I'd really really appreciate a demo project/source (or direction to - though I've scoured the web and can't find anything that works!)

I'll post separately about the current problems I'm having with the my current build, but a working example would sort it.

Many thanks,

nat.

#hse-sdio-stm32 #stm32-fat-chanfat-fatfs-sdio #sdcard-stm32f4-sdio-fatfs #sdcard-stm32f4-sdio-fatfs
84 REPLIES 84
cleonb322
Associate III
Posted on September 19, 2016 at 22:52

If I closed a file and then reopen it, I cannot write more data to it after reopening it, but if i keep it open i can write as many lines as i want then close it after i am finished writing. Does anyone have a similar issue withe ELM Chang's FATFS?

See the example below. Thanks. if (f_mount(&FatFs, '''', 1) == FR_OK) { f_mkdir (''TEST''); count = 0; while(count < 200){ if(f_open(&fil, ''TEST/test.txt'', FA_OPEN_ALWAYS | FA_WRITE) != FR_OK){ break; } else{ sprintf(array,''This is file entry number: %d '',count); f_puts(array, &fil); if(f_close(&fil) != FR_OK){ break; } } count++; } f_mount(0, '''', 1); }

http://stackoverflow.com/questions/39560704/elm-changs-fatfs#

If I close a file and then reopen it, I cannot write more data to it after reopening it, but if i keep it open i can write as many lines as i want then close it when i am finish writing. See the example below. Thanks.

if (f_mount(&FatFs, '''', 1) == FR_OK) { f_mkdir (''TEST''); count = 0; while(count < 200){ if(f_open(&fil, ''TEST/test.txt'', FA_OPEN_ALWAYS | FA_WRITE) != FR_OK){ break; } else{ sprintf(array,''This is file entry number: %d

'',count); f_puts(array, &fil); if(f_close(&fil) != FR_OK){ break; } } count++; } f_mount(0, '''', 1);}

cleonb322
Associate III
Posted on September 19, 2016 at 23:03

@clive 

If I close a file and then reopen it, I cannot write more data to it after reopening it. Does anyone have this problem? if I execute the following code it will not save all the lines, it will save only the last line of data. 

if (f_mount(&FatFs, '''', 1) == FR_OK) {

      f_mkdir (''TEST'');

      count = 0;

      while(count < 200){

          if(f_open(&fil, ''TEST/test.txt'', FA_OPEN_ALWAYS | FA_WRITE) != FR_OK){

              break;

          }

          else{

              sprintf(array,''This is file entry number: %d\r\n'',count);

              f_puts(array, &fil);

              if(f_close(&fil) != FR_OK){

                  break;

              }

          }

          count++;

      }

      f_mount(0, '''', 1);

}

Posted on September 20, 2016 at 01:08, cleaned up messy forum transition 6-May-2023

Seek to the end of the file

...
// Incremental write test, appending to end-of-file
if (f_open(&fil, "LOG.TXT", FA_OPEN_ALWAYS | FA_WRITE) == FR_OK)
{
  UINT BytesWritten;
  const char string[] = "Another line gets added";
  f_lseek(&fil, fil.fsize); // newer perhaps f_size(&fil) macro?
  f_write(&fil, string, strlen(string), &BytesWritten);
  f_close(&fil);
}

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 23, 2017 at 12:08

Hi,

Can you tell me how do you measure the writing speed to ur sd card???

Thanks & Regards

Sameena Shaikh

BYPASS is problematic on the F2/F4 implementations. ST want's you to use at least a DIV2 of the clock. However you can clock the SDIO peripheral from a 75 MHz PLL clock getting you 37.5 MHz on the bus. Problem then is that USB and CRYP don't work as wrong speed, and too fast.

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