FatFS not working in LPCOpen 2.04 for LPC4357 - see below for fix

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FatFS not working in LPCOpen 2.04 for LPC4357 - see below for fix

439 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rgledhill on Mon Feb 24 07:36:39 MST 2014
Hi all,

One of the several things sadly broken (and therefore clearly untested) with the LPC4357 LPCOpen2.04 build for Keil is FatFS which doesn't work with Long FileNames (LFN mode).

Thankfully they also produced an App Note a while back which describes how to do it properly:

http://postar.sino-star.com/public/uploads/20120319112312_598.pdf

Following these steps, and in particular the configuration settings described therein, has allowed us to use FatFS with LFN support except mysteriously when listing files, which still only works in 8.3 format.

Hope this helps!

Richard
Labels (1)
0 Kudos
3 Replies

334 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kaikeraut on Wed Apr 02 05:16:58 MST 2014
can anyone send me the working code for lpc4330  freertos + sdmmc + fatfs
0 Kudos

334 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rgledhill on Fri Feb 28 01:15:08 MST 2014
Hi,

Thank you, that's immensely helpful!  It would be very useful if NXP included your code above, but left the default of LFN disabled.

It would be great if this could go into next week's LPCOpen update...

I'll let you know how we get on, and thank you again.
Richard
0 Kudos

334 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sundarapandian on Thu Feb 27 12:43:00 MST 2014
LPCOpen ChanFatFS is supplied with the default configuration. If you want to modify any configuration parameters you should consult the documentation pages at this link. Moreover LFN is a patent owned by Microsoft and may be that is the reason elm-chan.org decided not to enable it in the default configuration. If you want to enable unicode support you can read the documents here.

If you want to enable LFN functionality, I would suggest you to read the documentation provided here. According to that document to enable LFN the user must implement the functions ff_convert and ff_wtoupper you can find these functions inside (software\filesystems\fatfs\src\ccsbcs.c) add it to your project or you can implement your own conversion function.

For your information I will provide you the steps I did to enable LFN in my projects

Implement a simple conversion function (Unicode support is too big so I don't use the default ones)

WCHAR ff_convert (WCHAR wch, UINT dir)
{
if (wch < 0x80) {
/* ASCII Char */
return wch;
}

/* I don't support unicode it is too big! */
return 0;
}

WCHAR ff_wtoupper (WCHAR wch)
{
if (wch < 0x80) {
/* ASCII Char */
if (wch >= 'a' && wch <= 'z') {
wch &= ~0x20;
}
return wch;
}

/* I don't support unicode it is too big! */
return 0;
}


I enable the LFN support by (defining _USE_LFN as 1 in software\filesystems\fatfs\src\ffconf.h, I left _LFN_UNICODE as the default 0)

#define_USE_LFN1


That is it, the following works fine
f_open(&Fil, "New_Text_Document.html", FA_READ);


Although there is no good document that says how to list the files using LFN but I had little peek into the chanFATFS code and came up with the following code

static TCHAR lfname[_MAX_LFN];


        result = f_opendir(&dir, "");
        /* Check result for errors */

printf("Directory listing...\r\n");
for (;; ) {
fno.lfname = lfname;
fno.lfsize = _MAX_LFN - 1;
/* Read a directory item */
rc = f_readdir(&dir, &fno);
if (rc || !fno.fname[0]) {
break;/* Error or end of dir */
}
if (fno.fattrib & AM_DIR) {
sprintf(debugBuf, "   [dir]  %s\r\n", fno.lfname[0] ? fno.lfname : fno.fname);
}
else {
sprintf(debugBuf, "   %8lu  %s\r\n", fno.fsize, fno.lfname[0] ? fno.lfname : fno.fname);
}
printf(debugBuf);
}
0 Kudos