File append mode in FatFSSDIO library

How do I open a file in SD card for appending using FatFSSDIO library? I checked the FatFs development site, FatFs - Generic FAT Filesystem Module. The file append mode is not available until version 0.13; while the FatFS library used in Ameba is 0.10. I think this library is already compiled into lib_arduino.a. Is it possible to replace the FatFS library with a newer one?

Hi Which Ameba board are you using?

Yes it’s possible, but not easy.

If you wanna manuplate the files open on FatFS over SD card, you can check out all the API available at

https://amebaiotdocuments.readthedocs.io/en/latest/ambd_arduino/AMB23/api_documents/Class%20SdFatFile.html

Also there are example available too at
https://amebaiotdocuments.readthedocs.io/en/latest/ambd_arduino/AMB23/examples_and_components/Peripheral%20Examples/FatfsSDIO%20-%20File%20system%20in%20SD%20card.html

I am working on AMB23 (RTL8722DM_MINI).

As you may know, arduino package comes with pre-compiled archive libraries (.a) to speed up the compilation on Arduino IDE, so all the fatfs related src are archived in the lib_arduino.a library under the varient folder in your arduino ameba package directory.

If you wanna add your own lib, you can,

  1. Remove the 0.10 fatfs src from the above mentioned lib
  2. Add the 0.13 to your sketch folder so they will be compiled with the .ino file and linked to other src during linking stage

It’s a bit of hassle if you are new to this process

Thanks for the response. I will try it later. But with 0.13 (or newer version) installed in my own sketch folder, will it cause any compilation or link errors such as duplicated functions/variables? I was thinking of a more complicated approach, renaming the function and variable names to prevent any duplicated problems!!

@mstsai If you removed all 0.10 src from the archive lib, you should not face any duplicate definition errors

I am not sure if I was doing correctly. But I did remove the src directory, the directory of 0.10c looks like

user@ubuntu:~/.arduino15/packages/realtek/hardware/AmebaD/3.1.2/system/component/common/file_system/fatfs/r0.10c$ ls -l
total 4
drwx------ 2 user user 4096 Sep 13  2021 include
user@ubuntu:~/.arduino15/packages/realtek/hardware/AmebaD/3.1.2/system/component/common/file_system/fatfs/r0.10c$ 



I wrote a simple function with the same function name, f_stat as

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "ff.h"


FRESULT f_stat(const char* path, FILINFO *fno) {

    return 0;
} 

I got the multiple definition error during the link stage as follow:

/home/user/.arduino15/packages/realtek/hardware/AmebaD/3.1.2/variants/rtl8722dm_mini/lib_arduino.a(ff.o): In function `f_stat':
/cygdrive/d/0000_GIT/000_D_test/amebad/v6.2/project/realtek_amebaD_va0_example/GCC-RELEASE/project_hp/asdk/../../../../../component/common/file_system/fatfs/r0.10c/src/ff.c:3297: multiple definition of `f_stat'
libraries/AmebaSD20/utils.c.o:/home/user/.arduino15/packages/realtek/hardware/AmebaD/3.1.2/libraries/AmebaSD20/src/utils.c:42: first defined here
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board AMB23 (RTL8722DM_MINI).

Or, should I remove everything from 0.10c including the header files ?

Thanks

Ok, I misunderstand your suggestion. Instead of remove the “source”, I need to remove the ff.o from lib_arduino.a,

$ ar d lib_arduino.a ff.o

Then, I can use the ff.c in my sketch.

Hi C files at these path are NOT to be compiled into the firmware, they are only there for reference purpose. Only header files got included where necessary.

To alter the true definition of certain functions and memory contrainers, you have to follow my steps list above to remove the compiled object files from the archive lib (lib_arduino.a) and then add your own source code to the sketch afterwards

That’s correct, good work~