K32W041 - Failing FLASH write using Flash_Program()

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

K32W041 - Failing FLASH write using Flash_Program()

2,406 Views
Emiel1984
Contributor II

For our project we would like to write multiple 'data records' into flash memory.
Each record  contains 100 bytes.

From my understanding we need to write in blocks of 32 bytes.
Therefore we increased the amount of bytes 'written' to 128 (4 * 32).
We still request the function 'Flash_Program()' to write 100 bytes but increase the write 'pointer' location by 128 bytes after each write.

As required we first erase the flash page ( flash location used to start: 0x59000) .
Then we request to write 100 bytes to be written into it.
The first request is verified successfull. We did read the 100 bytes back that we did write into it.
The pointer is then increased by 128 (4*32 bytes). (0x59080)

Then we request to write another 100 bytes into flash.
But is fails every time. Every single time the same 4 bytes are not read back as the value we requested to be written into it.
All other 96 bytes are written in correctly.

Emiel1984_2-1659793456899.png

 


Code is attached with this ticket.
I have used the SDK example "k32w061dk6_flash_demo"  as a base.

 

Installed:

Emiel1984_1-1659793243256.png

 

0 Kudos
7 Replies

2,359 Views
EduardoZamora
NXP TechSupport
NXP TechSupport

Hello Emiel,

By any chance, are you planning to use any of the connectivity features stack (BLE, Zigbee, Thread) together with the Flash driver?

Regards,
Eduardo.

0 Kudos

2,356 Views
Emiel1984
Contributor II

Im already using the radio communication (802.15.4).

But we want to store other data we collected.

 

Why this question ?

0 Kudos

2,289 Views
EduardoZamora
NXP TechSupport
NXP TechSupport

Hi,

Truly apologize for my late response.

Please, consider doing a FLASH_ErasePages() or FLASH_Erase() before each Flash program operation/iteration.

Also, please be aware that the connectivity stack and its data use some space in Flash memory, so you need to be careful about which memory locations you are writing to.

If you need to handle the storage of stack context data and application data in Non-Volatile Memory, please take a look at the Core Utility User Guide (K32W0x SDK folder > docs > wireless > Zigbee > JN-UG-3133), Chapter 2: Persistent Data Manager (PDM), this information may be helpful.

Regards,
Eduardo.

0 Kudos

2,396 Views
KalaimaniArumugamdev
Contributor III

Hi,

    Based on the code point of your erase operations done

if (FlashBufferHead % 512 == 0)

Above condition try @initial time FlashBufferHead is zero and it work fine after the first iteration it's become 128.it will not erase the next block of flash because you taking sector size as 128 byte.so that you facing fail state.

 And confirm that your buffer data and first write operation data as same.

Form the code:

 uint32_t buffer[30];

 uint8_t *data=&buffer[0];

 data pointer location is same as buffer[0] and buffer array size is 30, and buffer array hold 120 bytes of memory. Ensure your data array update correct or not

 

0 Kudos

2,388 Views
Emiel1984
Contributor II

Maybe I'm misunderstanding your input but this specific line only ensures that I erase every page before I start writing into it.  0x59000 \ 512 ==  flash page 712  (712* 512 == flash address location 0x59000) .

if (FlashBufferHead % 512 == 0)

My 'record buffer' starts at the beginning of a page but is multiple pages in size.
I do not want to write the records for an entire page at once because this means I need to buffer them elsewhere untill I have enough to fit.
I want to avoid creating another buffer to store records into before writing them into flash.
From my understanding the only requirement for writing bytes into flash is that we need to write at least 32 bytes at a time.
And for reading we need to read at least 16 bytes at a time.

We can't only erase a page during initialisation. We need to be able to erase\overwrite older records over time.


In my code I request to write 100 bytes at a time.
So what I expect that happens is ( confirmed this in debug

--run0
Flash page 0x59000 is erased  (because FlashBufferHead point to the beginning of a page).
100 bytes in written.  0x59000
FlashBufferHead  gets value 128.

--run1 
100 bytes in written.  0x59080
But here we get the issue that when I read the values back from flash.
These are different as mentioned in the topic start. We did already erase this part of the flash during run 0.

FlashBufferHead gets value 256.

--run2
100 bytes in written.  0x59100
FlashBufferHead gets value 384.

--run3
100 bytes in written.  0x59180
FlashBufferHead gets value 512..

--run4
Flash page 0x59200 is erased  (because FlashBufferHead locates to the next page)
100 bytes in written.  0x59200
FlashBufferHead gets value 640..

0 Kudos

2,361 Views
KalaimaniArumugamdev
Contributor III

Hi @Emiel1984 ,

   Sorry for the late reply, Please refer below link for Flash Program API

https://mcuxpresso.nxp.com/api_doc/dev/1578/group__flash__driver.html 

In code :change the code from

driver_result = FLASH_Program(FLASH, pu32Start , (uint32_t*)inp, 100);

 To

driver_result = FLASH_Program(FLASH, pu32Start, (uint8_t*)inp, 100);

Also verify the inp data.

0 Kudos

2,405 Views
Emiel1984
Contributor II

As a test I changed the start address to 0x59080.
Then the same behaviour applies.
The first 100 bytes are written in correctly.. the next run  the same bytes (as in the screenshot above)are again wrong.
Looks like the exact same values are written, because these 'wrong' values\bytes are exactly the same (but now on a location 128\0x80 bytes later in the flash page).
At (index==value) 35== 3, 51==59, 70 =102, 86==94)

0 Kudos