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.

CSL ATA Filesystem consecutive file writes fail

Hi,

 

I'm using the CSL example csl_mmcsd_atafs_example.c (for CCS V4.X) in order to write a file to an SD/MMC.

Adding another consecutive  ATA_write() call after the existing one corrupts the file system and doesn't allow access to this file from an external card reader.

It created a bigger file, but it is unreadable. Extra write call - where it says "My addition":

 

/* Find the first file available */
    ata_error =  ATA_fileInit(gpstrAtaDrive, pAtaFile);
    if(ata_error) {
        //printf("ATA_fileInit error (0x%x)\n", ata_error);
        return(ata_error);
    }

    /* Set the temp write buffer */
    pAtaFile->pDrive->_AtaWriteBuffer = AtaWrBuf;

    /* Set the file name */
    ATA_setFileName(pAtaFile, fileName, "txt");

    ata_error = ATA_create(pAtaFile);
    if(ata_error != ATA_ERROR_NONE)
    {
        printf("ATA_create Failed\n");
        return(ata_error);
    }
    else
    {
        printf("\nFile Creation on SD card is Successful\n");
    }

        /* Write data to the file */
        ata_error = ATA_write(pAtaFile, gMmcWriteBuf, CSL_MMCSD_ATA_BUF_SIZE);

      /**** My addition ****/    

       ata_error = ATA_write(pAtaFile, gMmcWriteBuf, CSL_MMCSD_ATA_BUF_SIZE);

    if(ata_error != ATA_ERROR_NONE)
    {
        printf("ATA_write Failed\n");
        return(ata_error);
    }
    else
    {
        printf("\nWriting Data to the file on SD card successful\n");
    }

    /* Reset the file pointer to the beginning */
    ATA_seek (pAtaFile, 0);

    /* Read the data from the file in little endian mode */
    ata_error = ATA_readLittleEndian(pAtaFile,gMmcReadBuf, CSL_MMCSD_ATA_BUF_SIZE);
    if(ata_error != ATA_ERROR_NONE)
    {
        printf("ATA_readLittleEndian Failed\n");
        return(ata_error);
    }
    else
    {
        printf("\nReading Data from the file on SD card successful\n");
    }

    /* Close the file */
    ata_error = ATA_close(pAtaFile); 

 

Any ideas as to why that would happen, or should any other ATA FS function be called between those writes?

 

Thanks,

Shahar

  • If I don't call  ATA_seek () and ATA_readLittleEndian() then the file is written successfully.

    From that behavior, I assume the that the file structure has to "point" to the end of the file in order to successfully close it (i.e., correctly update the FAT). Is that correct?