0

I had a tm4c129xnczad microcontroller with SDcard connected to it via SPI3

and the SDcard with 1 Gb size had 2 volumes with about 500 Mb each

I want to write data to files to each volume I can access the first one but the second volume is not accessible through the code I had so the steps I did was

  1. first I started Mounting the 2 volumes such that
EIO_vmturnSDCardPowerON();
    UTIL_vNonOSDelayMiliSeconds(200);/* this delay is guarantee the proper rest for the SD card */
    /* Mount and register the FSHELL Card */
    SDSPI_Params_init(&objstrsdspiParameters);
    objsdspiHandle = SDSPI_open(Board_SDSPI0, DRIVE_NUM, &objstrsdspiParameters);
    if(objsdspiHandle == STD_NULL)
    {
        FSHELL_vmLogError0(&objstrFSHELLModuleInfoType, "Can't mount SD card");
    }
    else
    {
        FSHELL_vmLogActivity1(&objstrFSHELLModuleInfoType, "SD card is mounted Drive:%u", DRIVE_NUM);
        bSdMountState = STD_TRUE;
    }
    objsdspiHandle = SDSPI_open(1, 1, &objstrsdspiParameters);
    if(objsdspiHandle == STD_NULL)
    {
        FSHELL_vmLogError0(&objstrFSHELLModuleInfoType, "Can't mount SD card");
    }
    else
    {
        FSHELL_vmLogActivity1(&objstrFSHELLModuleInfoType, "SD card is mounted Drive:%u", 1);
        bSdMountState = STD_TRUE;
    }
  1. then I used the standard file APIs from the studio.h (fopen, fclose, fwrite ) functions such that
#include <stdio.h>

function (){
...
INT8S *ps8ProgFilePath = "fat:0:/ProgBlocks/Blocks.txt";
INT8S *ps8ProgFilePath_1 = "fat:1:/ProgBlocks/Blocks.txt";
FRESULT objFRESULT = FR_DISK_ERR;
FILE *pSourceFile;
...

objFRESULT = f_mkdir("/ProgBlocks");
if((objFRESULT == FR_OK)||(objFRESULT == FR_EXIST)) /* if folder is created or alredy existed */
{
pSourceFile = fopen((const INT8S*)ps8ProgFilePath, "a");
if(pSourceFile == STD_NULL)
{
SCFGM_vmLogError1(&objstrSCFGMModuleInfoType, "\"%s\" could not be created", (INT32U)ps8ProgFilePath);
}
else
{
u32NumBytesWritten = fwrite((INT8S*)ps8Data,1,(MAX_BLOCK_ID_STRING+(u32BlockLen*3)),pSourceFile);
if (u32NumBytesWritten != (MAX_BLOCK_ID_STRING+(u32BlockLen*3)))
{
SCFGM_vmLogError1(&objstrSCFGMModuleInfoType, "\"%s\"Err wrt Blk", (INT32U)ps8ProgFilePath);
}
}
if(fclose(pSourceFile) != 0)
{
SCFGM_vmLogError1(&objstrSCFGMModuleInfoType, "\"%s\" could not be Close", (INT32U)ps8ProgFilePath);
}
}
....
}

so I can access the first volume "fat:0:" but can't write or even access the second volume "fat:1:" in the same way

so the question is can I even access 2 volumes within the same SD card and how?

  • 1
    Can you access both volumes if you use FatFS API instead of stdio.h API? – user694733 May 23 '23 at 08:43
  • actually, the stdio version that I had come from TI along with their development environment, and it is been ported with FatFs API (chan with revision No. R0.15) but the issue with accessing the 2 volumes approach was the 2 devices need to be created properly with TI-RTOS APIs and liked and mounted correctly with FatFs then we can use whatever we want Chan(FatFs Api) or studio they both are using FatFS chan APIs – Hazem Khaled May 31 '23 at 13:00

1 Answers1

0

I wanted to access two volumes on my SD card because I thought it would solve a problem with the small MCU unit on the SD card that is responsible for reading and writing to the memory segments. Sometimes, this unit fails while reading from the card and becomes accessible after a very short amount of time. I didn't investigate this issue too much because it would involve a lot of debugging inside the FatFS chan version, which has a lot of small details that I'm not interested in. The issue occurs with CMD7 at the read function, and the response is not as expected, so the read function fails for a certain amount of time, usually 7-9 ms for me and 3 or 5 trial attempts. I changed my code to open the file repeatedly until it becomes accessible and then continue reading the data. However, this was not sufficient for my case because I was playing a message on a VLSI chip that requires runtime data to play. With this approach, the 9 ms delay was not noticeable while playing the message

here is the code snippet for the Trials approach

INT64U  start,end;
start = UTI_u64GetMilliSeconds();
do {
    objstrAllDeviceInfo[objenumVLSIChipIDType].pAudioFile = \
                               fopen((constINT8S*)ps8FileName, "rb");
    if(objstrAllDeviceInfo[objenumVLSIChipIDType].pAudioFile != STD_NULL)
    {
        break;
    }
    else
    {
        u32OpenTrials++;
    }
}while(u32OpenTrials < 15);
end = UTI_u64GetMilliSeconds();
VLSI_vmLogTA2(&objstrVLSIModuleInfoType, "opened file in %d ms with %d trials", (end - start), u32OpenTrials);