AnsweredAssumed Answered

Hi: Can anyone tell me where I'm wrong in write internal flash application?

Question asked by Alessio De Marchi on Feb 21, 2017
Latest reply on Feb 21, 2017 by Alessio De Marchi

Hi everybody.

 

I'm try to use the last sector of flash (S9KEAZN8 micro) as a simple eeprom (I have to save some trimming value for my application). I use IAR WorkBench as development tool.

This is the code:

void waitForCommandExecute()
{
unsigned char statVal;

 

  do {
    statVal = FTMRE_FSTAT;
    statVal &= FTMRE_FSTAT_CCIF_MASK;
  } while (statVal == 0);
}

 

....

/* The next row is where the program stop working */

  if ((FTMRE_FCLKDIV & FTMRE_FCLKDIV_FDIVLD_MASK) != FTMRE_FCLKDIV_FDIVLD_MASK)
  {
    waitForCommandExecute();
    FTMRE_FCLKDIV = ((configBUS_CLOCK_HZ / 1000 + 399U) / 1000U - 1U);
    FTMRE_FCLKDIV |= FTMRE_FCLKDIV_FDIVLCK_MASK;
  }

 

  if ((FTMRE_FSTAT & FTMRE_FSTAT_ACCERR_MASK) != 0)
    FTMRE_FSTAT |= FTMRE_FSTAT_ACCERR_MASK;
  if ((FTMRE_FSTAT & FTMRE_FSTAT_FPVIOL_MASK) != 0)
    FTMRE_FSTAT |= FTMRE_FSTAT_FPVIOL_MASK;

 

      // EEPROM/Flash erase
      FTMRE_FCCOBIX = 0x00;
      FTMRE_FCCOBHI = 0x0a; // sector Erase
      FTMRE_FCCOBLO = 0x00;
      FTMRE_FCCOBIX = 0x01;
      FTMRE_FCCOBHI = (u8_t)(BASE_FLASH_EEPROMADDRESS >> 8);
      FTMRE_FCCOBLO = (u8_t)(BASE_FLASH_EEPROMADDRESS & 0xff);

 

      FTMRE_FSTAT |= FTMRE_FSTAT_CCIF_MASK;
      waitForCommandExecute();

....

But when I execute the code step by step the Ide freeze with a message program of flash ...

I don't know what happens. Can anyone help me?

Thanks

Outcomes