Skip to main content
Visitor II
February 9, 2012
Question

SDIO and SD fat access example?

  • February 9, 2012
  • 82 replies
  • 16079 views
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
    This topic has been closed for replies.

    82 replies

    Visitor II
    September 19, 2016
    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);

    }

    Graduate II
    September 19, 2016

    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);
    }