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.

FatFS problem with NAND Flash (2048 byte pages) on C6748LCDK

Other Parts Discussed in Thread: SYSBIOS

Hi,

This is now more of a blog for other users of NAND flash and for TI to fix the code correctly, I hope it helps (please let me know if I have missed something as no one else seems to have had this issue on the forums!):

I'm trying to get the NAND flash working correctly on the C6748LCDK, the sample application in the PSP seemed to work, but when I integrated it in to my application it started causing problems, such as stack overflow (of previously working tasks), heap suddenly running of of memory or becoming corrupt. I switched to polled mode (and made other modifications to get polled mode to work) to remove use of the Edma (to allow me to debug more easily) and eventually tracked down (what I think) the problem is.

The NAND flash device on the C6748LCDK has 2048 byte pages, but the FatFS in SYS/BIOS is configured for 512 bytes sectors in bios_6_35_04_50\packages\ti\sysbios\fatfs\ffconf.h:

#define _MAX_SS         512             /* 512, 1024, 2048 or 4096 */

After digging down the call tree I found the code in biospsp_03_00_01_00\drivers\nand\src\llc_nand.c function LC_nandReadDataArea() reads 4 subpages of 256 x16 bits words (total 2048 bytes) in to a 512 byte buffer contained within a FATFS structure element BYTE win[_MAX_SS], in a call to  disk_read(fs->drv, fs->win, sector, 1) from move_window() in bios_6_35_04_50\packages\ti\sysbios\fatfs\ff.c.

So my question is how best to resolve this problem?

Normally I would change _MAX_SS to 2048 and re-compile the library, but it is part of bios_6_35_04_50 and I don't see how I can easily re-compile it. - I think I've just found the answer in Appendix A of the SYS/BIOS User Guide (http://www.ti.com/lit/ug/spruex3m/spruex3m.pdf).

After fixing the above it still doesn't work correctly, it gets stuck formatting the NAND flash (30 mins+) before I stopped it. More debugging and I found that the ssize element in the FATFS structure in ff.h should actually be a DWORD (32-bits) instead of a WORD, because there are a few calls to disk_ioctl(fs->drv, GET_SECTOR_SIZE, &fs->ssize) which actually calls blkMediaNandIoctl(BYTE drive, BYTE cmd, void * buf) in blkmedia.c, this writes a 32-bit int in to the 16-bit (WORD) data. This code also need modifying to return the correct sector size: *((UInt32 *)buf) = 2048 /* was 512 */;

So here are my quick and dirty hacks to fix it all:

1) Copy the complete bios_6_35_04_50 directory to bios_6_35_04_50_orig

2) In bios_6_35_04_50\packages\ti\sysbios\fatfs edit:

 ffconf.h and change:   //#define _MAX_SS         512             /* 512, 1024, 2048 or 4096 */   #define _MAX_SS         2048             /* FIX_NAND 512, 1024, 2048 or 4096 */

 ff.h and change:   //        WORD    ssize;                  /* Bytes per sector (512,1024,2048,4096) */         DWORD    ssize;                  /* FIX_NAND Bytes per sector (512,1024,2048,4096) */

3) Copy the complete bios_6_35_04_50 directory to bios_6_35_04_50_compile.  Edit: bios_6_35_04_50_compile\bios.mak and change the following lines to your installation (or whichever build you require):  See: Appendix A of the SYS/BIOS User Guide (http://www.ti.com/lit/ug/spruex3m/spruex3m.pdf) for more info.  This is what I changed for C6748:     XDC_INSTALL_DIR ?= c:/TI/CCSv5/xdctools_3_25_03_72   ti.targets.elf.C64P ?= c:/TI/CCSv5/ccsv5/tools/compiler/c6000_7.4.4   ti.targets.elf.C674 ?= c:/TI/CCSv5/ccsv5/tools/compiler/c6000_7.4.4

In Windows CMD prompt in the bios_6_35_04_50_compile directory type: gmake -f bios.mak It takes a long time to build, mine actually fails (with a segmentation fault) when starting the instrumented libraries (which is why I copied the directory to _compile first), but it had built the fatfs libs - that all I need.

4) Using explorer go to the bios_6_35_04_50_compile\packages\ti\sysbios\fatfs\lib\release, copy all the files and paste them in to bios_6_35_04_50\packages\ti\sysbios\fatfs\lib\release overwriting the exsiting ones.

5) copy your biospsp_03_00_01_00 directory to biospsp_03_00_01_00_orig.

6) Edit biospsp_03_00_01_00\drivers\blkmedia\src\blkmedia.c:  In blkMediaNandIoctl(BYTE drive, BYTE cmd, void * buf) change:   //  *((UInt32 *)buf) = 512;     *((UInt32 *)buf) = 2048; /* FIX_NAND */

7) Build your biospsp_03_00_01_00, in a Windows command prompt, cd to the biospsp_03_00_01_00 directory and type:   set ROOTDIR=C:\<your path to>\biospsp_03_00_01_00   gmake all

Again this takes a long time to build (and hence I have time to write this up!).

8) Rebuild you application with the NAND flash (biospsp) and bios libs and hopefully it should now work!

NOTE: blkMediaNandIoctl() in blkmedia.c should really get the sector size from the lower level NAND drivers for this to automatically work with different page sized devices. I'll leave that for TI to fix.

Cheers,

 

Tony