AnsweredAssumed Answered

STM32F103RBT6 and SD Card with FAT32

Question asked by ignat.mihai on Jan 23, 2015
Latest reply on Jun 30, 2015 by hinterdorfer.christi
I have a project in which I want to log some data into a text file on a SD card, using STM32F103RBT6. I managed to program the interface driver through SPI, since this chip doesn't have SDIO. It works fine and I can read the card's data from its CSD register. I want to write into a text file and I have to create the text file first.
I began experimenting with FatFS but I didn't manage to understand how it works. The library has several functions used for disk and file system initializations but I don't understand which to use first. On top of that, after I managed to write and compile a program with some of those functions, I got a linker error stating that the memory was overflown by 55kB.
I then experimented with dosfs and managed to read the FAT header. But now I can't create or write the file, although I made the proper setting, I think.

The code is:

intwrite_file(uint8_t *buffer)
    uint8_t sector[SECTOR_SIZE], sector2[SECTOR_SIZE];
    uint32_t pstart, psize, i;
    uint8_t pactive, ptype;
    uint32_t cache;
    FILEINFO* fi;

    /* Opens an existing file. If not exist, creates a new file. */
    if(DFS_OpenFile(&vi, "WRTEST.TXT", DFS_WRITE, sector, &fi))
        //printf("error opening file\n");
        DFS_Seek(&fi, f_size(fi), sector);
    DFS_WriteFile(&fi, sector, &buffer[0], &cache, SECTOR_SIZE);

The code was ported from the stsw-stm32040 pack, which is for STM32F4, I think.

I am opened to any suggestions. Thank you and have a nice day.