Questions tagged [fatfs]

FatFs is a generic FAT file system module for small embedded systems.

The FatFs module is written in compliance with ANSI C (C89) and completely separated from the disk I/O layer. Therefore it is independent of the platform. It can be incorporated into small microcontrollers with limited resource, such as 8051, PIC, AVR, ARM, Z80, 78K and etc.

Features

  • Windows compatible FAT file system.
  • Platform independent. Easy to port.
  • Very small footprint for code and work area.
  • Various configuration options:

    • Multiple volumes (physical drives and partitions).
    • Multiple ANSI/OEM code pages including DBCS.
    • Long file name support in ANSI/OEM or Unicode.
    • RTOS support for multi-task operation.
    • Multiple sector size support upto 4KB.
    • Read-only, minimized API, I/O buffer and etc...

Application Interface layer

  1. File Access

    • f_open - Open/Create a file
    • f_close - Close an open file
    • f_read - Read data
    • f_write - Write data
    • f_lseek - Move read/write pointer, Expand size
    • f_truncate - Truncate size
    • f_sync - Flush cached data
    • f_forward - Forward data to the stream
    • f_gets - Read a string
    • f_putc - Write a character
    • f_puts - Write a string
    • f_printf - Write a formatted string
    • f_tell - Get current read/write pointer
    • f_eof - Test for end-of-file
    • f_size - Get size
    • f_error - Test for an error
  2. Directory Access

    • f_opendir - Open a directory
    • f_closedir - Close an open directory
    • f_readdir - Read an item
    • f_findfirst - Open a directory and read first item found
    • f_findnext - Read a next item found
  3. File/Directory Management

    • f_stat - Check existance of a file or sub-directory
    • f_unlink - Remove a file or sub-directory
    • f_rename - Rename or move a file or sub-directory
    • f_chmod - Change attribute of a file or sub-directory
    • f_utime - Change timestamp of a file or sub-directory
    • f_mkdir - Create a sub-directory
    • f_chdir - Change current directory
    • f_chdrive - Change current drive
    • f_getcwd - Retrieve the current directory and drive
  4. Volume Management

    • f_mount - Register/Unregister a work area of a volume
    • f_mkfs - Create an FAT volume on the logical drive
    • f_fdisk - Create logical drives on the physical drive
    • f_getfree - Get total size and free size on the volume
    • f_getlabel - Get volume label
    • f_setlabel - Set volume label
  5. Device Control Interface layer

    Since the FatFs module is a file system layer, it is completely separated from the physical devices, such as memory card, harddisk and any type of storage devices. FatFs accesses the storage devices via a simple interface shown below. The low level device control module is not a part of FatFs module. It is provided by implementer. Also sample implementations for some platforms are available in the downloads.

    • disk_status - Get device status
    • disk_initialize - Initialize device
    • disk_read - Read sector(s)
    • disk_write - Write sector(s)
    • disk_ioctl - Control device dependent features
    • get_fattime - Get current time.
118 questions
1
vote
1 answer

Program to find the newest file among unknown number of files

I need to write a program for a STM32 MCU with C and FATFS, to find the newest file among unknown number of files. Files names contain their creation dates, the numbers in the file name are separated with "_". for example:…
vouria
  • 25
  • 3
  • 9
1
vote
0 answers

STM32 I2S with DMA playing slow

I want to implement a WAV/MP3 player(now let's just say WAV) with an STM32, it reads it from the SD with FATFS, then transfer it to the I2S buffer with DMA. The problem is that when I plug my speakers, it plays the song at the correct pitch(tone)…
1
vote
0 answers

Fatfs detect SD card removal

I have an Issue with my SD card that, if it is removed it is not detected. (Removed manually). Therefore, when I try and use the SD card I get errors as it is not present. So I need to detect if the SD card is removed / inserted. If it is inserted…
Thomas Morris
  • 794
  • 5
  • 26
1
vote
0 answers

Create another txt file on the sd card if there is already an existing file using FATFS

I want to store some data to sd card using FATFS (STM32 micro-controller), but i have a problem i want to create a new file every time if there is already a file (from older experiments). So can someone give an example how to do that? For example if…
1
vote
1 answer

Assersion error using f_printf of fatfs, but f_write works fine

I have a small piece of code that opens a file, reads a single number, adds one and writes it back to the file. It works fine when I use f_write, but f_open returns FR_INT_ERR. I'm using version R0.12c. The code that generates error: FIL…
anishtain4
  • 2,342
  • 2
  • 17
  • 21
1
vote
1 answer

Reading data from a text file line by line into arrays using strtok in C

Currently trying to read data from a text file line by line using strtok and a space as a delimiter and save the info into different arrays. Im using the FatFs library to read the file from an sd card. Atm im only trying to read the first 2 elements…
1
vote
0 answers

FatFS f_write never returning

I am trying to write to a file on an SD card using an STM32F401RET6 development board. I am using an SDIO adapter I got on amazon (https://www.amazon.ca/gp/product/B07C26YZPK/ref=oh_aui_detailpage_o06_s00?ie=UTF8&psc=1). In STM32CubeMX, I have…
Marcel
  • 1,034
  • 1
  • 17
  • 35
1
vote
1 answer

Using f_mount to read and write data to text file

In my Application I need to open, read and write data to a text file using the calls f_open, f_read, and f_write. It is failing to open the .txt file res = f_open(&f_header.file, file_path, FA_OPEN_EXISTING | FA_WRITE | FA__WRITTEN | FA_READ |…
yagami
  • 149
  • 2
  • 12
1
vote
0 answers

How to write a program to record sound and write it to the SD card?

I am using a STM32L476G_EVAL board and Eclipse(C language). I need to write a program which can record sound and write the obtained samples of the sound to the SD card. I have two separate codes, one for recording and reproducing the sound which…
1
vote
1 answer

How to get largest free contiguous block of memory in FatFs

Using the FatFs and their API, I am trying to pre-allocate file system space for the remainder of the drive to write files of unknown sizes. At the end of the file write process, any unused space is then truncated (f_truncate). However, I'm having a…
LaneL
  • 737
  • 1
  • 6
  • 25
1
vote
2 answers

Using FatFs causes infinite loop in f_write on PIC18F46J50 uC

Im trying to implement the FatFs module for a project for several days now. My low-level I/O configurations are correctly implemented as i can see the signals using an oscilloscope. But i cant seem to get a proper write working on the SD-Card. All i…
keko
  • 37
  • 10
1
vote
1 answer

Cannot mount SD using FatFS on STM32

I'm trying to write to a MicroSD-Card using STM32F405 chip. The pins are connected correctly and each pin on the MicroSD-Card slot can be written to by using HAL_GPIO_WritePin. (Messured with ossciloscope) I'm using CubeMX to generate the init code…
Poehli
  • 307
  • 4
  • 16
1
vote
2 answers

FatFS data corruption on read write

We are using Chan's FatFS with FreeRTOS and lwIP on a board incorporating Cortex-M4. The board is able to send and receive files over a TCP socket and store them on SD card using FatFS. I'm trying to test the functionality but seems like it's not…
Murat Şeker
  • 1,651
  • 1
  • 16
  • 29
1
vote
1 answer

SD card can't read write STM32f4

I am trying to interface sd card with STM32F4 but things are not working,code was developed using cubemx Interface is sdio 1 bit mode(due to pin constraints) SD card 8 Gb formated with default allocation size Steps taken to debug: I single step…
Punit Salian
  • 9
  • 1
  • 2
1
vote
1 answer

Data overwritten when opening file using 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) ==…
o_tech
  • 15
  • 1
  • 9