AnsweredAssumed Answered

Core lockup reset when erase a flash sector in KE02

Question asked by lei yue on Sep 9, 2014
Latest reply on Sep 11, 2014 by jeremyzhou

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?

Outcomes