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.

DK-TM4C123G SD-card code on a TM4C123G

Other Parts Discussed in Thread: TM4C123GH6PM, CC2650

Hi guys,

I'm trying to port the code from TivaWare_C_Series-2.0.1.11577/examples/boards/dk-tm4c123g/sd-card/sd_card.c to work on my TM4C123G Launchpad. I'm using functions from /port/mmc-dk-tm4c123g.c (MMC/SDC control module).

I'm using this breakout board https://www.sparkfun.com/products/11403 with the following connections;

D3 (chip select) - PA3 (SSI0Fss)
CMD (MOSI) - PA6 (SSIOTx)
DO (SOMI) - PA4 (SSIORx)
CLK - PA2 (SSI0Clk)

Currently I'm getting an error in the disk_initialize function and as a result I get FR_NOT_READY when I try to create a file on the SD-card. As I'm also using SSI0 on my Tiva I'm not sure what I need to change in the initialization to get this code to work. As far as I can see all the port configurations are the same across both boards? My main function is below,

int
main(void)
{
    int nStatus;
    FRESULT iFResult;
    //
    // Enable lazy stacking for interrupt handlers.     This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPULazyStackingEnable();

    //
    // Set the system clock to run at 50MHz from the PLL.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Configure SysTick for a 100Hz interrupt.  The FatFs driver wants a 10 ms
    // tick.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Enable Interrupts
    //
    ROM_IntMasterEnable();

    //
    // Initialize the UART as a console for text I/O.
    //
    ConfigureUART();


    UARTprintf("\n\nSD Card Example Program\n");
    UARTprintf("Type \'help\' for help.\n");

    //
    // Mount the file system, using logical disk 0.
    //
    iFResult = f_mount(0, &g_sFatFs);
    if(iFResult != FR_OK)
    {
        UARTprintf("f_mount error: %s\n", StringFromFResult(iFResult));
        return(1);
    }

    power_on();
    BOOL a = wait_ready();
    DSTATUS errd;
    if(a) {
        send_initial_clock_train();
        errd = disk_initialize(0);
        UARTprintf("\nInitialising disk 0. Status = %i\n", errd);
    }

    FIL fil;
    uint32_t count = 8*512;
    iFResult = f_open(&fil, "testfile.txt", FA_CREATE_NEW|FA_WRITE);
    SysCtlDelay(SysCtlClockGet()/3);
    if(iFResult != FR_OK) {UARTprintf("fresult: %s\n", StringFromFResult(iFResult)); }
    else{UARTprintf("\n Opened SD card\n");}

    iFResult = f_write(&fil, "Hello world", 11, &count);
    if(iFResult != FR_OK) {UARTprintf("Error writing to file: %s\n", StringFromFResult(iFResult));}
    iFResult = f_close(&fil);
    f_mount(0, NULL);
}

Any help appreciated.