fs_write freezes app for 100+ ms

Hi,
    On nRF52840, on example https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/subsys/mgmt/mcumgr/smp_svr bluetooth stack configurations

    I am calling fs_write( less than 512bytes) and I have the main thread frozen for ~130ms.

    I tried calling fs_write from a different thread and I have now the main thread frozen for ~90ms:



   Please kindly advise, you know of an asynchronous flash write function? Or is other way to write the thread so that fs_write() will not cause freeze in other threads?

   





  The curious thing is that only part of fs_write call is blocking: may you know if the low level function code is public? If yes, where can be found for board nRF52840?


Kind Regards,
Iulian

MSc.MEd. Software Engineer and Trainer
"But God demonstrates His own love for us in this: While we were still sinners, Christ died for us." (Romans 5:8)

  • Hi,

    For background on persistent storage, see  Persistent storage of keys and data using the nRF Connect SDK .

    fs_write() depends on the backend used. Which backend do you use for your file system?

    Which overlays do you use to build the smp_srv sample?

    Regards,
    Sigurd Hellesvik

  • Hi Sigurd,
       Thank you: let me look into the link you sent

       I use the zephyr/fs/littlefs one:

      I use the nrf52840dk_nrf52840.overlay


    Kind Regards,
     Iulian




  • Hi Sigurd,
      Did not manage to reach far as had to jump on another task and when get back have to decide if to continue this path or look for alternative.

      The question is, on nrf52840, is possible to save 500 bytes to flash in a separate thread without freezing other threads at all (or no more than 2 milliseconds)?

    Kind Regards,
    Iulian

  • IulianI said:

      The question is, on nrf52840, is possible to save 500 bytes to flash in a separate thread without freezing other threads at all (or no more than 2 milliseconds)?

    I looked more into it, and I see that the CPU pauses when writing to flash.

    So if you have timing requirements, you could write less data at a time when writing to flash.
    Here you can see how much time it takes to write a 32 bit word to flash:

    Now how the data is written depends on how your file system does the writing: Does it write all with one command or with multiple?
    So maybe you have to just reduce the size you write at once.
    Or if you give the fs write thread low priority, and the file system writes in multiple blocks, the scheduler will fix the rest?

    An alternative could always be to use the NVMC drivers to do this manually in a low-prio thread to make sure you do not spend too much time.

1 2