Can't read FSTAT

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't read FSTAT

361 Views
oscargarciaabad
Contributor III

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.

Labels (1)
0 Kudos
4 Replies

36 Views
mjbcswitzerland
Specialist V

Hi


What if you remove the PrintfPointer() calls?

If UpdateFlash() is running from RAM and the Flash controller is busy also the printout routine needs to run from RAM - either using no interrupts or interruptr also running in RAM.

Regards

Mark

0 Kudos

36 Views
oscargarciaabad
Contributor III

Hello Mark,

I found out the problem. Processor expert generated a wrong linker script. I wanted to put a struct in flash in order to save user configuration, but the symbol was never put in flash (it didn't appeard in the map file), now I solved and everything works fine.

Thanks a lot for your help!

Regards,

Oscar.

0 Kudos

36 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Oscar,

    That is good to hear you already solved the problem.

    When using the PE, it is best to check the Build options in the CPU module, some KL SRAM address and size in the PE is not correct, this configuration will lead the wrong linker script.


Have a great day,
Jingjing

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

0 Kudos

36 Views
oscargarciaabad
Contributor III

Hi Jingjing,

Thanks for the info!

Best regards,

Oscar.

0 Kudos