NVS partition size problem
Posted: Fri Feb 07, 2020 11:39 pm
Hi,
I was programming a circular non-volatile buffer and i find out that when I open an NVS partition of size 0x1000 it seems that it can't save the values meanwhile when the size of the partition is 1M there is no problem with the saved values.
This is what i get when the partition size is 1M, every time it reboots it has the same quantity of used values:
BUT when the size of the partition is 0x1000 this is what happens:
FIRST TIME:
AFTER REBOOT:
I don't know whats happening and why it depends on the size of the partition to actually save.
here i share my partition table:
And here the initialization in the main() :
And here the task that actually save the values:
Does anyone have an idea on whats happening? did i missed something?
I was programming a circular non-volatile buffer and i find out that when I open an NVS partition of size 0x1000 it seems that it can't save the values meanwhile when the size of the partition is 1M there is no problem with the saved values.
This is what i get when the partition size is 1M, every time it reboots it has the same quantity of used values:
Code: Select all
I (326) cpu_start: Pro cpu start user code
I (344) spi_flash: detected chip: gd
I (345) spi_flash: flash io: dio
I (345) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
W (353) adio-example: partition init: log_part
Count: UsedEntries = (152), FreeEntries = (64360), AllEntries = (64512)
FIRST TIME:
Code: Select all
W (353) adio-example: Inicializando Particion log_part
Count: UsedEntries = (0), FreeEntries = (126), AllEntries = (126)
W (403) adio-example: Writing first LOG element: log_0
Count: UsedEntries = (2), FreeEntries = (124), AllEntries = (126)
Code: Select all
W (353) adio-example: Inicializando Particion log_part
Count: UsedEntries = (0), FreeEntries = (126), AllEntries = (126)
W (403) adio-example: Writing first LOG element: log_0
Count: UsedEntries = (2), FreeEntries = (124), AllEntries = (126)
here i share my partition table:
Code: Select all
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x4000
otadata, data, ota, , 0x2000
phy_init, data, phy, , 0x1000
factory, app, factory, , 3M
ota_0, app, ota_0, , 3M
ota_1, app, ota_1, , 3M
# log_part, data, nvs, , 2M
log_part, data, nvs, , 0x1000
Code: Select all
ESP_LOGW(TAG, "Inicializando Particion %s", nvs_partition_name);
err = nvs_flash_init_partition(nvs_partition_name);
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND)
{
ESP_ERROR_CHECK(nvs_flash_erase_partition(nvs_partition_name));
err = nvs_flash_init_partition(nvs_partition_name);
}
ESP_ERROR_CHECK(err);
NVS_PRINT_STATS(nvs_partition_name);
sprintf(log_aux,"log_%d", log_val);
ESP_LOGW(TAG, "Writing first LOG element: %s", log_aux);
usintNVSwrite_from_partition(nvs_partition_name, nvs_name, nvs_log_handle, 10, log_aux);
ESP_LOGW(TAG, "Reading first LOG element: %s. log_val vale: %d", log_aux, log_val);
usintNVSread_from_partition(nvs_partition_name, nvs_name, nvs_log_handle, &log_val, log_aux);
ESP_LOGW(TAG, "log_val after reading is: %d", log_val);
Code: Select all
static void log_save(void *args)
{
adc_t *adc = args;
char *TAG = "log task";
ESP_LOGI(TAG,"log_save task: INIT");
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
ESP_LOGI(TAG,"log_save task: STARTED");
while (1)
{
if(xSemaphoreTake( xSemaphore, ( TickType_t ) 10 ))
{
//ESP_LOGW(TAG,"tengo semaforo en log");
//Convert adc_reading to voltage in mV
ESP_LOGW(TAG,"log_value to save is: %d", adc->analog_read);
uint32_t voltage = esp_adc_cal_raw_to_voltage(adc->analog_read, adc->adc_chars);
configASSERT(adc->adc_chars);
ESP_LOGI(TAG,"Voltage: %dmV | Raw: %d", voltage, adc->analog_read);
//ESP_LOGW(TAG,"suelto semaforo en log");
sprintf(log_aux, "log_%d", log_index);
ESP_LOGI(TAG, "saving %s = %d", log_aux, adc->analog_read);
usintNVSwrite_from_partition(nvs_partition_name, nvs_name, nvs_log_handle, adc->analog_read, log_aux);
log_index++;
if (log_index>150)
log_index=1;
xSemaphoreGive( xSemaphore );
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
}