AnsweredAssumed Answered

Using Flash Commands resets the MKW01Z128

Question asked by JOSEP LLUIS MORALES on Jun 3, 2015
Latest reply on Jan 27, 2016 by Fabrice TOCCI

Hi!

 

Im trying to use the "Program longword command" 0x06 to program in flash 4 bytes but when I clear de CCIF bit to execute the command, the debug goes to startup code "startup_MKW01Z4.s"  function Reset_Handler, Do you have any idea Why this is ocurring? im not using any interrupts to determine if the command has been executed.

 

Here is the code using the command:

//*****************************************************************************

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();

 

  //validar el rango de los argumentos

  //if(FlashInt_CheckData)

 

  //load the code of the operation in FCCOB reg

  FTFA_FCCOB0 = PROGRAM_LONGWORD;

 

  //load the startting address

  FTFA_FCCOB1 = (UINT8)((startPos & 0x00FF0000)>>16);

  FTFA_FCCOB2 = (UINT8)((startPos & 0x0000FF00)>>8);

  FTFA_FCCOB3 = (UINT8)((startPos & 0x000000FF));

 

  //loading data

  FTFA_FCCOB4 = (UINT8)((dataToWrite & 0xFF000000)>>24);

  FTFA_FCCOB5 = (UINT8)((dataToWrite & 0x00FF0000)>>16);

  FTFA_FCCOB6 = (UINT8)((dataToWrite & 0x0000FF00)>>8);

  FTFA_FCCOB7 = (UINT8)((dataToWrite & 0x000000FF));

 

  //launching the command writting 1 to CCIF

  FTFA_FSTAT |= FTFA_FSTAT_CCIF_MASK;

 

  //wait for the command completion

  while(FTFA_FSTAT & FTFA_FSTAT_CCIF_MASK == 0);

 

  LEAVE_ATOMIC();

 

  return OK;

}

 

Could be a problem of the bus speed? Im using BLPI mode:

//in BLPI

//MCGCLKOUT = 4Mhz

//FLASH clk <= 800Khz

//bus clock <= 800Khz

 

Could be a problem of trying to write a protected section of internal flash ?

 

Thanks in advance!

Outcomes