• AVR Freaks

Hot!FatFs FIL object not being created? Problem with reference to .h files?

Author
PRWiley
New Member
  • Total Posts : 21
  • Reward points : 0
  • Joined: 2019/07/04 06:16:51
  • Location: Lewisburg PA USA
  • Status: offline
2019/08/17 12:22:48 (permalink)
0

FatFs FIL object not being created? Problem with reference to .h files?

I am trying to get FatFs Generic FAT Filesystem module R0.13c (no link because it triggers an error) set up on a PIC18F45K42. As far as I can tell I have the header and source files copied into the project. However, when I try to compile this test code:
 
#include "mcc_generated_files/mcc.h"
#include "ff.h"
#include "diskio.h"

FATFS FatFs; /* FatFs work area needed for each volume */
FIL Fil; /* File object needed for each open file */

/*
Main application
*/
void main(void) {
UINT bw;

// Initialize the device
SYSTEM_Initialize();

if (f_mount(&FatFs, "", 1) == FR_OK) { /* Mount SD */

if (f_open(&Fil, "test.txt", FA_OPEN_ALWAYS | FA_READ | FA_WRITE) == FR_OK) { /* Open or create a file */

if ((Fil.fsize != 0) && (f_lseek(&Fil, Fil.fsize) != FR_OK)) goto endSD; /* jump to end of the file to append data */

f_write(&Fil, "Hello world! This is text message written to sd card\r\n", 54, &bw); /* Write data to the file */

endSD: f_close(&Fil); /* Close the file */
}
}

while (1) {
// Add your application code
}
}

 
I get the following errors:
 
main.c:64:10: error: no member named 'fsize' in 'FIL'
if ((Fil.fsize != 0) && (f_lseek(&Fil, Fil.fsize) != FR_OK)) goto endSD; /* jump to end of the file to append data */
     ~~~ ^
main.c:64:44: error: no member named 'fsize' in 'FIL'
if ((Fil.fsize != 0) && (f_lseek(&Fil, Fil.fsize) != FR_OK)) goto endSD; /* jump to end of the file to append data */

 
I assume this is because something is going wrong with the declaration of the Fil object, but, being new to C and PICs, I am not sure what. Perhaps the complier can't find the code for defining the project? I note that #include <xc.h> is generating an "unresolved include" warning in the mcc.h file.
 
Can anyone suggest what might be going wrong and how I start to debug?
 
Many thanks.

Peter R. Wiley
I feel a lot more like I do now than I did when I came in.
#1

13 Replies Related Threads

    mbrowning
    Just a Member
    • Total Posts : 1504
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: online
    Re: FatFs FIL object not being created? Problem with reference to .h files? 2019/08/17 13:53:47 (permalink)
    +1 (1)
    /* File object structure (FIL) */

    typedef struct {
        FFOBJID    obj;            /* Object identifier (must be the 1st member to detect invalid object pointer) */
        BYTE    flag;            /* File status flags */
        BYTE    err;            /* Abort flag (error code) */
        FSIZE_t    fptr;            /* File read/write pointer (Zeroed on file open) */
        DWORD    clust;            /* Current cluster of fpter (invalid when fptr is 0) */
        DWORD    sect;            /* Sector number appearing in buf[] (0:invalid) */
    #if !FF_FS_READONLY
        DWORD    dir_sect;        /* Sector number containing the directory entry (not used at exFAT) */
        BYTE*    dir_ptr;        /* Pointer to the directory entry in the win[] (not used at exFAT) */
    #endif
    #if FF_USE_FASTSEEK
        DWORD*    cltbl;            /* Pointer to the cluster link map table (nulled on open, set by application) */
    #endif
    #if !FF_FS_TINY
        BYTE    buf[FF_MAX_SS];    /* File private data read/write window */
    #endif
    } FIL;

    I see no fsize element in the FIL struct type. What makes you think there should be?
    There's an fsize element in the FILINFO struct type.
    /* File information structure (FILINFO) */

    typedef struct {
        FSIZE_t    fsize;            /* File size */
        WORD    fdate;            /* Modified date */
        WORD    ftime;            /* Modified time */
        BYTE    fattrib;        /* File attribute */
    #if FF_USE_LFN
        TCHAR    altname[FF_SFN_BUF + 1];/* Altenative file name */
        TCHAR    fname[FF_LFN_BUF + 1];    /* Primary file name */
    #else
        TCHAR    fname[12 + 1];    /* File name */
    #endif
    } FILINFO;


    Oh well - there's always next year
    #2
    PRWiley
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2019/07/04 06:16:51
    • Location: Lewisburg PA USA
    • Status: offline
    Re: FatFs FIL object not being created? Problem with reference to .h files? 2019/08/17 14:01:34 (permalink)
    +1 (1)
    What makes me think it should be is that the code came from a tutorial here: https://www.studentcompanion.co.za/interfacing-sd-card-with-pic-microcontroller-xc8/  This source has been generally reliable, so I didn't think to check but obviously I should have.

    Peter R. Wiley
    I feel a lot more like I do now than I did when I came in.
    #3
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11285
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: FatFs FIL object not being created? Problem with reference to .h files? 2019/08/17 16:01:19 (permalink)
    +2 (2)
    Old versions of FatFS had FIL.fsize and FILINFO.fsize.  It was presumably dropped since it was redundant.
     
    #4
    PRWiley
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2019/07/04 06:16:51
    • Location: Lewisburg PA USA
    • Status: offline
    Re: FatFs FIL object not being created? Problem with reference to .h files? 2019/08/20 07:59:21 (permalink)
    0
    Making some progress, but I am getting a host of warnings and errors when trying to compile, to wit:

    CLEAN SUCCESSFUL (total time: 57ms)
    make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
    make[1]: Entering directory '/Users/prwlabmac/MPLABXProjects/SPI_SDTestA.X'
    make -f nbproject/Makefile-default.mk dist/default/production/SPI_SDTestA.X.production.hex
    make[2]: Entering directory '/Users/prwlabmac/MPLABXProjects/SPI_SDTestA.X'
    "/Applications/microchip/xc8/v2.05/bin/xc8-cc" -mcpu=18F45K42 -c -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/mcc_generated_files/device_config.p1 mcc_generated_files/device_config.c
    "/Applications/microchip/xc8/v2.05/bin/xc8-cc" -mcpu=18F45K42 -c -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/main.p1 main.c
    "/Applications/microchip/xc8/v2.05/bin/xc8-cc" -mcpu=18F45K42 -c -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/diskio.p1 diskio.c
    "/Applications/microchip/xc8/v2.05/bin/xc8-cc" -mcpu=18F45K42 -c -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/ffsystem.p1 ffsystem.c
    "/Applications/microchip/xc8/v2.05/bin/xc8-cc" -mcpu=18F45K42 -c -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/ff.p1 ff.c
    "/Applications/microchip/xc8/v2.05/bin/xc8-cc" -mcpu=18F45K42 -c -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/mcc_generated_files/pin_manager.p1 mcc_generated_files/pin_manager.c
    "/Applications/microchip/xc8/v2.05/bin/xc8-cc" -mcpu=18F45K42 -c -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/mcc_generated_files/spi1.p1 mcc_generated_files/spi1.c
    "/Applications/microchip/xc8/v2.05/bin/xc8-cc" -mcpu=18F45K42 -c -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/mcc_generated_files/mcc.p1 mcc_generated_files/mcc.c
    diskio.c:32:12: warning: implicit declaration of function 'RAM_disk_status' is invalid in C99 [-Wimplicit-function-declaration]
                    result = RAM_disk_status();
                             ^
    diskio.c:39:12: warning: implicit declaration of function 'MMC_disk_status' is invalid in C99 [-Wimplicit-function-declaration]
                    result = MMC_disk_status();
                             ^
    diskio.c:46:12: warning: implicit declaration of function 'USB_disk_status' is invalid in C99 [-Wimplicit-function-declaration]
                    result = USB_disk_status();
                             ^
    diskio.c:70:12: warning: implicit declaration of function 'RAM_disk_initialize' is invalid in C99 [-Wimplicit-function-declaration]
                    result = RAM_disk_initialize();
                             ^
    diskio.c:77:12: warning: implicit declaration of function 'MMC_disk_initialize' is invalid in C99 [-Wimplicit-function-declaration]
                    result = MMC_disk_initialize();
                             ^
    diskio.c:84:12: warning: implicit declaration of function 'USB_disk_initialize' is invalid in C99 [-Wimplicit-function-declaration]
                    result = USB_disk_initialize();
                             ^
    diskio.c:113:12: warning: implicit declaration of function 'RAM_disk_read' is invalid in C99 [-Wimplicit-function-declaration]
                    result = RAM_disk_read(buff, sector, count);
                             ^
    diskio.c:122:12: warning: implicit declaration of function 'MMC_disk_read' is invalid in C99 [-Wimplicit-function-declaration]
                    result = MMC_disk_read(buff, sector, count);
                             ^
    diskio.c:131:12: warning: implicit declaration of function 'USB_disk_read' is invalid in C99 [-Wimplicit-function-declaration]
                    result = USB_disk_read(buff, sector, count);
                             ^
    diskio.c:163:12: warning: implicit declaration of function 'RAM_disk_write' is invalid in C99 [-Wimplicit-function-declaration]
                    result = RAM_disk_write(buff, sector, count);
                             ^
    diskio.c:172:12: warning: implicit declaration of function 'MMC_disk_write' is invalid in C99 [-Wimplicit-function-declaration]
                    result = MMC_disk_write(buff, sector, count);
                             ^
    diskio.c:181:12: warning: implicit declaration of function 'USB_disk_write' is invalid in C99 [-Wimplicit-function-declaration]
                    result = USB_disk_write(buff, sector, count);
                             ^
    12 warnings generated.
    "/Applications/microchip/xc8/v2.05/bin/xc8-cc" -mcpu=18F45K42 -c -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -DXPRJ_default=default -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -o build/default/production/ffunicode.p1 ffunicode.c
    "/Applications/microchip/xc8/v2.05/bin/xc8-cc" -mcpu=18F45K42 -Wl,-Map=dist/default/production/SPI_SDTestA.X.production.map -DXPRJ_default=default -Wl,--defsym=__MPLAB_BUILD=1 -fno-short-double -fno-short-float -memi=wordwrite -O0 -fasmfile -maddrqual=ignore -xassembler-with-cpp -mwarn=-3 -Wa,-a -msummary=-psect,-class,+mem,-hex,-file -ginhx032 -Wl,--data-init -mno-keep-startup -mno-download -mdefault-config-bits -std=c99 -gdwarf-3 -mstack=compiled:auto:auto:auto -Wl,--memorysummary,dist/default/production/memoryfile.xml -o dist/default/production/SPI_SDTestA.X.production.elf build/default/production/mcc_generated_files/spi1.p1 build/default/production/main.p1 build/default/production/mcc_generated_files/device_config.p1 build/default/production/mcc_generated_files/mcc.p1 build/default/production/mcc_generated_files/pin_manager.p1 build/default/production/diskio.p1 build/default/production/ff.p1 build/default/production/ffsystem.p1 build/default/production/ffunicode.p1
    mcc_generated_files/spi1.c:79:: warning: (520) function "_SPI1_Exchange8bit" is never called
    mcc_generated_files/spi1.c:92:: warning: (520) function "_SPI1_Exchange8bitBuffer" is never called
    main.c:85:: warning: (520) function "_putch" is never called
    mcc_generated_files/pin_manager.c:143:: warning: (520) function "_PIN_MANAGER_IOC" is never called
    ff.c:2334:: warning: (520) function "_dir_read" is never called
    ff.c:2599:: warning: (520) function "_dir_remove" is never called
    ff.c:2645:: warning: (520) function "_get_fileinfo" is never called
    ff.c:3735:: warning: (520) function "_f_read" is never called
    ff.c:4252:: warning: (520) function "_f_lseek" is never called
    ff.c:4413:: warning: (520) function "_f_opendir" is never called
    ff.c:4479:: warning: (520) function "_f_closedir" is never called
    ff.c:4509:: warning: (520) function "_f_readdir" is never called
    ff.c:4597:: warning: (520) function "_f_stat" is never called
    ff.c:4632:: warning: (520) function "_f_getfree" is never called
    ff.c:4721:: warning: (520) function "_f_truncate" is never called
    ff.c:4771:: warning: (520) function "_f_unlink" is never called
    ff.c:4865:: warning: (520) function "_f_mkdir" is never called
    ff.c:4949:: warning: (520) function "_f_rename" is never called
    mcc_generated_files/spi1.c:108:: warning: (1498) pointer (SPI1_Exchange8bitBuffer@dataOut) in expression may have no targets
    mcc_generated_files/spi1.c:120:: warning: (1498) pointer (SPI1_Exchange8bitBuffer@dataOut) in expression may have no targets
    diskio.c:32:: warning: (1518) direct function call made with an incomplete prototype (RAM_disk_status)
    diskio.c:36:: warning: (1257) local variable "_stat" is used but never given a value
    diskio.c:39:: warning: (1518) direct function call made with an incomplete prototype (MMC_disk_status)
    diskio.c:46:: warning: (1518) direct function call made with an incomplete prototype (USB_disk_status)
    diskio.c:70:: warning: (1518) direct function call made with an incomplete prototype (RAM_disk_initialize)
    diskio.c:74:: warning: (1257) local variable "_stat" is used but never given a value
    diskio.c:77:: warning: (1518) direct function call made with an incomplete prototype (MMC_disk_initialize)
    diskio.c:84:: warning: (1518) direct function call made with an incomplete prototype (USB_disk_initialize)
    diskio.c:113:: warning: (1518) direct function call made with an incomplete prototype (RAM_disk_read)
    diskio.c:113:: warning: (1464) number of arguments passed to function "_RAM_disk_read" does not match function's prototype
    diskio.c:117:: warning: (1257) local variable "_res" is used but never given a value
    diskio.c:122:: warning: (1518) direct function call made with an incomplete prototype (MMC_disk_read)
    diskio.c:122:: warning: (1464) number of arguments passed to function "_MMC_disk_read" does not match function's prototype
    diskio.c:131:: warning: (1518) direct function call made with an incomplete prototype (USB_disk_read)
    diskio.c:131:: warning: (1464) number of arguments passed to function "_USB_disk_read" does not match function's prototype
    diskio.c:163:: warning: (1518) direct function call made with an incomplete prototype (RAM_disk_write)
    diskio.c:163:: warning: (1464) number of arguments passed to function "_RAM_disk_write" does not match function's prototype
    diskio.c:167:: warning: (1257) local variable "_res" is used but never given a value
    diskio.c:172:: warning: (1518) direct function call made with an incomplete prototype (MMC_disk_write)
    diskio.c:172:: warning: (1464) number of arguments passed to function "_MMC_disk_write" does not match function's prototype
    diskio.c:181:: warning: (1518) direct function call made with an incomplete prototype (USB_disk_write)
    diskio.c:181:: warning: (1464) number of arguments passed to function "_USB_disk_write" does not match function's prototype
    diskio.c:212:: warning: (1257) local variable "_res" is used but never given a value
    ff.c:2659:: warning: (1498) pointer (get_fileinfo@fno) in expression may have no targets
    ff.c:2659:: warning: (759) expression generates no code
    ff.c:2728:: warning: (1498) pointer (get_fileinfo@fno) in expression may have no targets
    ff.c:2729:: warning: (1498) pointer (get_fileinfo@fno) in expression may have no targets
    ff.c:2731:: warning: (1498) pointer (get_fileinfo@fno) in expression may have no targets
    ff.c:2734:: warning: (1498) pointer (get_fileinfo@fno) in expression may have no targets
    ff.c:2735:: warning: (1498) pointer (get_fileinfo@fno) in expression may have no targets
    ff.c:2736:: warning: (1498) pointer (get_fileinfo@fno) in expression may have no targets
    ff.c:2737:: warning: (1498) pointer (get_fileinfo@fno) in expression may have no targets
    ff.c:3125:: warning: (759) expression generates no code
    ff.c:3244:: warning: (759) expression generates no code
    ff.c:3260:: warning: (759) expression generates no code
    ff.c:3281:: warning: (759) expression generates no code
    ff.c:3564:: warning: (759) expression generates no code
    ff.c:3750:: warning: (1498) pointer (f_read@br) in expression may have no targets
    ff.c:3774:: warning: (1498) pointer (f_read@fp) in expression may have no targets
    ff.c:3775:: warning: (1498) pointer (f_read@fp) in expression may have no targets
    ff.c:3776:: warning: (1498) pointer (f_read@fp) in expression may have no targets
    ff.c:3779:: warning: (1498) pointer (f_read@fp) in expression may have no targets
    ff.c:3786:: warning: (1498) pointer (f_read@fp) in expression may have no targets
    ff.c:3805:: warning: (1498) pointer (f_read@fp) in expression may have no targets
    ff.c:3806:: warning: (1498) pointer (f_read@fp) in expression may have no targets
    ff.c:3809:: warning: (1498) pointer (f_read@fp) in expression may have no targets
    ff.c:3812:: warning: (1498) pointer (f_read@fp) in expression may have no targets
    ff.c:3822:: warning: (1498) pointer (f_read@br) in expression may have no targets
    ff.c:4331:: warning: (759) expression generates no code
    ff.c:4335:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4340:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4348:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4349:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4350:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4353:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4357:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4361:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4362:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4373:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4374:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4375:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4377:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4380:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4385:: warning: (759) expression generates no code
    ff.c:4386:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4387:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4393:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4394:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4397:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4399:: warning: (1498) pointer (f_lseek@fp) in expression may have no targets
    ff.c:4428:: warning: (1498) pointer (f_opendir@dp) in expression may have no targets
    ff.c:4443:: warning: (1498) pointer (f_opendir@dp) in expression may have no targets
    ff.c:4450:: warning: (1498) pointer (f_opendir@dp) in expression may have no targets
    ff.c:4467:: warning: (1498) pointer (f_opendir@dp) in expression may have no targets
    ff.c:4493:: warning: (1498) pointer (f_closedir@dp) in expression may have no targets
    ff.c:4648:: warning: (1498) pointer (f_getfree@fatfs) in expression may have no targets
    ff.c:4651:: warning: (1498) pointer (f_getfree@nclst) in expression may have no targets
    ff.c:4705:: warning: (1498) pointer (f_getfree@nclst) in expression may have no targets
    ff.c:4737:: warning: (1498) pointer (f_truncate@fp) in expression may have no targets
    ff.c:4747:: warning: (1498) pointer (f_truncate@fp) in expression may have no targets
    ff.c:4748:: warning: (1498) pointer (f_truncate@fp) in expression may have no targets
    ff.c:4754:: warning: (1498) pointer (f_truncate@fp) in expression may have no targets
    ff.c:4758:: warning: (1498) pointer (f_truncate@fp) in expression may have no targets
    :0:: error: (500) undefined symbols:
     _get_fattime(dist/default/production/SPI_SDTestA.X.production.o) _MMC_disk_initialize(dist/default/production/SPI_SDTestA.X.production.o) _USB_disk_initialize(dist/default/production/SPI_SDTestA.X.production.o) _RAM_disk_initialize(dist/default/production/SPI_SDTestA.X.production.o) _MMC_disk_status(dist/default/production/SPI_SDTestA.X.production.o) _USB_disk_status(dist/default/production/SPI_SDTestA.X.production.o) _RAM_disk_status(dist/default/production/SPI_SDTestA.X.production.o) _MMC_disk_write(dist/default/production/SPI_SDTestA.X.production.o) _USB_disk_write(dist/default/production/SPI_SDTestA.X.production.o) _RAM_disk_write(dist/default/production/SPI_SDTestA.X.production.o) _MMC_disk_read(dist/default/production/SPI_SDTestA.X.production.o) _USB_disk_read(dist/default/production/SPI_SDTestA.X.production.o) _RAM_disk_read(dist/default/production/SPI_SDTestA.X.production.o)
    (908) exit status = 1
    nbproject/Makefile-default.mk:265: recipe for target 'dist/default/production/SPI_SDTestA.X.production.hex' failed
    make[2]: Leaving directory '/Users/prwlabmac/MPLABXProjects/SPI_SDTestA.X'
    nbproject/Makefile-default.mk:90: recipe for target '.build-conf' failed
    make[1]: Leaving directory '/Users/prwlabmac/MPLABXProjects/SPI_SDTestA.X'
    nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
    make[2]: *** [dist/default/production/SPI_SDTestA.X.production.hex] Error 1
    make[1]: *** [.build-conf] Error 2
    make: *** [.build-impl] Error 2

    BUILD FAILED (exit value 2, total time: 7s)

     
    I assume there's some relationship between the warnings and the error, but it's beyond my current understanding.
     
    Any suggestions about how to troubleshoot?

    Peter R. Wiley
    I feel a lot more like I do now than I did when I came in.
    #5
    1and0
    Access is Denied
    • Total Posts : 9607
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: FatFs FIL object not being created? Problem with reference to .h files? 2019/08/20 08:28:46 (permalink)
    0
    Switch to C90 mode.
    #6
    mbrowning
    Just a Member
    • Total Posts : 1504
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: online
    Re: FatFs FIL object not being created? Problem with reference to .h files? 2019/08/20 09:20:00 (permalink)
    +1 (1)
    It appears you are using the diskio.c provided in the FatFS 0.13c distribution. Right at the top it says
    /* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2016        */
    /*-----------------------------------------------------------------------*/
    /* If a working storage control module is available, it should be        */
    /* attached to the FatFs via a glue function rather than modifying it.   */
    /* This is an example of glue functions to attach various exsisting      */
    /* storage control modules to the FatFs module with a defined API.       */

    Clearly a file that needs massive massaging on a implementation specific basis.
    The tutorial you referenced in post #3 has a fully realized implementation using MCC and XC8, and has a heavily modified version of diskio.c based on the MCC output - why aren't you basing your code on that?

    Oh well - there's always next year
    #7
    PRWiley
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2019/07/04 06:16:51
    • Location: Lewisburg PA USA
    • Status: offline
    Re: FatFs FIL object not being created? Problem with reference to .h files? 2019/08/20 12:19:28 (permalink)
    0
    After doing a bit more research and poking around, I discovered that since March of 2019, FatFs has been available in the IDE as a software library and the MCC will generate the needed code including disco.c and demo code. See http://ww1.microchip.com/...ystemLibrary_v1_00.pdf
     
    Alas, now that I have a demo project together the complier is failing with:
    mcc_generated_files/fatfs/fatfs_demo.c:29:: error: (1250) could not find space (563 bytes) for variable _drive
    mcc_generated_files/fatfs/fatfs_demo.c:30:: error: (1250) could not find space (548 bytes) for variable _file
    (908) exit status = 1

     
    The problem seems to be with the size of the drive and file objects required.
     
    Same result with the PIC18F45K42 and PIC18F46K42. The latter I thought would have had enough resources to work. Ho hum.
     

    Peter R. Wiley
    I feel a lot more like I do now than I did when I came in.
    #8
    katela
    Super Member
    • Total Posts : 1378
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: online
    Re: FatFs FIL object not being created? Problem with reference to .h files? 2019/08/20 16:07:09 (permalink)
    0
    My sample project using MCC Library compiles after disabling the generate example/demo file.
    I manually added the demo code in the main function and it compiles.
    PIC: PIC18F45K42
    XC8: v2.05 in C99 mode or C90 mode
    MPLAB: v5.25
    MCC: v3.85.1
    FatFs Library: v1.00
    post edited by katela - 2019/08/20 16:23:26

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #9
    PRWiley
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2019/07/04 06:16:51
    • Location: Lewisburg PA USA
    • Status: offline
    Re: FatFs FIL object not being created? Problem with reference to .h files? 2019/08/21 13:21:05 (permalink)
    0
    @katela Many thanks for posting your code. It helped me find a dumb mistake in mine that was preventing it from compiling.  I was able to use the demo code to open and write to the HELLO.TXT file on the SD card.
     
    However, in attempting to extend the example to read the contents of the file back I am getting odd results.  f_open on the file returns "FAT32" (expecting "FR_OK") and that response does not seem to be documented at http://elm-chan.org/fsw/ff/00index_e.html . I wonder if it could be a feature of the Microchip version of the library?

    Peter R. Wiley
    I feel a lot more like I do now than I did when I came in.
    #10
    katela
    Super Member
    • Total Posts : 1378
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: online
    Re: FatFs FIL object not being created? Problem with reference to .h files? 2019/08/21 13:31:27 (permalink)
    0
    Can you post your code how you are reading?

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #11
    PRWiley
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2019/07/04 06:16:51
    • Location: Lewisburg PA USA
    • Status: offline
    Re: FatFs FIL object not being created? Problem with reference to .h files? 2019/08/26 04:52:55 (permalink)
    0
    Coming back to this after a break. Thanks for all responses
     
    It code works the way it should now that I understand the code I was using was unmounting the card. Fixed that and the read works as it should. I'm still confused by some other issues, but those are for another post.

    Peter R. Wiley
    I feel a lot more like I do now than I did when I came in.
    #12
    katela
    Super Member
    • Total Posts : 1378
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: online
    Re: FatFs FIL object not being created? Problem with reference to .h files? 2019/08/26 05:16:41 (permalink)
    +1 (1)
    It always good to share your experience, like posting your working code for others in the future who might face the same problems as you. 

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #13
    PRWiley
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2019/07/04 06:16:51
    • Location: Lewisburg PA USA
    • Status: offline
    Re: FatFs FIL object not being created? Problem with reference to .h files? 2019/08/28 06:51:30 (permalink)
    +2 (2)
    Sure.
     
    Here's the code that's working for me know, although the audio is being played back far too slowly. I think it's an issue with the speed of the SD Card read. About to post a question about that issue since it's now off topic for this thread.
     
    /**
      Generated Main Source File

      Company:
        Microchip Technology Inc.

      File Name:
        main.c

      Summary:
        This is the main file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs

      Description:
        This header file provides implementations for driver APIs for all modules selected in the GUI.
        Generation Information :
            Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.77
            Device : PIC18F46K42
            Driver Version : 2.00
    */

    /*
        (c) 2018 Microchip Technology Inc. and its subsidiaries.
        
        Subject to your compliance with these terms, you may use Microchip software and any
        derivatives exclusively with Microchip products. It is your responsibility to comply with third party
        license terms applicable to your use of third party software (including open source software) that
        may accompany Microchip software.
        
        THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
        EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY
        IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS
        FOR A PARTICULAR PURPOSE.
        
        IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
        INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
        WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP
        HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO
        THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
        CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT
        OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS
        SOFTWARE.
    */

    #include "mcc_generated_files/mcc.h"
    #include <xc.h>
    #include <stdio.h>
    #include <stdint.h>
    #include "mcc_generated_files/drivers/spi_master.h"

    /*
                             Main application
     */

    FATFS drive;
    FIL file;
    UINT br;
    uint8_t contents[44]; // buffer for header information
    uint8_t data_read[512]; // buffer for 8 bit WAV data from SD Card
    long sample_rate; // file sample rate
    long int data_size; // the data size
    long int indexed_fs;
    uint16_t byte_index; // index of WAV data buffer
    long int byte_count;
    char result;

    void startPlayback(void);
    void fetchWAVData(void);


    void main(void)
    {
        // Initialize the device
        SYSTEM_Initialize();
        TMR1_StopTimer();

        // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
        // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global Interrupts
        // Use the following macros to:

        // Enable the Global Interrupts
        INTERRUPT_GlobalInterruptEnable();

        // Disable the Global Interrupts
        //INTERRUPT_GlobalInterruptDisable();
        __delay_ms(1000);
        printf("Starting.");
        printf("\n\r");
        __delay_ms(1000);
        if (f_mount(&drive,"0:",1) == FR_OK)
            {
            if (f_open(&file, "PRW8.WAV", FA_READ) == FR_OK){
                
                result = f_read(&file, contents, 44, &br);
                    if (result == FR_OK){
                        data_size = ((uint32_t)contents[43] << 24) |
                                    ((uint32_t)contents[42] << 16) |
                                    ((uint32_t)contents[41] << 8) |
                                    ((uint32_t)contents[40]);
                        int kb = data_size/1024;
                        sample_rate = ((uint32_t)contents[27] << 24) |
                                      ((uint32_t)contents[26] << 16) |
                                      ((uint32_t)contents[25] << 8) |
                                      ((uint32_t)contents[24]);
                        printf("Size: %lu kB: %u", data_size, kb);
                        printf("\n\r");
                        printf("Sample rate: %lu ", sample_rate);
                        printf("\n\r");
                        __delay_ms(2000);
                      
                        
                        printf("\n\r");
                        startPlayback();
                    }
                
            } else {
            
                printf("File not opened.");
                result = f_open(&file, "PRW8.WAV", FA_READ);
                printf("\n\r");
                printf("%s ", result);
                
            }
            } else {
                
                printf("File not mounted.");
                printf("\n\r");
                
            }

        while (1)
        {
            // Add your application code
        }
    }

    // To start playback we get the first chunk of data past the header
    void startPlayback(void)
    {
        printf("Starting playback.");
        printf("\n\r)");
        byte_index = 0;
        f_lseek(&file, 45); // start at the 45th byte
        f_read(&file, data_read, sizeof data_read, &br);
        byte_count = 557; // set count for the second read
        TMR1_StartTimer();
        TMR2_StartTimer();
    }

    // called on TMR1 interrupt to load byte, every 43us
    void loadDuty(void)
    {
        PMW5_LoadEightBitDutyValue(data_read[byte_index]);
        //printf("%02x \n\r", data_read[byte_index]);
        byte_index++;
        if (byte_index == 512) // if all of the data_read was sent, get more data
        {
            byte_index = 0;
            fetchWAVData();
        }
    }

    // get WAV data from SD card, get the next 512 bytes
    // when byte_count > data_size we are done.
    void fetchWAVData(void)
    {
        f_lseek(&file, byte_count);
        f_read(&file, data_read, sizeof data_read, &br);
        printf("Data fetched at %li fs %lu", byte_count, data_size);
        printf("\n\r");
        byte_count += 512;
        if(byte_count > data_size)
        {
            printf("End of data.");
            TMR1_StopTimer();
            TMR2_StopTimer();
        }
    }
    /**
     End of File
    */

    post edited by PRWiley - 2019/08/28 07:01:52

    Peter R. Wiley
    I feel a lot more like I do now than I did when I came in.
    #14
    Jump to:
    © 2019 APG vNext Commercial Version 4.5