This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

FatFs unresolved write methods

I'm trying to write some wrapper functions for interacting with the SD Card on the 129x.

The problem is that when I compile my code it can't seem to find the f_puts, or f_printf methods. All the other ff methods I'm using don't cause any issues (f_open, f_close, f_lseek..). I'm wondering if there is some pre-processor definition I need to use the write functions? I didn't see anything like that when I scanned through ff.h/ff.c

I'm not certain if I've written this function properly at all because I can't test it with the f_puts but here is what I have.

uint8_t sdcardLogError(char* errorFileName, char* error) {
    
    FRESULT fr;
    
    fr = f_open(&g_sErrorFile, errorFileName, FA_WRITE);
    
    // if error here return error number
    if (fr != FR_OK) {
        return 1; // Open file error
    }
    
    // Variable to hold the number of bytes written
    int16_t bw;
    
    // Move to the end of the file
    fr = f_lseek(&g_sErrorFile, f_size(&g_sErrorFile));

    // if error here return error number
    if (fr != FR_OK) {
        return 2; // Seek failure
    }
    
    // Write the line to the file
    bw = f_puts((const TCHAR*)error, &g_sErrorFile);
    
    // if error here return error number
    if (bw == -1) {
        return 3; // Write failed, end of file error
    }
    
    // No errors
    return 0;
}

which results in

unresolved symbol f_puts, first referenced in ./customlib/sdcard/sdcardio.obj

If I comment out the f_puts line, it compiles fine.

  • Hi,

    In my Tiva folder, I can find f_puts declared in third_party/fatfs/src/ff.h at line 232 and definition in ff.c line 4208.

    What toolchain do you use? did you added this folder (fats) as symbolic link to your project?

    Petrei

  • I'm using the TIv5.1.7 compiler through code composer studio.

    f_puts and f_printf are both in third_party/fatfs/src/ff.h and ff.c. I added ff.c as a linked resource to the project and "${SW_ROOT}/third_party" to my include paths.

    When I "open declaration" on f_puts CCS can find it. The syntax highlighter shows it as defined as well.

  • I just discovered the preprocessor conditionals that are holding me up.

    The f_putc, f_puts, and f_printf functions are all under !_FS_READONLY and _USE_STRFUNC

    This is the problem with not indenting preprocessor conditionals. It becomes difficult to determine whether or not you're inside one.

    I'm not certain what way I should go about defining _USE_STRFUNC, whether it gets defined based on something else or if I should just define it directly in my main project file.

  • Hi,

    I think your path "${SW_ROOT}/third_party" is not correct (it is incomplete) should be "${SW_ROOT}/third_party/fatfs/src" and "${SW_ROOT}/third_party/fatfs/port" - limiting at third_party does not go into folders. 

    Check your settings at Project | Properties | Resource | Linked Resources | Linked resources tab - and see if you have some "Absolute location" at top of the tab - if yes, click on each item below that line and then on the right side click Convert button to be converted to relative paths (eclipse request..)

    Also, about _USE_STRFUNC:

    _USE_STRFUNC is defined in /src/ffconf.h as

    line 39: #define _USE_STRFUNC 0 /* 0: disable or 1-2: Enable */

    line 40: /* To enable string functions set _USE_STFUNC to 1 or 2 */

    Suggest also to grab a good tool for finding keywords in folders - a good one is Total Commander.

    Petrei

     

  • The path is ok. I include the files as

    #include "fatfs/src/ff.h"

    That is how it's done in the TivaWare  SD Card example project.

    Is there any reason to switch from absolute location to relative location for the linked resources? I already have relative paths but I'm just wondering what the difference would be. In CCS on linux the linked resource paths are dropped whenever I try to copy/import a project so I have to re-link them all again. The gui editor for the linked resources is also broken and I have to manually put them into the .project file.

    I've got grep for keyword searches, I wasn't using it because I've been searching for text using the CCS(eclipse) search tool but came up empty handed for _USE_STRFUNC. I'm not sure if the SD Card example uses ffconf at all. It seems my real struggle with this is coming from the example project being a poor starting point.

    I grabbed the FatFs examples from ChaN and will use them as a reference instead. With any luck I should at least be able to get the board specific stuff from the Tiva example.

  • Hi,

    The Eclipse is more happy with relative paths - the absolute paths seems to be too bulky and in some cases (Win) even buggy so it is recommended to keep relative paths. I use OSX and if i do not set the relative ones, sometimes end in pin definition not found or even file not found, although is in path. Switching to relative removes all complaints (same on Win).

    [One suggestion then - seems ack is better/faster than grep]

    Keep in mind in sd-card example you have a port written for your micro - add also that file. And that supplied in Tiva is the last (or one of the latest) version of fatfs. The ffconf file may be/is used by the ff.*.* files, so there you may find out all about.

    Petrei

  • Thanks for the help.

  • One final question. I see now that ffconf.h is included in ff.h. However ffconf should be project specific and I don't really want to modify code in the TivaWare folder for one project and then have that code changed later on when working on another project. How do I handle this?

    Should I be making a copy of ffconf.h and placing it directly in my project folder? When ff.h includes ffconf.h, will it look for ffconf.h at my project root first or, as I suspect, continue to use the ffconf.h in the /fatfs/src/ folder?

  • Hi, 

    I think you may try - but also another possibility is to make a copy in the actual folder and name it ffconf-original.h; this will not be used by application, only ffconf will be used. When the project is finished and you start another one, name the file ffconf-app1.h and remove the "-original" suffix from copy (I know it is risky an unreliable..- I used something similar with an old .asm project, long time before git.). Or zip first the original folder before any modification.

    Or use some specific software for versioning - I think git is best.