Implementing Freescale FAT Lite on ColdFire

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

Implementing Freescale FAT Lite on ColdFire

6,547 Views
PabloA
Contributor II

Hi there, I need some help about this issue:

 

I'm working in a data logger project like DEMOFLEXISJMSD_DataLogger_V2

http://www.freescale.com/webapp/sps/site/training_information.jsp?code=WBNR_SDCARDREADER_S08JM&fsrch...

This example use a SD card and Freescale FAT Lite to storage data.

 

I implemented the same FAT functions in the MCF51CN128RM ColdFire with the following results:

 

1. SD_Init() function returns:

     Ok (0).

 

2. FAT_FileOpen (FILE_NAME, MODIFY) function returns:

    FILE_NOT_FOUND (1) ->     If the file was not created with the same function with CREATE (1) as parameter.

                                              If I create a file using Windows XP, this function doesn't found it.

 

     FILE_FOUND (0) ->             Just if the file was created using FAT_FileOpen function.

 

3. FAT_FileOpen (FILE_NAME, CREATE) function returns:

     FILE_CREATE_OK (2) ->  But when I read the SD Card using Windows XP nothing appears.

 

I'm using FAT functions like this:

 

 

SD_Card_Status = SD_Init();

 

if (SD_Card_Status != OK)

{

     return;

}

 

FAT_Read_Master_Block();

 

SD_Card_Status = FAT_FileOpen (FILE_NAME, MODIFY);

 

if (SD_Card_Status = FILE_NOT_FOUND)

{

     SD_Card_Status = FAT_FileOpen (FILE_NAME, CREATE);

}

FAT_FileClose();

 

 

SD_Card_Status = FAT_FileOpen (FILE_NAME, MODIFY);

FAT_FileWrite (SD_String_Array, 20);

FAT_FileClose();

 

In this forum I found a discussion about Freescale FAT (https://community.freescale.com/message/86766#86766) but i can't solve the problem.

Even I  tried changing some part of the code suggested in the forum, but it doesn't work.

 

Cuestions:

 

Why FAT_FileOpen function returns FILE_CREATE_OK and Windows can't read it?

Why FAT FileOpen function can't recognize a file created with Windows?

Is this FAT library able to manage up to 2Gbs?

 

If some body test Freescale FAT Lite at ColdFire, please give me some tips.

 

Best regards!

 

Pablo Suárez

Labels (1)
0 Kudos
Reply
35 Replies

1,410 Views
guille
Contributor II

Great! Thx

0 Kudos
Reply

1,410 Views
carlospalma
Contributor I

Hello, people. I return to this thread because after conducting extensive test, two problems were found when implementing the library:

1. Worked with JM60 when tested on a PCB (not development system) but not with JM128, no idead about the reason  for this, if anyone has any clue I would like to hear about it.

2. The system developed in PCB is unable to create .txt files larger than 32 KB, after that I get an error message telling me that there was an error when opening the file and I must make sure there's a volume on the specified unit. So far I think this may be a result of that routine to read the master block, but it could be anything else.

0 Kudos
Reply

1,410 Views
leonardomontero
Contributor I

Hi Carlos, I solved the problem by replacing the assembler instruction asm (BGND) of the family HS08 by the assembler instruction asm(WDEBUG (A0)) of the Coldfire family in FAT.C file in the function FAT_FileWrite

0 Kudos
Reply

1,410 Views
guille
Contributor II

Hi Carlos, it seems that theres is an issue with the FAT library when creating files larger than the "allocation unit size" (also known as "cluster") used on the SD card. This comes from one of the original functions of the Freescale FAT library.

For example, in my case, the cluster size is 8KBytes (8192Bytes) so I can't create files larger than 8192Bytes succesfully. I was wondering if you use cluster of 32KB, it would explain that in your case you had troubles with files larger than 32KB.

Best regards,

Guille.

0 Kudos
Reply

1,410 Views
guille
Contributor II

Hello people, after a long break i'm working again. I'm sorry for the delay of this answer. Carlos, it seems that you tested the library more than me. Right now we are reworking on the PCB, making our product smaller. The next step is a firmware review (including the FAT library) so I will notify you when I have more results. It is a main gole for us to reach a reduced, simple and stable FAT library, but we are testing only with the JM128, so I can't tell you how is it about the JM60. Again, sorry for the delay of this answer.

Best regards,

Guille.

0 Kudos
Reply

1,410 Views
JimDon
Senior Contributor III

Has anyone tried Chan's code lately? I used it several years ago and it worked well.

FatFs - Generic FAT File System Module

0 Kudos
Reply

1,410 Views
sebasira
Senior Contributor I

Hello again Jim!

I'd like to give a try to Chan's PetitFs.. As you said is the only one with a good support. The problem is that I don't know what to do with diskio.c... I guess that is where I'm suppose to pu SPI routines. I know how to configure ths spi, how to read a byte and write a byte.

But what EXACTLY should I do in each routine? Could you provide and example?

Thanks!

0 Kudos
Reply

1,410 Views
sebasira
Senior Contributor I

I've seen both (FatFs and PetitFat) years ago but never test them. I'm guessing I should use PetitFat because I don't believe I've got enough space for the full project.

But it was written for 8bit MCU and I'm using a 32bit one (MCF51QE). Since the project was done 3years ago I also guess it wouldn't have "support" in case of errors/problems

The advantage is the support of FAT32.

Jim: In which MCU did you test it? Would you recomend me to try it on a 32bit MCU? I'm asking you that because the original Freescale library was also ment for 8bit MCUs and when I ported to 32btis, I couldn't make it work until someon (I believe it was Carlos Cuevas) point me that I should change struct alignment to be byte instead of long. Until that moment I didn't know about struct alignment. I don't know if a problem like this one can arise with this project too; and without support, it would be difficult to port.

EDIT: I just re-check ELM's library... and I notice it only provides FAT routines, not low-leve disk IO. Now I remember that was the final reason why I didn't use it.

0 Kudos
Reply

1,410 Views
JimDon
Senior Contributor III

The latest version was posted January 24 2013 so I would say it is still getting great support. Combined with the fact that the first release was 2006, it's age is a huge advantage, rather than a disadvantage.

The bit size of the processor should not at all be an issue - endianness and structure packing (a compiler issue) are bigger deals but IIRC he had solutions for that (of course structure packing must be by compiler, but we all know about that one).

He says it supports FAT12/16/32 long file names.

I ported it to a Dragon12 board (HCS12 - a 16 bit processor). Once I got my issue ironed out (Proper SPI operation etc), it was fine. You probably have the device specific issues already working.

I don't have an SD card slot right now, so I can't try it at this time, but I think it might be worth looking at.

0 Kudos
Reply

1,410 Views
sebasira
Senior Contributor I

One thing I forgot to mentioned, is that not all the SD Cards can be handled via SPI... SunDisk's ones does. And if I recall correctly 2GB is the maximum for DRM104 FAT and also suan's library.

Saludos!

0 Kudos
Reply

1,410 Views
TomE
Specialist II

More interesting information on the various FAT formats and their history here:

http://en.wikipedia.org/wiki/Fat16

A bit of perspective from Wikipedia. FAT16 (actually FAT16B) dates from 1987, 25 years ago. FAT32 was introduced with Windows 95 OSR2 in 1996, 16 years ago. FAT32 supports 32 bit cluster numbers, increasing the disk size from the 2G FAT16 limit to 16T. FAT32 usually implies "VFAT Long File names" (LFN) too, otherwise you have to use "8.3 file names".

FAT16 is fine for embedded storage, but if you want to be able to swap SD cards or USB Keys between the embedded system and other computers you'll have less problems if you get a stack that supports FAT32 and LFNs. That one doesn't support directories either (only files in the root directory).

> I needed to use SD Formatter:

Under Windows (at least XP) with small enough memory sticks you have the choice of formatting "FAT32", "FAT" or "exFAT". That library might work with "FAT" formatting.

If you are swapping cards between the embedded device and a PC, be careful, and expect to lose data when the computers somehow disagree. I've even had the linux-based OS in a Tektronix oscilloscope format a USB Key in a way that Windows accepted, but which put a commercial embedded FAT32 stack into an infinite loop.

Tom

0 Kudos
Reply

1,410 Views
sebasira
Senior Contributor I

Hi Pablo!

I was having lots of problem with DEMOFLEXISJMSD_DataLogger_V2 software, even I've read that it's got lots of bugs... Also, I was using it and sometimes it just hangs... It's been working fine and then suddenly it crashes for no reason so it was not reliable.

After lots of headaches I've found this: https://github.com/suan/Freescale-SD-FAT-Library and it works like a charm!!!

About FILE_CREATE_OK and can't see it on Windows (XP or 7), I can tell you 2 things:

1- In CodeWarrior Project Settings, you MUST set Struct Aligment to byte under ColdFire Processor panel.

2- With suan's Library I needed to use SD Formatter: https://www.sdcard.org/downloads/formatter_3/ to format the SD card because when I formatted with windows it wouldn't have the format as the Library espect it to be (I didn't go deeper with this but I think is about FAT standards. This is the structure that suan's Library uses: http://home.teleport.com/~brainy/fat16.htm)

I strongly recommend you to use this Library instead of the one from DRM104. So far I haven't got a single error regarding SD Card writes (I don't perform readings). And as you can see in older post I did have a lot of problems before.

0 Kudos
Reply

1,410 Views
jaroslavnecesan
Contributor I

Hi Pablo.

I have the same problem now and I don't know how to solve it. Have you found how to solve it meanwhile? Thank you

Jaro

0 Kudos
Reply

1,410 Views
TomE
Specialist II

In that previously referenced discussion it looks like they were working from a modified version of FAT Lite. So whatever version you found may need previous modifications before finally those endian-related modifications will work.


Where did you get the library from? What download link?

This library was originally for 8-bit processors, and if it wasn't written to have the right structure sizes on 32-bit native CPUs, all of the "ints" might be the wrong length. These absolutely have to match Microsoft's definition of which bit and byte goes where in the FAT and Directory entries.

If Freescale don't support a working FAT file system on these chips and you can't afford to buy one, this may turn into a big waste of your time.

Tom

0 Kudos
Reply

1,410 Views
scifi
Senior Contributor I

I seem to remember that the Codewarrior Coldfire compiler has configurable size of int and minimum alignment. So it might be possible to compile the code with the right settings to make it work.

0 Kudos
Reply