Skip to content
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

Add redundant storage pages #33

Open
PonomarevDA opened this issue Mar 12, 2024 · 0 comments
Open

Add redundant storage pages #33

PonomarevDA opened this issue Mar 12, 2024 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@PonomarevDA
Copy link
Owner

PonomarevDA commented Mar 12, 2024

Problem Description

When saving parameters to the persistent storage, we should initially erase the flash page and then write to it.
There is a chance to lose all the parameters if we turn off the power supply during the paramsSave() call.

Notes:

  • The single erase page takes ~20-40 ms for stm32f103

Proxy page approach

We can use proxy (temporary/intermediate) pages:

  • During the boot we can check the proxy pages. If they are not erased (not empty), let's try to restore data from them to the main page. Then erase the proxy pages.
  • During the paramsSave call we can initially save parameters to the proxy pages. It is expected that the proxy pages arealready erased before this call, so it should be fast.

The approach is simple, but it requires using erase twice for each paramsSave call.

Redundant page approach

Instead of using proxy pages, we can switch main pages after each paramsSave call.

  • During the boot we check which pages are erased and which are not. If first group is erased and second is not, let's consider second as main and first as redundant. If both of them are erased or written, let's use any group (it means that we lost the latest params, but at least can restore the previous version)
  • During the paramsSave call, we initially save to the redundant group, then erase the main group and switch main to redundant.

This approach is slightly more complex, but it is more efficient.

Notes

  • Before testing on a real device, it is better to implement it in SITL and cover with unit tests because the number of erase operations is limited
  • Usually we use 1 page for the storage, but for some tasks we need 2 or more pages.
  • For compatibility with current API, instead of changing the interface it is better to extend it. For example, this feature can be enabled only if paramsInitRedundantPage(first_idx) is called or similar.
@PonomarevDA PonomarevDA added enhancement New feature or request help wanted Extra attention is needed labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant