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

fstorage - multiple instance with softdevice ?

I have a use case where multiple instances of a fstorage is created, all with the nrf_fstorage_sd API. I also use the peer_manager and hence fds which in turn uses fstorage again with nrf_fstorage_sd api.

However what I've found is that you can only call the following once nrf_fstorage_init(&m_flashHandle, &nrf_fstorage_sd, nullptr); subsequent calls succeed without an error, but their p_flash_info field is not initialised and that causes a segfault when calling any of the fstorage APIs.

The issue seems to be in the following code in nrf_fstorage_sd.c

static ret_code_t init(nrf_fstorage_t * p_fs, void * p_param)
{
   ...

    if (!nrf_atomic_flag_set_fetch(&m_flags.initialized))
    {
        p_fs->p_flash_info = &m_flash_info;

        ...

So long story short; is this a bug in the nrf_fstorage_sd code ? or is creating multiple instances / handles to fstorage not allowed ? FWIW moving the p_flash_info assignment to outside the initialization if block appears to solved the problem for me, but maybe I'm missing something.

Apologies if this is documented somewhere, I've scanned through the docs but couldn't see anything.

Thanks in advance.

Related