Problem with KL17 flash erase an writing

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

Problem with KL17 flash erase an writing

1,555 次查看
vinayakwadkar
Contributor I

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

}

0 项奖励
回复
3 回复数

1,383 次查看
vinayakwadkar
Contributor I

Hi,

Ignore the first comment, because clicked on post button by mistake and question got posted with incomplete information.

Please read following information for question -

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

}

static uint32_t CommandLaunch(void)

{

  /* Clear command result flags */

  FTFA_FSTAT = FTFA_FSTAT_ACCERR_MASK | FTFA_FSTAT_FPVIOL_MASK | FTFA_FSTAT_RDCOLERR_MASK;

  /* Launch Command */

  FTFA_FSTAT = FTFA_FSTAT_CCIF_MASK;

  /* wait command end */

  while(!(FTFA_FSTAT & FTFA_FSTAT_CCIF_MASK));

  /*check for errors*/

  if(FTFA_FSTAT & (FTFA_FSTAT_MGSTAT0_MASK | FTFA_FSTAT_ACCERR_MASK | FTFA_FSTAT_FPVIOL_MASK | FTFA_FSTAT_RDCOLERR_MASK)) return(RESULT_ERROR);

  /*No errors retur OK*/

  return (RESULT_OK);

}

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

* Function Name: FlashErase

* Parameters: block base address, data size

* Return:  0 - Erase Successful

*          1 - Erase Fail

* Description. Erase data Flash sector

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

U32 FlashErase(U32 block_start,

                    U32 block_size)

{

U32 size;

union

{

  U32  word;

  U8   byte[4];

} dest;

  /*Set Write command*/

  while(!(FTFA_FSTAT & FTFA_FSTAT_CCIF_MASK));

     

  for(size = 0, dest.word = (U32)block_start;

      size < block_size; size += 4, dest.word += 4) 

  {

    /*Set destination address and command*/

    FTFA_FCCOB0 = 0x09;

    FTFA_FCCOB1 = dest.byte[2];

    FTFA_FCCOB2 = dest.byte[1];

    FTFA_FCCOB3 = dest.byte[0];

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

  }

  return(RESULT_OK);

}

We called flash erase routine first, to erase 100 flash locations staring from 0x2000 and then called flash write routine to write at 100 locations staring from 0x2000.

Flash write routine returns RESULT_OK but data which to be written is not reflected in flash location staring from 0x2000.

Could you please review the above flash routines and tell us whether we are missing something or need some correction in flash routines?

We are feeling that our operation of flash write is not happening correctly because flash erase is not happened successfully.

Please provide you comments. Thanks in advance!

Thanks,

Vinayak Wadkar

0 项奖励
回复

1,383 次查看
jeremyzhou
NXP Employee
NXP Employee

Hi Vinayak,

I was wondering if you can upload the whole demo, then I can run the demo on my board and it will help me to figure the root cause of the issue.

I'm looking forward to your reply.
Have a great day,
Ping

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

0 项奖励
回复

1,383 次查看
vinayakwadkar
Contributor I

Hi,

Thanks for your reply!

I don't find "attach" feature  while replying to question, so I have opened new thread regarding same question and attached demo code with new thread.

Please find the demo code and my comments on new thread - "Cannot erase or write internal flash memory".

Please check the new thread and reply on new thread.

Thanks,

Vinayak Wadkar

0 项奖励
回复