MC56F8367 Flash Write

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

MC56F8367 Flash Write

1,013 Views
eriklawrence
Contributor I

Greetings folks,

 

I'm looking to create a write function for a MC56F8365 component (performing the tests on the MC56F8367EVME board), and based on the guide provided in the 56F8300 Peripheral User Manual, I came up with the following (I'm still working with FMCLK, but the DIVLD bit in FMCLKD has been set) :

 

uint8_t flash_write(uint32_t *addr, uint16_t *buf, uint16_t len)

{

  uint16_t *pdata = buf, plen = len;

  uint32_t *paddr = addr;

  if(FMCMD & 0x40){

  FMCMD &= 0xFFBF;

  }

  /* Check FM clock */

 

while(len--){

 

/* Check to see if the command buffer is empty; otherwise, wait. */

  while((FMUSTAT & 0x0080) == 0);

 

  /* Select the desired flash space to write to. */

  FMCR |= 0x0002;

 

  /* Write the desired data at the desired address. */

  *((uint16_t*)addr) = *buf;

 

  /* Write the program command to the FMCMD register */

  FMCMD |= 0x0020;

 

  /* Clear the CBEIF bit of FMUSTAT */

  FMUSTAT |= 0x0080;

 

  /* Check the FMUSTAT register for protection, access errors */

  if(FMUSTAT & 0x0020){ // Protection Violation Check;

       FMUSTAT |= 0x0020;

       GPIO_C_DR |= 2;

       return 1;

  }

 

  if(FMUSTAT & 0x0010){ // Access Error Check

       FMUSTAT |= 0x0010;

       GPIO_C_DR |= 4;

       return 1;

  }

 

  /* Loop back around for another write; otherwise, check CCCIF */

  addr++;

  buf++;

  }

 

  while((FMUSTAT & 0x0040) == 0);

 

  /* Verify via previous variables */

  while(plen--){

       if( *paddr++ != *pdata++ ){

            GPIO_C_DR |= 8;

            return 1;

       }

  }

  return 0;

}

 

Upon running the code (either through the debugger or the flash programmer in CW 10.6 via a PE Micro Multilink Universal), the locations I intended to write to remain blank (0xFFFF).  Any ideas?

 

NOTE: Prior to operation, the Debugger notes the flash registers set as the following:

 

FMCLKD = 0x00a0

FMCR = 0x0000

FMSECH = 0x8000

FMSECL = 0xFFFF

FMPROT = 0x0000

FMPROTB = 0x000

FMUSTAT = 0x00c0

FMCMD = 0x0020

Labels (1)
0 Kudos
3 Replies

710 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi Erik,

Firstly, as you know that the flash clock FMCLK should range between 150K to 200kHz, the Flash driving clock is 30mhz if you run the DSP56F367 in 60MHz, the FMCLKD register should be set to 0x52. Note that the  initialization code do not initialize the FMCLKD register, furthermore the FMCLKD register can only be written once after RESET.

Secondly, you should erase the page before you program the data into Flash, because the programming process can only change the flash bit from 1 to 0, it can not change flash bit from 0 to 1. erasing process will change the flash bit to all 1.

You code is used to write data flash, make sure that the address where you write data locate at flash space. If you want to write program flash, the writting flash code should be copied into program RAM and run in RAM to manipulate flash operation.

BTW, make sure that the BKSEL bits in FMCR are correct, and check the FMPROT register whether the flash is protected.

make sure that you should increment the buf and addr address for each programing .

Hope it can help you

BR

XiangJun Rong

710 Views
eriklawrence
Contributor I

Thanks for responding!

Since I wrote the original question, I've resolved issues with the FMCLK, erasing the Flash before writing, and setting protection, but I'm afraid I'm a bit new when it comes to placing functions into and running from RAM. Could you provide an example, or some explanation of how to do so?

-Erik

0 Kudos

710 Views
johnlwinters
NXP Employee
NXP Employee

An application note to address this will be published soon.

0 Kudos