Flash writing MCF522559

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

Flash writing MCF522559

1,132 Views
adelvallem
Contributor II

Hi everyone I'm developing a code to write data into the flash memory.

I'm using the codewarrior 11.1 & coldfire v2 MCF52259

Reading the RM I found the next

"Before starting a command write sequence, the ACCERR and PVIOL flags in the CFMUSTAT register must be clear and the CBEIF flag should be tested to determine the state of the address, data, and command buffers. If the CBEIF flag is set, indicating the buffers are empty, a new command write sequence can be executed.
A command write sequence consists of three steps that must be strictly adhered to, because writes to  the CFM are not permitted between steps. However, flash register and array reads are allowed during a command write sequence. The basic command write sequence is as follows:
1. Write to one or more addresses in the flash memory.
2. Write a valid command to the CFMCMD register.
3. Clear CBEIF flag by writing a 1 to CBEIF to launch the command.
When the CBEIF flag is cleared, the CCIF flag is cleared on the same bus cycle by the flash command
controller indicating that the command was successfully launched.
"

Base on this steps I developed the next function:

 

#define FLASH_PROGRAM_ADDR(x) \
  (*(volatile unsigned long *)(void *)(&__IPSBAR[(0x04000000 + (x))]))

unsigned char Write_Flash(uint32 *mainPtr, uint32 data)
{
  vuint8 status;
  MCF_CFM_CFMUSTAT |= ACCERR;                 // clean a possible access error flag
  MCF_CFM_CFMUSTAT |= PVIOL;                  // clean a possible violation access flag
  while ((MCF_CFM_CFMUSTAT & CBEIF) != CBEIF) {;} // ready for another command
  FLASH_PROGRAM_ADDR(*mainPtr) = data;         // write to an address (?)
  MCF_CFM_CFMCMD = WRITE_WORD;                 // write command
  MCF_CFM_CFMUSTAT |= CBEIF;                   // launch command
  
  while ((MCF_CFM_CFMUSTAT & CCIF) != CCIF) {;}
  status = MCF_CFM_CFMUSTAT;
  return  (status);
}

 

 

I got the FLASH_PROGRAM_ADDR(x) from an example and I think it makes sense since the RM says:

"Flash accesses (reads/writes) by a bus master other than the core (e.g. DMA controller), or writes to flash by the core during programming must use the backdoor flash address of IPSBAR plus an offset of 0x0400_0000."

Running the programm the flash data doesn't change, at least  I can't see the change in debugger.

Does anyone notice where I might be getting it wrong?

if it matters the chosen address  is 0x00009000

Thank you in advance.

0 Kudos
Reply
1 Reply

1,093 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

First of all, sorry for the later reply.

I would like to recommend customer to refer [MCF5225x_SAMPLE_CODE ], which provides CFM project about how to erase/program MCF52259 internal Flash.

There need to copy and run related Flash operation code at RAM during Flash operation, when code run in Flash. Customer could check <cfm.c> file for the detailed info.

Wish it helps.

best regards,

Mike

0 Kudos
Reply