I'm getting the below pointer error. The Esp idf function nvs_set_i32() requires a int32_t (not uint32!?) I made a macro to make my life easier but I get the error Can someone help ?
"passing argument 3 of 'nvs_set_i32' makes integer from pointer without a cast [-Wint-conversion]"
ESP32 - nvs pointer issue
ESP32 - nvs pointer issue
- Attachments
-
- Screenshot_1.jpg (109.06 KiB) Viewed 2023 times
-
- Screenshot_2.jpg (38.74 KiB) Viewed 2023 times
-
- Posts: 52
- Joined: Thu Jun 22, 2023 12:50 pm
Re: ESP32 - nvs pointer issue
Hello. This is a function signature for nvs_set_i32.
You're passing int32_t pointer (int32_t *) into int32_t value field. You need to dereference it first with * or use just int32_t without pointer in your function parameter. Also your are using # macro stringification on "val", but I think it will stringify "val" itself and not the value, so you overwrite your previous values.
- esp_err_t nvs_set_i32 (nvs_handle_t handle, const char* key, int32_t value);
Re: ESP32 - nvs pointer issue
Thanks ESP_adokitkat I finally did it properly.
I still have a question though if you can answer.
I'm trying to check whether the ESP has reset from an upgrade (USB or OTA) to reset my "reset_counter" which is stored in flash.
I tried to detect that from the response from the function nvs_get(). If I get a "value not initialized" then it means I had a code upgrade and I should reset the "reset_counter" variable. But it seems that after I upgrade my code this variable is still initialized !
I still have a question though if you can answer.
I'm trying to check whether the ESP has reset from an upgrade (USB or OTA) to reset my "reset_counter" which is stored in flash.
I tried to detect that from the response from the function nvs_get(). If I get a "value not initialized" then it means I had a code upgrade and I should reset the "reset_counter" variable. But it seems that after I upgrade my code this variable is still initialized !
- Attachments
-
- Screenshot_2.jpg (35.54 KiB) Viewed 1789 times
-
- Posts: 52
- Joined: Thu Jun 22, 2023 12:50 pm
Re: ESP32 - nvs pointer issue
NVS is short for non-volatile storage. NVS partition is not erased during OTA upgrade nor even if you re-flash your firmware via USB, your values should still be there. You need to specifically erase the partition or do `idf.py erase-flash` to erase everything, or re-flash NVS partition with `idf.py <partition>-flash` i.e. `idf.py nvs-flash` if you generate it on PC.
If you are doing OTA upgrade for example you can just add another key to you NVS which you will set to e.g. 1 before performing the upgrade - if the upgrade fails, reset it back to 0, if it succeeds and reboots, it will stay 1 so you can check it and know you rebooted because of the upgrade and then reset it back to 0. Or you can write your own OTA upgrade function which increases some value in NVS like "ota_upgrade_counter" before rebooting...
For USB upgrade it is more tricky but you could do something like store firmware version in a define/variable and store it in NVS as well. At boot you can check if the define is the same as the value in the NVS and if not, you can increase e.g. "upgrade_counter" in NVS and set the new version value for future comparisons...
Just some quick ideas, maybe there are better ways.
If you are doing OTA upgrade for example you can just add another key to you NVS which you will set to e.g. 1 before performing the upgrade - if the upgrade fails, reset it back to 0, if it succeeds and reboots, it will stay 1 so you can check it and know you rebooted because of the upgrade and then reset it back to 0. Or you can write your own OTA upgrade function which increases some value in NVS like "ota_upgrade_counter" before rebooting...
For USB upgrade it is more tricky but you could do something like store firmware version in a define/variable and store it in NVS as well. At boot you can check if the define is the same as the value in the NVS and if not, you can increase e.g. "upgrade_counter" in NVS and set the new version value for future comparisons...
Just some quick ideas, maybe there are better ways.
Re: ESP32 - nvs pointer issue
Thanks ESP_adokitkat
Who is online
Users browsing this forum: No registered users and 80 guests