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.

TMS320F28379D: How to read data from a SD card

Part Number: TMS320F28379D
Other Parts Discussed in Thread: LAUNCHXL-F28379D, C2000WARE

Hello, I'm working on a LAUNCHXL-F28379D and specifically i would like to read data on a text file in a micro SD card using SPI. 

I read that there is an example about it in the previous version of C2000Ware, that is absent in my version (C2000Ware 5_01_00_00). I try to create a similar project by my own but I encounter the following problems:

1. Looking at the example of the previous version, I see that the library with the function to operate on a text file are in the "fatfs" folder, inside the "deprecated" folder, that it's absent in my version; 

2. I try to include the path of the "fatfs" folder for the version 5_01_00_00 (...\C2000_5\C2000Ware_5_01_00_00\utilities\third_party\f2837xd\fatfs) in Properties--> C2000 Compiler--> Include Options and on the sime time to add a folder "fatfs" in my project where I copy the files inside ...\C2000_5\C2000Ware_5_01_00_00\utilities\third_party\f2837xd\fatfs. In this way, some error appear when I try to built the project;

3. I try also to import the folder "deprecated" from the version 4_02_00_00 of C2000Ware and include it in the compiler path, but after the built operation there are several errors. 

Please provide guidance to resolve the issue. 

Thank you in advance. 

  • Hi, 

    The examples are available for all newer devices at the following path:

    C2000Ware_5_01_00_00\driverlib\f2838x\examples\c28x\sdspi

    These examples are not available for F28379D yet, but I do the porting and share the examples by Friday, May 6th. 

    In the mean time, you can take a look at the available examples in C2000ware (as mentioned above) and get started on the development of the application. 

    Thanks. 

  • Thank you for the suggestion. 

    Following the example in the path you indicated, I have successfully implement the communication between the board and the sd card reader, by appropriately modifying the example code for f2838x with the libraries included and related with my board (F28379D). 

    However, as I progress with the project, other issues have arisen: 

    1. I need to read a certain number of values from a text file on the SD card. Using the f_read function, all the contents of the file are placed into a single array, occupying a large amount of memory and resulting in the following warning: "#10210-D creating ".sysmem" section with default size of 0x400; use the -heap option to change the default size". In this case, in the main function, I call a function defined in another .c file where the reading of the text file takes place, but the array where the text is saved isn't preserve at the end of the function call. 



    2. To conserve memory, I attempted to use the f_gets function to process one line of text at a time, analyze it, and then overwrite the array with the text in the next line. However, in this case, when compiling, the following error occurs: "#10234-D</a> unresolved symbols remain". It's indicated that the f_gets symbol is undefined, despite it is present in the same library as other functions which are employed oreviously in the same code and they do not produce the same error (such as f_open). Below I report the code used for this last issue. In this case, I read the text file and analyze it in the same .c file, but also for this the objective is to analyze the text file in a function called in the main file. 

    // Included Files
    //
    #include "driverlib.h"
    #include "device.h"
    #include "board.h"
    #include <string.h>
    #include <stdlib.h>

    #include <sdspi/sdspi.h>
    #include <sdspi/SDFatFS.h>


    uint16_t SDFatFS_config_count = 1;
    SDFatFS_Object sdfatfsObject;

    SDSPI_Object sdspiObject = {
    .spiHandle = mySDCardSPI_BASE,
    .spiCsGpioIndex = mySDCardCS
    };

    SDFatFS_Object* SDFatFS_config [] = {&sdfatfsObject};

    SDSPI_Handle sdspiHandle = &sdspiObject;

    /* String conversion macro */
    #define STR_(n) #n
    #define STR(n) STR_(n)

    /* Drive number used for FatFs */
    #define DRIVE_NUM 0

    const char inputfile[] = STR(DRIVE_NUM)":input.txt";
    const char outputfile[] = STR(DRIVE_NUM)":output.txt";

    FIL src;
    FIL dst;

    unsigned int filesize;
    FRESULT fresult;
    //
    // Main
    //
    void main(void)
    {
    //
    // Initialize device clock and peripherals
    //
    Device_init();

    //
    // Disable pin locks and enable internal pullups.
    //
    Device_initGPIO();

    //
    // Initialize PIE and clear PIE registers. Disables CPU interrupts.
    //
    Interrupt_initModule();

    //
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    //
    Interrupt_initVectorTable();

    //
    // Board initialization
    //
    Board_init();

    SDFatFS_init();
    SDFatFS_Handle sdFatFs_handle = SDFatFS_open(sdspiHandle, DRIVE_NUM);
    if (sdFatFs_handle == NULL)
    {
    while(1);
    }


    /* Create a new file object for the file copy */
    fresult = f_open(&src, inputfile, FA_READ);

    if (fresult != FR_OK) {
    while(1);
    }

    char buf[20];
    f_gets(buf, 20, &src);

    /* Close outputfile[] */
    fresult = f_close(&src);
    if (fresult != FR_OK) {
    while(1);
    }

    EINT;
    ERTM;

    SDFatFS_close(sdFatFs_handle);

    while(1)
    {
    }

    }


    int32_t fatfs_getFatTime(void)
    {
    return 0;
    }

    //
    // End File
    //



    Thank you once again in advance for the assistance provided. 

  • Hi, 

    In order to use the f_gets function, a specific macro needs to be set. The procedure to do that is as follows:

    1. Import the following project into CCS -> c2000_fatfs_f2837xd from this path: C2000Ware_5_02_00_00\libraries\fatfs\ccs

    2. Go to ffconf.h and make the following change on line 28

    #define FF_USE_STRFUNC	1

    3. Build the project and make sure to link the generated fatfs.lib into the project that you are currently using. 

    Thanks.