Home > Net >  Writing small chunks of data to flash memory page
Writing small chunks of data to flash memory page

Time:11-05

I have an application where I must save chunks of data to flash memory. The flash memory used: https://datasheet.datasheetarchive.com/originals/dk/DKDS-24/460477.pdf

In the datasheet, it is mentioned that I cannot write to the page that has already been written ( even if it is half empty). I would like some advice regarding what is the best way to manage the writes to the memory?

  • I am writing chunks of 25 bytes.
  • Total page size is 256 Bytes
  • Total amount of pages 16,384
  • Smallest erase sector : 4KB (16 Pages)

My questions:

  1. The only way I can think of to manage the memory, is to have a 4KB buffer and everytime I want to write some data, read the last 16 pages of data and save it in the buffer. Then I CAN erase the sector and rewrite the previous data as well as a new chunk. Is this the most common practise? Are there any other better methods available?

The only other way I can think of is to simply write 1 chunk of data per page which sounds like a complete waste of memory. But considering that I have 16384 pages available, saving 16384 chunks of data might be more than enough for my application.

  1. Is it normal practise to use some asci character to signal the end of the chunk? For example using Decimal 13 (carriage return) as a seperator:

PAGE

[CHUNK1] 13 [CHUNK2] 13 [CHUNK3] ........

END OF PAGE

Appreciate all the help.

CodePudding user response:

According to chapter 8.2.13 you can write to previously unwritten bytes. So you don't read the target page to be able to write few bytes. Just use the correct address and write the chunk.

If you have a fixed size of chunks, you don't need a separator, specifically if the contents of each chunk is binary. ASCII separators are solutions for stream-like data. This will give you 10 chunks per page.

Just in case that you want to use all space, you can write a function that knows how to split a chunk to write it in two adjacent pages. Think of some kind of HAL, hardware abstraction layer.

  • Related