K-70: Write to flash.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K-70: Write to flash.

Jump to solution
921 Views
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 Kudos
Reply
1 Solution
776 Views
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!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
Reply
4 Replies
776 Views
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 Kudos
Reply
776 Views
john71
Senior Contributor I

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

0 Kudos
Reply
777 Views
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 Kudos
Reply
776 Views
john71
Senior Contributor I

I see. Thank you.

0 Kudos
Reply