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.

LAUNCHXL-CC1310: unable to read from FatFs file

Part Number: LAUNCHXL-CC1310
Other Parts Discussed in Thread: CC1310

Hello,

I am trying to read a file from the SD card on a CC1310 Launchpad. I have an SD card connected to the SPI and using the FatFs library I can open directories, read file info and open files using f_open without issue

However once I actually try to read/write a file, I get a "1", FR_DISK_ERR, and then any interfacing with the SD card stops:

int uartApi_readFile(const char *filename, char *buf, UINT len, UINT offset)
{
    SD_init();
    SDFatFS_Handle sdCardHandle;
    sdCardHandle = SDFatFS_open(Board_SD0, 0);

    FIL file;
//    BYTE readBuffer[UART_TX_SIZE];


    UINT readCount;
    UINT amountToRead = len;
    FRESULT ferr = f_open(&file, filename, FA_READ | FA_OPEN_ALWAYS);
    if (ferr == FR_OK)
    {
        ferr = f_read(&file, buf, amountToRead, &readCount);
        if (ferr != FR_OK)
        {
            snprintf(buf, amountToRead, "Couldn't read file %i - %i\n", ferr, readCount);
        }
    }
    else
    {
        snprintf(buf, amountToRead, "Couldn't open file %i\n", ferr);
    }
    f_close(&file);
//    SDFatFS_close(sdCardHandle);
    return ferr;
}

The SD card is mounted using SD_init() and SdFatFS_open, which should get it mounted as a disk (seeing as I can interface with it using f_open, and f_readdir etc:

For example this function, listing all the existing files to a string DOES work, only when I call the f_read does it break:

char* listSdContents()
{
    DIR dir;        //Directory struct
    FILINFO fno;    //File info struct

    char *FileSystemString = calloc(UART_TX_SIZE, sizeof(char));
//    SD_init();
//    SDFatFS_Handle sdCardHandle;
//    sdCardHandle = SDFatFS_open(Board_SD0, 0);
//    int_fast16_t sdResult = SD_initialize(sdCardHandle);

//    if (sdResult != SD_STATUS_SUCCESS)
//    {
//        char string[48];
//        snprintf(string, 47, "Open SD err: %i\n", sdResult);
//        strcat(FileSystemString, string);
//        return FileSystemString;
//    }

    FRESULT err = f_opendir(&dir, "/");
    if (err != FR_OK)
    {
        char string[48];
        snprintf(string, 47, "Open dir err: %i\n", err);
        strcat(FileSystemString, string);
//        SDFatFS_close(sdCardHandle);
        return FileSystemString;
    }

    do
    {
        f_readdir(&dir, &fno);
        if (fno.fname[0] != 0)
        {
            if ((strlen(FileSystemString) + strlen(fno.fname)) < UART_TX_SIZE)
            {
                strcat(FileSystemString, fno.fname);
                strcat(FileSystemString, "\n");
            }
            else
                strcat(FileSystemString, "full\n");
        }
    }
    while (fno.fname[0] != 0);
    strcat(FileSystemString, "Done\n");

//    SDFatFS_close(sdCardHandle);
    return FileSystemString;
}

Help would be very much appreciated. many thanks

Sjors