Hi AngelC
I could write and read the internal flash memory of my kinetis MKW01Z device, the command to write or read the memory must be executed from other section of the internal flash memory
Here I post the bare metal code for write 4bytes of internal memory, I hope it could be useful to others:
//*****************************************************************************
UINT8 FlashIntMan_WriteLongWord(UINT32 startPos,UINT32 dataToWrite)
//*****************************************************************************
// description: Writes a longword of the MCU internal flash
// HW dependanty function
// prerequisities:
// - check if the last command has been executed
// - check for errors in the last command execution
//*****************************************************************************
{
ENTER_ATOMIC();
//waiting for last command to complete,if any
while(((FTFA->FSTAT)&(1UL << 7))==0x00);
//load the code of the operation in FCCOB reg
FTFA_FCCOB0 = PROGRAM_LONGWORD;
//load the startting address
FTFA_FCCOB1 = startPos >> 16;
FTFA_FCCOB2 = startPos >> 8;
FTFA_FCCOB3 = startPos;
//loading data
FTFA_FCCOB4 = dataToWrite >> 24; //[MSB]
FTFA_FCCOB5 = dataToWrite >> 16;
FTFA_FCCOB6 = dataToWrite >> 8;
FTFA_FCCOB7 = dataToWrite; //[LSB]
//launching the command writting 1 to CCIF
FTFA_FSTAT |= FTFA_FSTAT_CCIF_MASK;
//wait for the command completion
while(((FTFA->FSTAT)&(1UL << 7))==0x00);
LEAVE_ATOMIC();
//check if address violation has ocurred
if(((FTFA->FSTAT)&(1UL << 4)) == 0x10)
{
//adress violation occurred reporting error
//clearing FPVIOL
FTFA->FSTAT |= 0x10;
CPrintf(flashViolString);
return ERROR;
}
return OK;
}