When attempting to save data in flash using NVS API, I get a crash.
My code will first call the begin function bellow, which seems to work..
But calls to save crashes. The object size is 168 bytes...
Here is the code and the error from ESP32-IDF.
Does anyone have any idea what is happening and why I get this crash?
Thanks,
Cyrille
Code: Select all
class SomeObject { public:
void save()
{
nvs_handle_t my_handle;
if (nvs_open("CdB500Brains", NVS_READWRITE, &my_handle)!=ESP_OK) return;
printf("TSavedData::save %d %d\r\n", int(this), sizeof(*this));
nvs_set_blob(my_handle, "save", (void*)this, sizeof(*this));
nvs_commit(my_handle);
nvs_close(my_handle);
}
void begin()
{
nvs_handle_t my_handle;
esp_err_t err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) { ESP_ERROR_CHECK(nvs_flash_erase()); err = nvs_flash_init(); }
ESP_ERROR_CHECK(err);
ESP_ERROR_CHECK(nvs_open("CdB500Brains", NVS_READWRITE, &my_handle));
size_t size = sizeof(*this); err= nvs_get_blob(my_handle, "save", (void*)this, &size);
if (err!=ESP_OK || size!=sizeof(*this)) { reset(); ESP_ERROR_CHECK(nvs_set_blob(my_handle, "save", (void*)this, sizeof(*this))); }
ESP_ERROR_CHECK(nvs_commit(my_handle));
nvs_close(my_handle);
}
}
Code: Select all
TSavedData::save 1073426588 168 // This is my print function. It shows the object address and size (168 bytes)
Guru Meditation Error: Core 0 panic'ed (Cache disabled but cached memory region accessed).
Core 0 register dump:
PC : 0x400e2308 PS : 0x00060034 A0 : 0x8008588b A1 : 0x3ffb1040
--- 0x400e2308: adc_hal_get_reading_result at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/hal/adc_hal.c:232
A2 : 0x00000000 A3 : 0x3ffb2850 A4 : 0x80083c04 A5 : 0x3ffc4110
A6 : 0x3ffc5e94 A7 : 0x00000002 A8 : 0x800857c0 A9 : 0x00060623
A10 : 0x3ffc5e98 A11 : 0x3ffc60bc A12 : 0x3ffb1044 A13 : 0x3ffb1048
A14 : 0x00000020 A15 : 0x00060623 SAR : 0x00000018 EXCCAUSE: 0x00000007
EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0x00000000
--- 0x4000c2e0: memcpy in ROM
0x4000c2f6: memcpy in ROM
Backtrace: 0x400e2305:0x3ffb1040 0x40085888:0x3ffb1080 0x40083099:0x3ffb10a0 0x4000c2dd:0x3ffc40f0 0x4008b92d:0x3ffc4100 0x4008bd25:0x3ffc4130 0x4008f9fb:0x3ffc4150 0x40084567:0x3ffc41d0 0x400e1666:0x3ffc4210 0x400dcb9b:0x3ffc4240 0x400f23e6:0x3ffc4260 0x400dd90a:0x3ffc4280 0x400dbcd2:0x3ffc42e0 0x400dc6f1:0x3ffc4340 0x400dc99d:0x3ffc43b0 0x400db743:0x3ffc43d0 0x400d7152:0x3ffc4400 0x400d71b2:0x3ffc4420 0x400d807a:0x3ffc4440 0x400f36e4:0x3ffc4460 0x400886b1:0x3ffc4490
--- 0x400e2305: adc_hal_digi_dma_link at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/hal/adc_hal.c:229
0x40085888: adc_dma_intr_handler at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/esp_adc/esp32/adc_dma.c:36
0x40083099: _xt_lowint1 at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/xtensa/xtensa_vectors.S:1240
0x4000c2dd: memcpy in ROM
0x4008b92d: spi_flash_ll_get_buffer_data at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/hal/esp32/include/hal/spi_flash_ll.h:137
0x4008bd25: spi_flash_hal_read at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/hal/spi_flash_hal_common.inc:215
0x4008f9fb: spi_flash_chip_winbond_read at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/spi_flash/spi_flash_chip_winbond.c:61
0x40084567: esp_flash_read at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/spi_flash/esp_flash_api.c:899
0x400e1666: esp_partition_read at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/esp_partition/partition_target.c:38
0x400dcb9b: nvs::NVSPartition::read(unsigned int, void*, unsigned int) at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/nvs_flash/src/nvs_partition.cpp:37
0x400f23e6: nvs::Page::readEntry(unsigned int, nvs::Item&) const at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/nvs_flash/src/nvs_page.cpp:855
0x400dd90a: nvs::Page::findItem(unsigned char, nvs::ItemType, char const*, unsigned int&, nvs::Item&, unsigned char, nvs::VerOffset) at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/nvs_flash/src/nvs_page.cpp:908
0x400dbcd2: nvs::Storage::eraseMultiPageBlob(unsigned char, char const*, nvs::VerOffset) at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/nvs_flash/src/nvs_storage.cpp:744 (discriminator 1)
0x400dc6f1: nvs::Storage::writeItem(unsigned char, nvs::ItemType, char const*, void const*, unsigned int) at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/nvs_flash/src/nvs_storage.cpp:447
0x400dc99d: nvs::NVSHandleSimple::set_blob(char const*, void const*, unsigned int) at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/nvs_flash/src/nvs_handle_simple.cpp:44
0x400db743: nvs_set_blob at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/nvs_flash/src/nvs_api.cpp:441
0x400d7152: TSavedData::save() at C:/Users/cydeb/Desktop/Brains/main/main.cpp:184
0x400d71b2: CMWiFi::setAPName(char const*, char const*, bool) at C:/Users/cydeb/Desktop/Brains/main/messages.h:322
0x400d807a: app_main at C:/Users/cydeb/Desktop/Brains/main/main.cpp:672
0x400f36e4: main_task at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/freertos/app_startup.c:208
0x400886b1: vPortTaskWrapper at C:/Users/cydeb/Documents/esp/v5.3.2/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:139