This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

fs_erase and fs_store sequence

I'm trying to use fstorage module for event logging; several pages are used as a large circular buffer. When logging wraps from one page to another, the new page needs to be erased before the next piece of data can be logged. So I need a means to defer writing while waiting for erase to complete.

One possibility is to simply call fs_erase() and then fs_store(), assuming that fstorage queues and executes operations in order. Not sure what happens to the fs_store operation though if the erase fails.

Another possibility is to have my own write queue, calling fs_store() from the fs_evt_handler() 'erase done' callback. Is that permitted? I've seen comments that the libraries are not reentrant or thread-safe.

Or should I use the app_scheduler library? The library seems to be limited to BLE and app_timer callbacks. Can it be used for fstorage callbacks as well?

Any other suggestions?

Using SDK13.1, SD132

TIA, Richard

  • The operations are executed in the same order they are queued. If you are able to determine that a new log entry would wrap around then you could queue an erase operation before the store operation. The erase shouldn't fail unless you have high BLE activity, but there is the possibility to have fstorage automically retry any operation that times out by tweaking the MAX_RETRIES macro (don't remember the exact name).

Related