Core lockup reset when erase a flash sector in KE02

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

Core lockup reset when erase a flash sector in KE02

967 Views
raysss
Contributor I

When I try to erase a flash sector in MKE02Z64VLD4,the core lockup reset is occured(the LOCKUP bit in SIM->SRSID is set).

the FTMRH registers config as:

FTMRH->FCLKDIV = 0x0f;//15.6~16.6MHz
FTMRH->FCNFG = 0x00;
FTMRH->FERCNFG = 0x00;

and the following functions for erasing a flash sector:

bool FlashPreCheck(void)

{

  if((FTMRH->FCLKDIV & FTMRH_FCLKDIV_FDIV_MASK) != 0x0f){

  if((FTMRH->FCLKDIV & FTMRH_FCLKDIV_FDIVLCK_MASK) != 0){

  NVIC_SystemReset();

  }

  else{

  if((FTMRH->FSTAT & FTMRH_FSTAT_CCIF_MASK) != 0){

  FTMRH->FCLKDIV = 0x0f;

  }

  }

  return FALSE;

  }

  if((FTMRH->FSTAT & FTMRH_FSTAT_CCIF_MASK) == 0){

  return FALSE;

  }

  if((FTMRH->FSTAT & FTMRH_FSTAT_ACCERR_MASK) != 0){

  FTMRH->FSTAT |= FTMRH_FSTAT_ACCERR_MASK;

  }

  if((FTMRH->FSTAT & FTMRH_FSTAT_FPVIOL_MASK) != 0){

  FTMRH->FSTAT |= FTMRH_FSTAT_FPVIOL_MASK;

  }

  __disable_irq();

  WDOG->CNT = 0x02A6;

  WDOG->CNT = 0x80B4;

  __enable_irq();

  return TRUE;

}

bool FlashEraseSector(u32 addr)

{

  u32 saddr;

  if(!FlashPreCheck())return FALSE;

  saddr = addr;

  __disable_irq();

  FTMRH->FCCOBIX = 0;

  FTMRH->FCCOBHI = 0x0a;

  FTMRH->FCCOBLO = (u8)(saddr >> 16);

  FTMRH->FCCOBIX = 1;

  FTMRH->FCCOBHI = (u8)(saddr >> 8);

  FTMRH->FCCOBLO = (u8)(saddr >> 0);

  FTMRH->FSTAT |= FTMRH_FSTAT_CCIF_MASK;

  while((FTMRH->FSTAT & FTMRH_FSTAT_CCIF_MASK) == 0);

  __enable_irq();

  if((FTMRH->FSTAT & FTMRH_FSTAT_MGSTAT_MASK) != 0)return FALSE;

  return TRUE;

}

Is anyone can help me?

Labels (1)
0 Kudos
1 Reply

434 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Lei yue,

I'd like to suggest that you could refer to the Flash demo from the sample code of the FRDMKE02Z board at first.

In the Flash demo, there're a lot of flash operation functions, so please refer to it for details and download the sample code through the link as below.

If you have any other questions, please feel free to contact with me.

The link of the sample code:

cache.freescale.com/files/32bit/software/KE02-SC.zip
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos