I am using a Flash Winbond w25q32bv with my ATXMEGA256A3BU. The flash memory is working fine, I can write and read data without any issue. So my question is not code related, it's a about the memory usage of my XMEGA.
Some background: The flash memory is divided in 16384 pages of 256 bytes each. The thing is that these pages can be written only if they were previously erased. Quote from the datasheet: "The page program instruction allow from one byte to 256 bytes (a page) of data to be programmed at previously erased (FFh) memory locations"
But I can only erased pages in groups of 16, it's not possible to erased pages one by one.
So, what I am actually doing every time I need to write a single page that is already written is doing a backup on my XMEGA of 16 pages. Erasing those 16 pages on the flash memory, putting the 15 pages I want to keep again in the flash and finally write the new data in the page I wanted to write. It was a bit hard to code this, but I did it and it's working. The thing is that to do this I use 256 bytes * 16 = 4 KB of memory of my XMEGA. This is not a problem when the rest of my program is simple and small, but I facing some issues of memory usage on more complex programs.
Do you have any idea on how can I reduce the memory usage? Maybe there is another way to implement the flash memory.
I know that my question is a bit tricky and confusing, so please if you need more information or further clarification please let me know.