Skip to content

Possible missing nvs_flash_init() in esp32/modPreference.c #189

Description

@zBuffer

xs_preference_set() does not take into account if NVS partition is not initialized (ESP_ERR_NVS_NOT_INITIALIZED).

What worked for me:

	err = nvs_open(xsmcToString(xsArg(0)), NVS_READWRITE, &handle);
	if(ESP_ERR_NVS_NOT_INITIALIZED == err) {
		err = nvs_flash_init();
		if (ESP_OK != err){
			if(err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
				const esp_partition_t *part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, "nvs");
				if(!part)
					xsUnknownError("esp_partition_find_first couldn't find nvs partition");

				err = esp_partition_erase_range(part, 0, part->size);
				if (ESP_OK != err)
					xsUnknownError("esp_partition_erase_range fail");
					
				err = nvs_flash_init();
			}
			if (ESP_OK != err)
				xsUnknownError("nvs_flash_init fail");
		}
		err = nvs_open(xsmcToString(xsArg(0)), NVS_READWRITE, &handle);
	}
	if (ESP_OK != err)
		xsUnknownError("nvs_open fail");

Or is there an option to force esptool to re-flash nvs partition?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions