K-70: Write to flash.

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

K-70: Write to flash.

跳至解决方案
1,332 次查看
john71
Senior Contributor I

The write operation is:

FlashProgram(&flashSSDConfig, dest, size, buffer, FlashCommandSequence);

I assume the "size" argument is the size of the "buffer".

But if we look into the function we see:

/* update size for next iteration */
   size -= PGM_SIZE_BYTE;

So should I write only multiple 8 chunks? What should I do if my data 11 bytes?

0 项奖励
回复
1 解答
1,187 次查看
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Evgeny Erenburg,

From your code I guess you are using the C90TFS Standard Software Driver.

The K70 uses phrase programming (8 bytes), so yes, the size of your data should be a multiple of 8 bytes, otherwise the driver will return a FTFx_ERR_SIZE error. In your case if your data is 11-bytes long, then you can send as parameter a 16-bytes buffer with 5 padding bytes (e.g. FFs).

I hope this helps.


Best Regards!,
Jorge Gonzalez

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

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,187 次查看
john71
Senior Contributor I

I'm trying to write a structure to FLASH.

The structure:

typedef struct TEST_S

{

    unsigned int start;

    unsigned int length;

    unsigned int text_addr;

    unsigned int padding;

}TEST;

TEST test;

Initialization:

uint32_t struct_size = sizeof(TEST);  //16 bytes

test.start = 0xDADA;

 test.length = total_len;     

 test.text_addr = 0;

 tests[test_idx].padding = 0;

Write operation:

uint32_t FLASH_PageProgram(uint32_t page_num, uint32_t addr, uint8_t *buffer, uint32_t size)

{

      uint32_t dest;

      DisableInterrupts;

      dest = flashSSDConfig.PFlashBlockBase + BYTE2WORD(page_num*FTFx_PSECTOR_SIZE) + addr;

      ret = FlashProgram(&flashSSDConfig, dest, size, buffer, FlashCommandSequence);

      EnableInterrupts;

      return ret;

}

Usage:

flash_addr = 0; //from the start of the page -> 0x000FA000, USER_PAGE = 250

ret = FLASH_PageProgram(USER_PAGE, flash_addr, (uint8_t*) &test, struct_size );

if (ret)

    return ret;

I get an error (ret = 1) - Protection violation is set in FSTAT register. In the debugger I see first 8 bytes it writes ok. On second 8 bytes the error is generated.

0 项奖励
回复
1,187 次查看
john71
Senior Contributor I

I found the problem. I should erase the page. Or track the current available address.

0 项奖励
回复
1,188 次查看
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Evgeny Erenburg,

From your code I guess you are using the C90TFS Standard Software Driver.

The K70 uses phrase programming (8 bytes), so yes, the size of your data should be a multiple of 8 bytes, otherwise the driver will return a FTFx_ERR_SIZE error. In your case if your data is 11-bytes long, then you can send as parameter a 16-bytes buffer with 5 padding bytes (e.g. FFs).

I hope this helps.


Best Regards!,
Jorge Gonzalez

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

0 项奖励
回复
1,187 次查看
john71
Senior Contributor I

I see. Thank you.

0 项奖励
回复