Problems porting SD FAT to MCF51 JM Badge Board - Datalogger application

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

Problems porting SD FAT to MCF51 JM Badge Board - Datalogger application

Jump to solution
7,031 Views
celsoken
Contributor V

Hi,

 

I am trying to use 9S08JM60 SD FAT software in MCF51 Badge Board but it doesn't seem to work.

Maybe someone already had these troubles and could help me in this job.

 

My goal is to run a (real) datalogger software designed for automotive applications, based on AP32.

I'll port the AP32 software to MCF51 after SD is working fine.

 

Besides the usual voltage/frequency/temperature inputs, I'll use QG8s as interface coprocessors - I gave up trying to imagine what I'll connect in the future.

 

Any help will be appreciated.

 

Thanks in advance,

 

Celso

Labels (1)
1 Solution
3,744 Views
celsoken
Contributor V

Solved:

 

Found a bug in SD_Write_Bloc (SD.C)

 

This software implements a software timer - wich is against Flexis recommendations - after sending the block to be written. It tipically worked on 9S08JM60 but crashed in MCF51.

 

The changes were from:

 

=============================================

for(u16Counter=0;u16Counter<BLOCK_SIZE;u16Counter++);

if((ReadSPIByte() & 0x0F) != 0x05) 

=============================================

 

To:

=======================================================================

SD_response=0xFF; // #001 created this variable
while (SD_response==0xFF) SD_response=ReadSPIByte(); // #001 wait for SD response <> 0xFF
if((SD_response & 0x0F) != 0x05)  // #001 checks if response = 0101 = data accepted
  
    {
        SPI_SS=DISABLE;
        return(WRITE_DATA_FAILS);     
    }
========================================================================

 

Preliminary test appears to be working.

And I look like a lunatic, talking to myself.
At least maybe it helps someone.

 

Celso

View solution in original post

0 Kudos
Reply
27 Replies
3,161 Views
guille
Contributor II

Hi there, I just published a revised version of FAT Lite. Some improvements were taken from this thread (thx!),  the others were the result of the efforts of me and my team.

http://code.google.com/p/sdfatlite/

Cheers!

3,166 Views
celsoken
Contributor V

Some progress done:

 

1. FAT_Read_Master_Block needed byte struct alignment setting in order to return coherent results.

 

2. File not found showed me how stupid I am, forgetting that XP uses hidden extension format so LOG.TXT turns out to be LOG.TXT.TXT

 

What is missing: FileWrite and FileClose does not seem to be working, any hints??

 

Thanks in advance,

 

Celso

 

0 Kudos
Reply
3,745 Views
celsoken
Contributor V

Solved:

 

Found a bug in SD_Write_Bloc (SD.C)

 

This software implements a software timer - wich is against Flexis recommendations - after sending the block to be written. It tipically worked on 9S08JM60 but crashed in MCF51.

 

The changes were from:

 

=============================================

for(u16Counter=0;u16Counter<BLOCK_SIZE;u16Counter++);

if((ReadSPIByte() & 0x0F) != 0x05) 

=============================================

 

To:

=======================================================================

SD_response=0xFF; // #001 created this variable
while (SD_response==0xFF) SD_response=ReadSPIByte(); // #001 wait for SD response <> 0xFF
if((SD_response & 0x0F) != 0x05)  // #001 checks if response = 0101 = data accepted
  
    {
        SPI_SS=DISABLE;
        return(WRITE_DATA_FAILS);     
    }
========================================================================

 

Preliminary test appears to be working.

And I look like a lunatic, talking to myself.
At least maybe it helps someone.

 

Celso

0 Kudos
Reply
3,166 Views
baja_usb
Contributor II

Hi, I'm trying to store some data on a SD card using my JMBADGE. I found out that the SD_PRESENT pin is not PTB7 but PTF3, at least in the Rev. C board.    

Although I've changed the code in the SD_Write_Block(...) routine, I can't get it work. How should be the byte struct alignment setting in the FAT_Read_Master_Block routine? How can I do that?

 

I saw the sd car reader webcast but, there is a .pdf or some kind of application note explaining the FAT API?

 

Thanks a lot!

 

Daniel

 

0 Kudos
Reply
3,166 Views
celsoken
Contributor V

Dear Daniel,

 

The byte struct alignment is a codewarrior setting, located in compiler options.

The FAT API I used is an 8-bit one, I could not find the powerpoint file that explained the Lite FAT but you could start digging at: http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=DEMOFLEXISJMSD&fpsp=1&tab=Design_Tool...

 

Good luck,

 

Celso

 

0 Kudos
Reply
3,166 Views
sebasira
Senior Contributor I

Celso, I've found the presentation you were talking about... It explain Lite FAT

 

it can be downloaded from here: link

 

Also, on Freescale website there's a video explaining this presentation: SD Card Training by Freescale

 

Hope it helps to anyone

0 Kudos
Reply
3,166 Views
celsoken
Contributor V

Dear Sebastian,

 

First of all, sorry for my late reply.

 

I took 2 days off for extended weekend - guess where? - Bs Aires.

I had to fulfill my quota of Bifes de Chorizo and malbec wines so Argentina is the best place. Good reason, huh?

 

Honestly I didn't see this subject since 2009, but I checked and the byte struct alignment is a codewarrior setting, located in compiler options. It is little endian/big endian option. CW default is one and the FAT driver needed the opposite.

 

I hope it helps.

 

Saludos,

 

Celso

 

0 Kudos
Reply
3,166 Views
sebasira
Senior Contributor I

Hi Celso!

 

 

So you were visiting my country? Great! I hope you enjoy it... I've got no doubt about Argentine's meat and wines... they're great! I really love "asado".

Bs Aires is not my preferred city, it's too messy, people live with lot of stress that's the problem of being a Capital City and a really big one. I live in Rosario, the second city of the country... and I really love it...

 

Well, I've found struct aligment setting, manage to change it and now it's working perfectly... But I want it to know what does it mean... Or how you realize the problem were there, I guess it could take a mi a lifetime to figure it out.. I really don't pay much attention on codewarrior settings, because till now I never had to deal with them.

 

Thanks! and Saludos!

0 Kudos
Reply
3,166 Views
celsoken
Contributor V

I'm glad you solved your problem.

The problem is related to data organization.

It's quite simple, take a 32-bit example the hexa # 3F528644

It could be stored sequentially in memory like:

3F, 52, 86, 44 (MSB fist)

or like:

44, 86, 52, 3F (LSB first)

 

Regarding Rosario, it's my preference too (Fito, Les Luthiers, ...) but I was with my wife her preference is shopping. So we went to Bs As.

If you wanna discuss further pls do it in private because it is out of scope of this forum.

 

Saludos,


Celso

 

 

0 Kudos
Reply
3,166 Views
JimDon
Senior Contributor III

Guys,

Endian order and struct alginment are two different things.

Did you change "Struct Align".

Which do you change?

It's not 100% clear to me....

 

0 Kudos
Reply
3,161 Views
celsoken
Contributor V

Jim, you're right.

I've checked my release notes and I've translated them to english:

 

FAT adapted from JM60 datalogger app
- changed SPI treatment to MCFJM51 (specially new timing)

- BGND instruction deleted from FAT.C
- SD.h was added include IO_Map.h for MCF51 I/O
- Define Struct Alignment: byte to get compilation OK, otherwise it crashes on FAT_Read_Master_Block
- Found and corrected a bug in SD_Write_Bloc (SD.C)

This software implements a software timer - wich is against Flexis recommendations - after sending the block to be written.
It tipically worked on 9S08JM60 but crashed in MCF51.
The changes were from:
=============================================
for(u16Counter=0;u16Counter<BLOCK_SIZE;u16Counter++);
if((ReadSPIByte() & 0x0F) != 0x05)
=============================================

To:
=======================================================================
SD_response=0xFF; // #001 created this variable
while (SD_response==0xFF) SD_response=ReadSPIByte(); // #001 wait for SD response <> 0xFF
if((SD_response & 0x0F) != 0x05)  // #001 checks if response = 0101 = data accepted
    {
        SPI_SS=DISABLE;
        return(WRITE_DATA_FAILS);    
    }
========================================================================

Sorry, I've got too much wine!

 

Regards,

 

Celso

0 Kudos
Reply
3,161 Views
JimDon
Senior Contributor III

celsoken,

I wasn't tring to get on your case, I'm planning to use this code on 51JM, so I wanted to be sure.

Plus, I don't think you can change the Endianess of the CPU :smileyhappy:.

Now explain structure alginment to our friend as well as you did endiness....

 

0 Kudos
Reply
3,161 Views
celsoken
Contributor V

Dear Jim/Sebastian,

 

(you're abbusing on my hangover situation :smileyhappy: )

 

The structure alignment deals with internal organization - a compiler issue.

I think that 4-byte boundaries is standard for Coldfire while 8-bitters use a 1-byte one.

As the code was originally written for S08 processor I assumed it uses a single byte struct alignment.

But I'm not 100% sure.

 

Sebastian, you can get more detail in http://en.wikipedia.org/wiki/Data_structure_alignment

 

Cheers,

 

Celso

0 Kudos
Reply
3,161 Views
sebasira
Senior Contributor I

jajajajajajaja I can't stop laughing  about your hangover....

 

Thanks for the info!

 

0 Kudos
Reply
3,161 Views
sebasira
Senior Contributor I
- changed SPI treatment to MCFJM51 (specially new timing)- BGND instruction deleted from FAT.C- SD.h was added include IO_Map.h for MCF51 I/O- Define Struct Alignment: byte to get compilation OK, otherwise it crashes on FAT_Read_Master_Block- Found and corrected a bug in SD_Write_Bloc (SD.C)

 I've done everything you mention.... except the followings:

- Change SPI treatment

- include IO_Map

 

About IO_Map I guess it's related to your hardware or your application.... so I guess it's not relecant...

 

What you mean about SPI treatment? I leave it as it was and works fine..

0 Kudos
Reply
3,161 Views
celsoken
Contributor V

Dear Sebastian,

 

Probably our hardware (board, processor speed, SPI rate or even SD card) were different so I needed to change it. Maybe you don't need any change at all.

 

E.g. the software timing loop in the original release crashed so maybe I was running the MCF at higher speed.

 

Regards,

 

Celso

0 Kudos
Reply
3,161 Views
sebasira
Senior Contributor I

Thanks Celso... I just want to know if I was missing something!

 

Best Regards!

0 Kudos
Reply
3,166 Views
sebasira
Senior Contributor I

Hi Jim!

 

I've change Struct Align combo Box to be BYTE, under codewarrior project settings, under coldfire settings... It's available for CFv1, and it's no available for S08JM family

Hope it helps!

 

Celso, in your example wich is byte aligned? and what's the alignemnt of the other?

 

Thanks!

0 Kudos
Reply
3,166 Views
sebasira
Senior Contributor I

Celso...

 

Can't believe I'm as stupid as you said before when I read your post I past over the part you said about hidden extension... That was the problem...

 

Now.. With mi badge board MC9S08JM60 I can't find the byte aligned you mentioned... Or is it only for CFv1 MCUs?

 

I'd like to learn more about FAT, you also mentioned a lite FAT guide.... have you found it?

 

Thanks! 

0 Kudos
Reply
3,166 Views
TomE
Specialist II

> I'd like to learn more about FAT, you also mentioned a lite FAT guide.... have you found it?

 

Where else but?

 

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

 

Tom

 

0 Kudos
Reply