Using Flash Commands resets the MKW01Z128

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Using Flash Commands resets the MKW01Z128

1,603 次查看
joseplluismoral
Contributor II

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!

0 项奖励
回复
5 回复数

1,345 次查看
joseplluismoral
Contributor II

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;

}

0 项奖励
回复

1,345 次查看
fabricetocci
Contributor III

Hi Josep,

First of all, thank you for having shared your code. It could be a starting point for me.

I have to develop a fllash programming SW for MKW01 and it seems that you already did it.

I would like to give to customers the capability to reflash their products without having to jump on their premisses!!!

Will it be possible for you to share more code with me? This will same me a bunch of time.

Can you please explain the purpose of ENTER_ATOMIC() and LEAVE_ATOMIC() functions??

I hope, you'll consider my requuest.

Best regards.

Fabrice.

0 项奖励
回复

1,345 次查看
joseplluismoral
Contributor II

Consulting the RCM SRS1, it indicates that the event is caused by a core lock-up...

Which situation using the flash commands can trigger that???

0 项奖励
回复

1,345 次查看
AngelC
Senior Contributor I

Hello Josep,

Could you please describe the project you are using specifically? It seems not to be any of our software solutions officially supported for KW0x. If that is the case, I am afraid we could not help you with any custom implementation. Anyway, a detailed description of how you are creating such project or where did you get it would give us a better context.

Regards,

AngelC

0 项奖励
回复

1,345 次查看
joseplluismoral
Contributor II

Im using:

- KDS 3.0, without processor expert

- P&EMicro programmer & debugger

0 项奖励
回复