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.

Interfacing micro SD card with TMS320F28377d experimenter kit with fatfs library

Other Parts Discussed in Thread: TMS320F28377D, CONTROLSUITE

Hello,

I am trying to interface a micro SD card (8 gb) with a TMS320f28377d experimenter kit. I am trying to use the micro SD slot which is provided in the kit. I am using the fatfs library. I tried to create a file in the SD card but I am not successful in it. Any help would be appreciable.

The following is my main file code

/*
* main.c
* Priti Chakraborty
* date: 8/3/'16
*/


#include "F28x_Project.h"
#include <string.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "third_party/fatfs/src/ff.h"
#include "third_party/fatfs/src/diskio.h"

//*****************************************************************************
// This is the handler for this SysTick interrupt. FatFs requires a
// timer tick every 10 ms for internal timing purposes.
//*****************************************************************************
__interrupt void
SysTickHandler(void)
{
// Call the FatFs tick timer.
disk_timerproc();
PieCtrlRegs.PIEACK.all |= 1;
}

void main(void) {

static FATFS g_sFatFs;
FIL fil;
FRESULT fresult1, fresult2, fresult3;


// INITIALIZING SYSTEM CONTROL
InitSysCtrl();


//DISABLING SYSTEM INTERRUPTS
//DINT;

// Set the clocking to run from the PLL at 50MHz
//
SysCtlClockSet(SYSCTL_OSCSRC_OSC2 | SYSCTL_PLL_ENABLE | SYSCTL_IMULT(10) | SYSCTL_SYSDIV(2));
SysCtlAuxClockSet(SYSCTL_OSCSRC_OSC2 | SYSCTL_PLL_ENABLE | SYSCTL_IMULT(12) | SYSCTL_SYSDIV(2)); //60 MHz

#ifdef _FLASH
// Copy time critical code and Flash setup code to RAM
// This includes the following functions: InitFlash();
// The RamfuncsLoadStart, RamfuncsLoadSize, and RamfuncsRunStart
// symbols are created by the linker. Refer to the device .cmd file.
memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);

// Call Flash Initialization to setup flash waitstates
// This function must reside in RAM
InitFlash();
#endif


//
// Initialize interrupt controller and vector table
//
InitPieCtrl();
InitPieVectTable();

//
// Set the system tick to fire 100 times per second.
//
SysTickInit();
SysTickPeriodSet(SysCtlClockGet(SYSTEM_CLOCK_SPEED) / 100);
SysTickIntRegister(SysTickHandler);
SysTickIntEnable();
SysTickEnable();

// Enable Interrupts
IntMasterEnable();

// Creating a file

// Mount the file system, using logical disk 0.
fresult1 = f_mount(0, &g_sFatFs);

fresult2 = f_open(&fil,"message.txt", FA_CREATE_NEW);

/* Close the file */
fresult3= f_close(&fil);

}

Thanks

  • Hi Priti,

    I'm not exactly sure what the problem might be in your code.

    In case you are not aware, the following example (in controlSUITE) is designed to interface with the microSD slot on the cCARD:
    \controlSUITE\device_support\F2837xD\v180\F2837xD_examples_Cpu1\sd_card\cpu01\


    Thank you,
    Brett

  • Thanks. Suddenly, I am able to read a file from SD card. But that file is not getting written. I am unable to figure out what might be the problem. The file is getting created but even after writing the file, the file remains empty. i am getting FR_OK status in every fatf command written in the  following code.

    /*
    * main.c
    * Priti Chakraborty
    * date: 8/3/'16
    */


    #include "F28x_Project.h"
    #include <string.h>
    #include "inc/hw_ints.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/systick.h"
    #include "third_party/fatfs/src/ff.h"
    #include "third_party/fatfs/src/diskio.h"

    FILINFO *finfo ;
    char linea[16]; /* Line buffer */
    WORD btra = 16;
    WORD bra;

    char linec[16]; /* Line buffer */
    WORD btrc =16;
    WORD brc;


    char lineb[16]="HELLO\0"; /* Line buffer */
    WORD btrb=16 ;
    WORD brb;

    char lined[16]; /* Line buffer */
    WORD btrd = 16;
    WORD brd;

    static FATFS g_sFatFs;
    FIL fil;
    FRESULT fresult1;
    FRESULT fresult10;
    FRESULT fresult11;
    FRESULT fresult12;
    FRESULT fresult13;
    FRESULT fresult14;
    FRESULT fresult15;
    FRESULT fresult16;
    FRESULT fresult17;
    FRESULT fresult24;
    FRESULT fresult71;
    FRESULT fresult72;
    FRESULT fresult81;
    FRESULT fresult91;


    //*****************************************************************************
    // This is the handler for this SysTick interrupt. FatFs requires a
    // timer tick every 10 ms for internal timing purposes.
    //*****************************************************************************
    __interrupt void
    SysTickHandler(void)
    {
    // Call the FatFs tick timer.
    disk_timerproc();
    PieCtrlRegs.PIEACK.all |= 1;
    }

    void main(void) {
    // FIL fil;
    //FRESULT fresult1, fresult2, fresult3;


    // INITIALIZING SYSTEM CONTROL
    InitSysCtrl();


    //DISABLING SYSTEM INTERRUPTS
    //DINT;

    // Set the clocking to run from the PLL at 50MHz
    //
    SysCtlClockSet(SYSCTL_OSCSRC_OSC2 | SYSCTL_PLL_ENABLE | SYSCTL_IMULT(10) | SYSCTL_SYSDIV(2));
    SysCtlAuxClockSet(SYSCTL_OSCSRC_OSC2 | SYSCTL_PLL_ENABLE | SYSCTL_IMULT(12) | SYSCTL_SYSDIV(2)); //60 MHz

    //
    // Initialize interrupt controller and vector table
    //
    InitPieCtrl();
    InitPieVectTable();

    //
    // Set the system tick to fire 100 times per second.
    //
    SysTickInit();
    SysTickPeriodSet(SysCtlClockGet(SYSTEM_CLOCK_SPEED) / 100);
    SysTickIntRegister(SysTickHandler);
    SysTickIntEnable();
    SysTickEnable();

    // Enable Interrupts
    IntMasterEnable();

    // Creating a file

    // Mount the file system, using logical disk 0.
    // fresult0 = f_mount(1, &g_sFatFs);
    fresult1 = f_mount(0, &g_sFatFs);


    fresult10 = f_open(&fil,"p.txt", FA_CREATE_ALWAYS);
    fresult11 = f_close(&fil);

    fresult12 = f_open(&fil,"p.txt", FA_WRITE);
    fresult13=f_write(&fil,&lineb,btrb,&brb);
    fresult14= f_close(&fil);

    fresult15 = f_open(&fil,"p.txt", FA_READ);
    fresult16= f_read(&fil,&lined,btrd,&brd);
    fresult17= f_close(&fil);

    }

  • I forgot to mention that the status of f_write is FR_OK but the error of f_close is FR_RW_ERROR
  • I found out if the file is already written with some data, only then over- writing is possible. I am unable to write in an empty file.
  • Priti,

    Have you been able to resolve this issue?

    -Mark
  • Yes, the issue is solved. i found there was an error in the disk_write function in the mmc file provided with the device support of TMS320f28377d  file.

  • Priti,

    Can you share what the error is in the mmc files? It would be great if you could let us know so that we may fix it in the next release so others do not face this problem.

    Thanks,
    Mark

  • Yes Mark,

    The transmit datablock function in the mmc-F2837x.c  provided with the support files had an error . The loop variable was not incremented in that function. The corrected xmit_datablock function should be like this written below.

    /*-----------------------------------------------------------------------*/
    /* Send a data packet to MMC */
    /*-----------------------------------------------------------------------*/

    #if _READONLY == 0
    static
    BOOL xmit_datablock (
    const BYTE *buff, /* 512 byte data block to be transmitted */
    BYTE token /* Data/Stop token */
    )
    {
    BYTE resp, wc;
    Uint16 j=0;


    if (wait_ready() != 0xFF) return FALSE;

    xmit_spi(token); /* Xmit data token */
    if (token != 0xFD) /* Is data token */
    {

    for(j=0;j<512;j++) /* Xmit the 512 byte data block to MMC */
    {
    xmit_spi(*buff++);

    }

    xmit_spi(0xFF); /* CRC (Dummy) */
    xmit_spi(0xFF);
    resp = rcvr_spi(); /* Reveive data response */
    if ((resp & 0x1F) != 0x05) /* If not accepted, return with error */
    return FALSE;
    }

    return TRUE;
    }
    #endif /* _READONLY */

  • Priti,

    Thank you for for reporting this. It looks like there is already a bug filed against this exact issue. It should be resolved in the near future.

    -Mark