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.

TM4C129ENCPDT: Other microcontrollers forum

Part Number: TM4C129ENCPDT

Hi All,

I am using ti rtos tirtos_tivac_2_16_01_14 with CCS version 9.1. I am using external flash memory MX25L128 using spi along with FatFS file system using ROM APIs.

Previously I was using the buffer size of 512 and now I changed it to 4096 as the sector size of flash memory is 4096.

I changed it here- 

#define _MIN_SS 4096 //512
#define _MAX_SS 4096 //512        in ffconf.h

This issue is a bit weird. I'll try to explain it.

I have created the CONFIG file, LOGSENT file, LOGFILE file in the flash memory. I am able to read/write/open ( fatfs API calls )  the CONFIG file and LOGSENT file. But when it comes to LOGFILE, I can only do open/write operations. When I try to read the log file, it is giving some weird error. I am attaching the 2 screenshots. One before the reading the LOGFILE, and one after reading the LOGFILE. I want you to see the debug window. After the f_read call, my function stack goes corrupt and I got an exception- 

LOGFILE size 6807
Error:E_hardFault: FORCED

Error:E_busFault: PRECISERR: Immediate Bus Fault, exact addr known, address: bebebebe
FSR = 0x0000
HFSR = 0x40000000
DFSR = 0x00000000
MMAR = 0xbebebebe
BFAR = 0xbebebebe
AFSR = 0x00000000
Terminating execution...

This only happens when I use the buffer size of 4096. If it is replaced to 512, everything runs fine. I have to use 4096 buffer size. Please let me know. Thanks

  • Hi Akhilesh,

    Can you take a look at Tools->ROV->Tasks->Detailed to see how big your tasks stacks are? Do you happen to have the buffer of size 512 or 4096 as a local variable? If so, when you increase from 512->4096, I expect you need to increase your task stack size also (or make the buffer a global or alloc it).

    Note: I'm suspecting this because we initialize task stacks with 0xbebebebe.

    Todd

  • Hi Todd,

    I resolved this issue. Let me understand if I am doing right.

    What I did is I changed the buffer size in ffconf.h. The FATfs I am using is from ti rtos. So I had to rebuild the ti rtos components in order to make these changes effective. When I rebuilt it, it is working fine. But again I have a few doubts.

    1. Now that I am using a buffer size of 4096 as this is the sector size of my flash. What will happen every time if the buffer which I am going to write in some file say xyz.txt is less than 4096? In the end, whatever the size of the buffer, we can only write 256B at a time (as seen from the datasheet of flash). So, I am breaking the buffer of 4096 into 16 parts and writing it one by one in the MX25FatFs_diskWrite() function. If the content to be written is less than 4096B, will it waste the extra space in the sector or what it will do? Because in the function MX25FatFs_diskWrite(), I am getting the sector number. I map this sector no to the address by multiplying it with 4096. 

    for(ui32PageIdx = 0; ui32PageIdx < 16;
    ui32PageIdx++)
    {
    MX66L51235FPageProgram((ui32BlockAddr + (ui32PageIdx * 256)), (flashBuf + (ui32PageIdx * 256)), 256);
    } // this is what I am doing while writing. 

    2. How the MX25FatFs_diskWrite() is getting the sector no? I am calling f_write/f_open/f_read and MX25FatFs_diskWrite/read etc gets the sector no? I mean how the whole system FATfs is working? Still, I am not able to figure it out. 

    Thanks

    Regards,

    Akhilesh

  • Akhilesh,

    For detailed questions about FatFS, please refer to the third party site: http://elm-chan.org/fsw/ff/00index_e.html

    Todd

  • Hi Todd, Can you explain 1st point?

    Also, what if I want to use sdspi drivers for flash? Will that work? I tried the sample code on the evaluation board df-tm4c129x but the error was check jumper settings. I tried the example fatsdDK-tm4c129x from the resource explorer. 

    Thanks

  • Akhilesh,

    The SDSPI driver works on SD cards.

    Regarding the first point, you need to work with FatFS vendor on this question.

    Todd

  • Hi Todd,

    Just a query, how will you suggest to me to read/write operation using ROM APIs on fatfs at a low level. 

    1 more thing. I am attaching the screenshot also.

    When I format the flash and start creating file and writing, I have some doubts about the no of free clusters and others. 

    1. Volume size 537040504 clusters after calling  f_getfree(path, &fre_clust, &g_MX25Handle); 

    I don't understand why it is showing such a large value.

    2. During the debugging, I checked the value of FIlL ptr and those are in the screenshot attached.

    - free_clust = 1463. Why??

    - n_fatent = 4028. Is this because I have set the buffer size of 4096 and the total no of sectors is 4096? My csize is 1 i.e. 1 sector per cluster. 

    - My volume base starts at sector 63. Why? It wastes a lot of space. (62*4KB).

    - fatbase starts at 64. 

    - dirbase starts at 66

    -database starts at 70. Why? (Check the attached screenshots )

    What is it doing from 0-63 sectors? 

    Thanks

  • You can use the ROM driverlib functions in the lower level driver. Please refer to https://www.ti.com/lit/ug/spmu298d/spmu298d.pdf for more details on how to use them.

    Sorry, TI did not author the FatFS module. You need to contact the FatFS vendor for support questions.

    Todd