-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EEPROM library on logging principle (from STM32) #254
Comments
If i remember correctly, the page-swap algorithm of the LGT8 is implemented in hardware. Though, you can implement a write-buffer and use the serial-write functions to write it all at once using |
I have read the documentation. Indeed, on LGT8F328p, the emulation of EEPROM uses a technic of page swapping at the hardware level. This mode is enabled in the ECCR register. The emulation mode is called E2PROM. |
I don't remember if it is possible to write directly to the flash once outside the bootloader :-/ Also, I have not read the STM32 pdf you provided yet, because I don't understand the benefit of storing a log in RAM given the fact that the LGT8 only has 2kB of RAM :
What are the minimal requirements of this algorithm ? |
PS : it is possible to write to the flash without triggering the swap using the SWM functions and macros (SWM = Serial Write Mode). |
PS2 : also note that the hardware swap is not triggered if you write to a cell that contains |
The algorithm from STM does not use RAM. It creates a log directly in Flash memory, appending it to the same Flash page without rewriting. And only when the log fills one page, the algorithm rewrites the data to another page, but not all, only the last actual values. To understand the meaning, you still need to read the document. The point of this is that the number of Flash page rewrites is reduced by a factor of thousands. However, there is a drawback - this algorithm is effective only when a relatively small amount of settings is stored in the emulated EEPROM, much less than the full size of the emulated EEPROM. However, that is what usually happens. |
Maybe you could try implementing it ? The SWM functions and macro I mentioned would allow you to write the log into blank pages without triggering hardware page swaps. Given the fact that the cells of the flash are 32bits wide, they are large enough to store a tiny struct containing a value, an address and a flag for each log entry (if this is the approach you choose). Also, keep in mind that the last 4 bytes of each 1k pages are reserved to the hardware page-swap algorithm. |
Porting itself will not be difficult if it is feasible in principle. And whether it is feasible or not depends on one fact: whether or not the LGT8F328 has the ability to directly access Flash memory pages, including arbitrary writing and erasing. There is definitely such an opportunity in the bootloader, the question is whether we can do this from the user program. If so, then the sequence of actions could be as follows:
The main thing, going back to the beginning, is the question whether direct access to Flash memory possible from a user program. |
Basically But LGT8Fx capable read the FLASH like RAM from address 0x4000. The complier can't produce an optimal code when acessing this address range. |
This PR may be relevant in this discussion: #261 |
Hello dbuezas!
On LGT8F328p, EEPROM is emulated using space from the main Flash memory. The emulation uses a technic of page swapping: each time we write to the emulated EEPROM, the device erases the new page, copies the old data from the old page and updates the new data on the fly on the new page, then it swaps the old and new page.
The STM32 also does not have an EEPROM and is also emulated using the main Flash memory space. However, it uses a much more economical logging principle in terms of the number of page erasures.
The principle is described in the document http://www.st.com/web/en/resource/technical/document/application_note/CD00165693.pdf.
In short: all changes are written to the log, and only when the log takes up a full page (1KB), the compressed log
is copied to the second page (only the latest actual values are copied).
The actual library code is here:
https://github.com/rogerclarkmelbourne/Arduino_STM32/tree/master/STM32F1/libraries/EEPROM
It would be nice if this principle was also ported to LGT8F328p (perhaps as a second version of the EEPROM library).
This will greatly reduce the number of Flash memory overwrites, which is already limited. In addition, such porting does not look too complicated.
What do you think about this? Do you want to try this task?
The text was updated successfully, but these errors were encountered: