AnsweredAssumed Answered

Problem with KL17 flash erase an writing

Question asked by Vinayak Wadkar on May 10, 2016
Latest reply on May 11, 2016 by Vinayak Wadkar

Hi,

 

We want to store some constant data in KL17 flash.

To store constant data we made use of  flash routines provided by IAR system(which we got from following location after installing IAR) -

C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.4\arm\src\flashloader\NXP\FlashKLXX

 

To write data in flash we use following routine -

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

* Function Name: FlashWrite

* Parameters: block base address, data size, ram buffer

*             pointer

* Return:  0 - Write Successful

*          1 - Write Fail

* Description. Writes data to Flash

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

uint32_t FlashWrite(void *block_start,

                     uint32_t count,

                    char const *buffer)

{

uint32_t size;

 

 

union

{

  uint32_t  word;

  uint8_t   byte[4];

} dest;

 

 

  /*Set Write command*/

  while(!(FTFA_FSTAT & FTFA_FSTAT_CCIF_MASK));

 

 

  for(size = 0, dest.word = (uint32_t)block_start + offset_into_block;

      size < count; size += 4, dest.word += 4, buffer += 4)

  {

 

    /*Set destination address and command*/

    FTFA_FCCOB0 = 0x06;

    FTFA_FCCOB1 = dest.byte[2];

    FTFA_FCCOB2 = dest.byte[1];

    FTFA_FCCOB3 = dest.byte[0];

    /*copy data*/

    FTFA_FCCOB4 = buffer[3]; /* +0 */

    FTFA_FCCOB5 = buffer[2]; /* +1 */

    FTFA_FCCOB6 = buffer[1]; /* +2 */

    FTFA_FCCOB7 = buffer[0]; /* +3 */

 

 

    if(RESULT_ERROR == CommandLaunch()) return RESULT_ERROR;

  }

  return(RESULT_OK);

}

Outcomes