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.

AM5728: Read/write on FAT SD card

Part Number: AM5728


I would like to write and read files on an SD card formatted with FAT file system using the TI AM5728 EVM.  Section 6.12.3.2 of the Processor SDK RTOS mentions that APIs can be used to perform file operations (i.e. f_open(), f_write() and etc.).  However, PDK doesn't have an example demonstrating how this is done.  Also the FAT documentation below doesn't include these APIs:

$(TI_PDK_INSTALL_DIR)\packages\ti \fs\fatfs\docs\doxygen\html\index.html

Please let me know if an example exists to write/read files on an SD card formatted as FAT.

Thanks,

Dave

  • Hi,

    Your query has been assigned to a TI engineer. Please note that feedback may be delayed due to holidays in the USA.

  • Hi Dave,

    In Processor SDK RTOS 6.1.0 for AM57xx, there is an example under pdk_am57xx_1_0_16\packages\ti\drv\mmcsd\example\fatfs_console. It shows the FATFS on SD card.

    Ming

  • Ming,

    Thanks for your help.  I successfully demonstrated a file copy operation using the FATFS Console example (i.e. via "cat" command).  

    However, when the SD card is inserted into a Windows PC the copy is often corrupted.  Perhaps the SD card needs to be unmounted.  Please let me know if I should invoke FATFS_close() before removing the SD card from the EVM.

    Regards,

    Dave

  • Hi Dave,

    Please make sure you do the f_close() (which will flush all the data to the files on SD card) for all the f_open()-ed files before eject the SD card. FATFS_close is not that important.

    Ming

  • Ming,

    I am using a simple "hello.txt" file which contains "abc" to verify the FAT console example.

    My test sequence is as follows:

        (1) cat hello.txt > h1.txt <CR>

        (2) cat h1.txt <CR> 

    Note "abc" is successfully displayed for step (2).  

    Next I eject the SD card and insert into a Windows PC.  Windows Explorer correctly lists h1.txt for SD card file contents and h1.txt properties displays correct size of 3 bytes.  However, I get "can't find file" anomaly when trying to open h1.txt.  If I then eject and reinsert the SD card then Windows wants to repair it.  See screenshots below.

    Note, I added "printf's" to verify f_close() is being performed correctly for the "cat" command.  FYI - per your advice FATFS_close() also didn't help.

    Please let me know if you have any ideas to fix this anomaly.

    Regards,

    Dave

  • FYI - file "h1.txt" is no longer present after the "scan and fix" operation.

  • FYI - performing f_sync() before f_close() doesn't resolve the issue.  I am not sure if any hardware caches need to be invalidated or if this is a Windows 10 issue.

    Regards,

    Dave

  • Hi Dave,

    I did the same steps you did. I can see the newly created file on SD card. I did see the  "scan and fix" and "continue" options. I choose to "continue". I am using the micro SD card as the boot disk also (copy the MLO and app into the micro SD card). I saw you were not booting from SD card.

    It seems pointing to the Windows format program. In order to make a micro SD card to be bootable for AM572x, you will need to either format it to FAT32 with HP formatter or the Linux format tools.

    Can you try to make the micro SD card into a bootable SD card and try it again?

    Ming

  • Ming,

    Today I demonstrated data integrity is maintained if I don't insert the SD card into a Windows 10 PC.  At this point I wish to defer debugging Windows 10 compatibility issues since it is preferred to retrieve data via FTP.

    FYI my SD card was initially made bootable using Win32 Disk Imager (i.e. write the TI prebuilt sd_card.img file).  This SD card was later "fixed" by Windows when corruptions were detected.  Note that I deleted the MLO and app from this card since I am debugging via JTAG.

    Thanks again for your help,

    Dave

  • Hi Dave,

    It is good to know the data integrity has been maintained by the FATFS.

    In fact, I see this "SD card or USB flash drive corruption" warnings all the time on Windows, especially when the SD card or USB drive have been operated on other OS machines. My guess is that this is a Windows issue.

    Would you mind mark this thread as "Resolved".

    Ming