Hello all,
I'm trying to save some data in the flash of my device. The device is a kinetis MKL46Z256VLL4 (I have a FRDM-KL46Z board).
I created a function to perform the erase/program sequence. This function is executed from SRAM. I did so the following way:
void __attribute__((section (".data"), long_call)) UpdateFlash(void);
I initiliaze the FTFA moule the following way:
void FTFA_Init(void)
{
/* SIM_SCGC6: FTF=1 */
SIM_SCGC6 |= SIM_SCGC6_FTF_MASK;
/* FTFA_FSTAT: CCIF=0,RDCOLERR=1,ACCERR=1,FPVIOL=1,??=0,??=0,??=0,MGSTAT0=0 */
FTFA_FSTAT = FTFA_FSTAT_RDCOLERR_MASK | FTFA_FSTAT_ACCERR_MASK | FTFA_FSTAT_FPVIOL_MASK;
/* FTFA_FPROT0: PROT=0xFF */
FTFA_FPROT0 = FTFA_FPROT0_PROT(0xFF);
/* FTFA_FPROT1: PROT=0xFF */
FTFA_FPROT1 = FTFA_FPROT1_PROT(0xFF);
/* FTFA_FPROT2: PROT=0xFF */
FTFA_FPROT2 = FTFA_FPROT2_PROT(0xFF);
/* FTFA_FPROT3: PROT=0xFF */
FTFA_FPROT3 = FTFA_FPROT3_PROT(0xFF);
/* FTFA_FCNFG: CCIE=0,RDCOLLIE=0,ERSAREQ=0,ERSSUSP=0,??=0,??=0,??=0,??=0 */
FTFA_FCNFG = 0x00U;
}
The probleam appears when I try to read the FSTAT register (inside UpdateFlash function) the following way:
void UpdateFlash(void) {
int (*PrintfPointer)(const char *, ...) = printf;
uint8_t FSTAT;
PrintfPointer("Updating user parameters in flash\n");
PrintfPointer("Waiting for previous command to complete\n");
while(!(FTFA_FSTAT & FTFA_FSTAT_CCIF_MASK));
PrintfPointer("Previous command completed\n");
FSTAT = (uint8_t) FTFA_FSTAT;
}
The FSTAT = (uint8_t) FTFA_FSTAT; statement is launching a Hard fault exception.
What is happening here?
Thanks in advance,
Oscar.