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
Thank you for the answer.
Now I'm try to execute code from ram. I will return my result probably tomorrow.
The code should act as flash sector erase, but the problem is the same as for the flash write.
Hi Alessio
FTMRE_FSTAT |= FTMRE_FSTAT_CCIF_MASK;
waitForCommandExecute();
must be executed from SRAM and not from Flash - it will immediately fail if executed in Flash since the Flash becomes unreadable while it is being erased. Also one usually protects the call from interrupts since an interrupt will usually cause Flash to be accessed and so a failure too.
To save time, this is available in the uTasker KEA project, which is available as open source at
http://www.utasker.com/forum/index.php?topic=1721.msg7086#msg7086
Its flash driver is compatible with all Flash and EEPROM in KE, KEA, KL, K etc. parts and includes Flash emulation to identify issues before they get to the HW (with fail-safe parameter system in Flash/EEPROM emulation).
Regards
Mark
Professional support for Kinetis: http://www.utasker.com/index.html
Remote desktop one-on-one coaching: http://www.utasker.com/services.html
Getting started to expert videos: https://www.youtube.com/results?search_query=utasker+shorts
Hi.
I try to execute the code from FLASH but with interrupt disabled and the code is running well.
Tomorrow I try a long test.
Thanks a lot