Flash Programming in Coldfire v1

cancel
Showing results for 
Search instead for 
Did you mean: 

Flash Programming in Coldfire v1

Jump to solution
996 Views
gerardodiez
Contributor II

Hi guys,

 

I´ve read the Flash Programmimg routines for the HCS08 and the Coldfire V1 devices AN3942. I´ve searched the Doonstack files which uses a programming API written in asm and I am trying to translate them into C language.

 

Has anyone this task done?

 

Best regards,

Labels (1)
1 Solution
455 Views
kef
Specialist I

It is not clear, what derivative are you using? MCF51QE has 1024bytes sectors, MCF51AC256 - 2048 bytes sectors. See p.4.4.1 in corresponding reference manual.

Yes, I used that code on MCF51QE128.

View solution in original post

0 Kudos
12 Replies
455 Views
gerardodiez
Contributor II

Hi to all,

I am trying to use the code you have sent me but it doesn´t work properly. its behaivour is caotic. It erases 2 pages instead of 1 page. Does anyone get this problems too??

0 Kudos
455 Views
kef
Specialist I

Most likely you have wrong data or misinterpret what datasheets say about page size on your device. Code above can't erase more than one page in the same call.

0 Kudos
455 Views
gerardodiez
Contributor II

Hi edward,

I dont know what I am doing wrong. I made a test writting all my section of flash with some data and I execute the erase call once and I realized this bad behaivour. It erases 2KB. So this code is correct? It is tested?

0 Kudos
456 Views
kef
Specialist I

It is not clear, what derivative are you using? MCF51QE has 1024bytes sectors, MCF51AC256 - 2048 bytes sectors. See p.4.4.1 in corresponding reference manual.

Yes, I used that code on MCF51QE128.

0 Kudos
455 Views
gerardodiez
Contributor II

I am developing my application with the MCF51AC256 microcontroller but the reference manual says the following in the chapter 4.

4.4.1 Features

Features of the flash memory include:

• Flash size

— MCF51AC256: 262,144 bytes (256 sectors of 1024 bytes each).

So must I find the correct libraries? Where can i find them?

Thanks for the useful help.

0 Kudos
455 Views
kef
Specialist I

Rev 5 and latest Rev 6 MCF51AC256RM.pdf say this

4.4.1 Features


Features of the flash memory include:


• Flash size


— MCF51AC256: 262,144 bytes (128 sectors of 2048 bytes each)

— MCF51AC128: 131,072 bytes (64 sectors of 2048 bytes each)

0 Kudos
455 Views
gerardodiez
Contributor II

Thanks Edward you are so helpful. I was looking preliminary RM. I´ve downloaded this RM and I realized one thing I dont understand completly.

You are right and in:

4.4.1 Features

— MCF51AC256: 262,144 bytes (128 sectors of 2048 bytes each)


But In 4.4.4.4 Sector Erase Command:

The sector erase operation will erase all addresses in a 1 KB sector of flash memory using an embedded

algorithm.

So can I erase one 1KB or 2KB with this micro? Where do you find the code to your micro? Where can i find for the mine.

0 Kudos
455 Views
kef
Specialist I

For any inconsistences you may found in documention, you should make sarvice request.

I coded attached routine myself. It is identical for QE, AC, and other existing CF V1 families. If it erases 2kB on AC, then AC sectors must be 2kB. QE has 1kB flash sectors. You can ask support any questions, including this one, just make service request here:

https://www.freescale.com/webapp/servicerequest.create_SR.framework

455 Views
sebasira
Senior Contributor I

Hi! Some time ago I've started a thread related to Flash Erasing and Programming on CFv1... Maybe it usefull to you. There you'll find some attached files.

I didn't take a look at what kef post here, maybe there are the same files. If not, you will have 2 options.

SebaS

455 Views
kef
Specialist I

I attached minimalistic flash routines that work for me on MCF51QE. You need to use ANSI C startup to make PGM[] properly initialized at start up. Also you need to initialize flash clock divider. Hope it works. Usage:

FlashSectorErase( (void*)longword_aligned_sector_address );

FlashProgramLong( (void*)longword_aligned_sector_address, 0x55aa55aa );

455 Views
gerardodiez
Contributor II

Hi Edward,

First of all I would like to apreciate your fast answer. I think the piece of code you have sent me, can be useful but it gives me a compiling error.

#include "derivative.h"

#define FSTATADR 0xFFFF9825

static volatile unsigned short PGM[]  = {

   0x117C,0x0080,0x9825,    //  MOVE.B   #0x80, FSTATADR(A0)

                                          //  fpgmex1:

   0x0828,0x0006,0x9825,    //  BTST     #6, FSTATADR(A0)

   0x67F8,                          //  BEQ.B    fpgmex1

   0x4E75                          //  RTS

};

char FlashSectorErase(void *sector) {   

(void)page;

   FSTAT = 0x30;

   *(long*)sector = 0; // write any data to long word aligned address

   FCMD = 0x40;

   asm {   

      LEA      (0), A0

      JSR      PGM

   }   

   return (char)(FSTAT & 0x30);

}

the label page is not defined. Where must it be defined??

0 Kudos
455 Views
kef
Specialist I

gerardodiez,

sorry, just delete that line. At some point I renamed page argument to sector. In older version write zero operation was done in assembly, thus there was a (void)page; to stop compiler emitting warning about unused function argument. I don't know how I forgot to compile after last edit...

0 Kudos