Time executing NVS functions

Jonas A
Posts: 4
Joined: Tue Mar 09, 2021 11:14 am

Time executing NVS functions

Postby Jonas A » Thu Jun 10, 2021 9:38 am

Hello,

Is this function non-blocking?

esp_err_t nvs_set_u32(nvs_handle_thandle, const char *key, uint32_t value)

Writing to flash usually takes a few milliseconds. Does this function block the current task x milliseconds? Or is there a background task that write to the flash memory?

BR
Jonas

ESP_jakob
Posts: 23
Joined: Mon Jun 01, 2020 6:28 am

Re: Time executing NVS functions

Postby ESP_jakob » Fri Jun 11, 2021 6:25 am

Hi Jonas,

the NVS functions are all blocking. There is no background thread going on. Since NVS may re-order data if one page is full, there's a potential erasure of flash which takes a "long" time, blocking the current thread.

If you want to do something during the time of writing, then please use a FreeRTOS task or alternatively std::async, if you're using C++.

Best,
Jakob

Jonas A
Posts: 4
Joined: Tue Mar 09, 2021 11:14 am

Re: Time executing NVS functions

Postby Jonas A » Fri Jun 11, 2021 8:14 am

Thanks for the answer. I measured the time of

esp_err_t nvs_set_u32(nvs_handle_thandle, const char *key, uint32_t value)

and it took 500 uS to execute.

Who is online

Users browsing this forum: No registered users and 54 guests