ESP32

ESP32, NVS, nvs_rw_value

CoyoteUgly 2018. 8. 23. 00:23

ESP32, NVS, nvs_rw_value



0. 참고 사이트


1. 모듈


2. 보드 연결


3. 소스 설명

esp_err_t err = nvs_flash_init();

// Open
nvs_handle my_handle;
err = nvs_open("storage", NVS_READWRITE, &my_handle);

// Read
int32_t restart_counter = 0; // value will default to 0, if not set yet in NVS
err = nvs_get_i32(my_handle, "restart_counter", &restart_counter);

// Write
err = nvs_set_i32(my_handle, "restart_counter", restart_counter);

// Commit written value.
err = nvs_commit(my_handle);

// Close
nvs_close(my_handle);

4. 소스

https://github.com/sglee0223/esp32/tree/master/nvs_rw_value


5. 결과 확인

storage Label 파티션에 int32_t 형의 변수를 리셋 시마다 +1 한 값을
계속적으로 overwrite하는 구조입니다.

I (0) cpu_start: App cpu up.
I (215) heap_init: Initializing. RAM available for dynamic allocation:
I (221) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (228) heap_init: At 3FFB3340 len 0002CCC0 (179 KiB): DRAM
I (234) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (240) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (247) heap_init: At 40088DDC len 00017224 (92 KiB): IRAM
I (253) cpu_start: Pro cpu start user code
I (271) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.

Opening Non-Volatile Storage (NVS) handle... Done
Reading restart counter from NVS ... The value is not initialized yet!
Updating restart counter in NVS ... Done
Committing updates in NVS ... Done

Restarting in 10 seconds...
Restarting in 9 seconds...
Restarting in 8 seconds...
Restarting in 7 seconds...
Restarting in 6 seconds...
Restarting in 5 seconds...
Restarting in 4 seconds...
Restarting in 3 seconds...
Restarting in 2 seconds...
Restarting in 1 seconds...
Restarting in 0 seconds...
Restarting now.
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x12 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:5884
load:0x40078000,len:9308
ho 0 tail 12 room 4
load:0x40080400,len:6148
entry 0x40080748
I (30) boot: ESP-IDF v3.2-dev-518-g020ade65 2nd stage bootloader
I (31) boot: compile time 12:59:53
I (31) boot: Enabling RNG early entropy source...
I (37) boot: SPI Speed      : 40MHz
I (41) boot: SPI Mode       : DIO
I (45) boot: SPI Flash Size : 4MB
I (49) boot: Partition Table:
I (53) boot: ## Label            Usage          Type ST Offset   Length
I (60) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (67) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (75) boot:  2 factory          factory app      00 00 00010000 00100000
I (82) boot: End of partition table
I (86) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x06f70 ( 28528) map
I (105) esp_image: segment 1: paddr=0x00016f98 vaddr=0x3ffb0000 size=0x022a8 (  8872) load
I (109) esp_image: segment 2: paddr=0x00019248 vaddr=0x3ffb22a8 size=0x00000 (     0) load
I (113) esp_image: segment 3: paddr=0x00019250 vaddr=0x40080000 size=0x00400 (  1024) load
0x40080000: _WindowOverflow4 at /home/sglee/esp/esp-idf/components/freertos/xtensa_vectors.S:1685

I (122) esp_image: segment 4: paddr=0x00019658 vaddr=0x40080400 size=0x069b8 ( 27064) load
I (142) esp_image: segment 5: paddr=0x00020018 vaddr=0x400d0018 size=0x15ed0 ( 89808) map
0x400d0018: _flash_cache_start at ??:?

I (174) esp_image: segment 6: paddr=0x00035ef0 vaddr=0x40086db8 size=0x02024 (  8228) load
0x40086db8: multi_heap_realloc_impl at /home/sglee/esp/esp-idf/components/heap/multi_heap.c:559

I (178) esp_image: segment 7: paddr=0x00037f1c vaddr=0x400c0000 size=0x00000 (     0) load
I (181) esp_image: segment 8: paddr=0x00037f24 vaddr=0x50000000 size=0x00000 (     0) load
I (195) boot: Loaded app from partition at offset 0x10000
I (196) boot: Disabling RNG early entropy source...
I (201) cpu_start: Pro cpu up.
I (205) cpu_start: Starting app cpu, entry point is 0x40081084
0x40081084: call_start_cpu1 at /home/sglee/esp/esp-idf/components/esp32/cpu_start.c:225

I (196) cpu_start: App cpu up.
I (216) heap_init: Initializing. RAM available for dynamic allocation:
I (222) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (228) heap_init: At 3FFB3340 len 0002CCC0 (179 KiB): DRAM
I (235) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (241) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (247) heap_init: At 40088DDC len 00017224 (92 KiB): IRAM
I (254) cpu_start: Pro cpu start user code
I (272) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.

Opening Non-Volatile Storage (NVS) handle... Done
Reading restart counter from NVS ... Done
Restart counter = 1
Updating restart counter in NVS ... Done
Committing updates in NVS ... Done

Restarting in 10 seconds...
Restarting in 9 seconds...
Restarting in 8 seconds...
Restarting in 7 seconds...
Restarting in 6 seconds...
Restarting in 5 seconds...
Restarting in 4 seconds...
Restarting in 3 seconds...
Restarting in 2 seconds...
Restarting in 1 seconds...
Restarting in 0 seconds...
Restarting now.
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x12 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:5884
load:0x40078000,len:9308
ho 0 tail 12 room 4
load:0x40080400,len:6148
entry 0x40080748
I (30) boot: ESP-IDF v3.2-dev-518-g020ade65 2nd stage bootloader
I (31) boot: compile time 12:59:53
I (31) boot: Enabling RNG early entropy source...
I (37) boot: SPI Speed      : 40MHz
I (41) boot: SPI Mode       : DIO
I (45) boot: SPI Flash Size : 4MB
I (49) boot: Partition Table:
I (53) boot: ## Label            Usage          Type ST Offset   Length
I (60) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (67) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (75) boot:  2 factory          factory app      00 00 00010000 00100000
I (82) boot: End of partition table
I (86) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x06f70 ( 28528) map
I (105) esp_image: segment 1: paddr=0x00016f98 vaddr=0x3ffb0000 size=0x022a8 (  8872) load
I (109) esp_image: segment 2: paddr=0x00019248 vaddr=0x3ffb22a8 size=0x00000 (     0) load
I (113) esp_image: segment 3: paddr=0x00019250 vaddr=0x40080000 size=0x00400 (  1024) load
0x40080000: _WindowOverflow4 at /home/sglee/esp/esp-idf/components/freertos/xtensa_vectors.S:1685

I (122) esp_image: segment 4: paddr=0x00019658 vaddr=0x40080400 size=0x069b8 ( 27064) load
I (142) esp_image: segment 5: paddr=0x00020018 vaddr=0x400d0018 size=0x15ed0 ( 89808) map
0x400d0018: _flash_cache_start at ??:?

I (174) esp_image: segment 6: paddr=0x00035ef0 vaddr=0x40086db8 size=0x02024 (  8228) load
0x40086db8: multi_heap_realloc_impl at /home/sglee/esp/esp-idf/components/heap/multi_heap.c:559

I (178) esp_image: segment 7: paddr=0x00037f1c vaddr=0x400c0000 size=0x00000 (     0) load
I (181) esp_image: segment 8: paddr=0x00037f24 vaddr=0x50000000 size=0x00000 (     0) load
I (195) boot: Loaded app from partition at offset 0x10000
I (196) boot: Disabling RNG early entropy source...
I (201) cpu_start: Pro cpu up.
I (205) cpu_start: Starting app cpu, entry point is 0x40081084
0x40081084: call_start_cpu1 at /home/sglee/esp/esp-idf/components/esp32/cpu_start.c:225

I (196) cpu_start: App cpu up.
I (216) heap_init: Initializing. RAM available for dynamic allocation:
I (222) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (228) heap_init: At 3FFB3340 len 0002CCC0 (179 KiB): DRAM
I (235) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (241) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (247) heap_init: At 40088DDC len 00017224 (92 KiB): IRAM
I (254) cpu_start: Pro cpu start user code
I (272) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.

Opening Non-Volatile Storage (NVS) handle... Done
Reading restart counter from NVS ... Done
Restart counter = 2
Updating restart counter in NVS ... Done
Committing updates in NVS ... Done

Restarting in 10 seconds...
Restarting in 9 seconds...
Restarting in 8 seconds...
Restarting in 7 seconds...
Restarting in 6 seconds...
Restarting in 5 seconds...
Restarting in 4 seconds... 



'ESP32' 카테고리의 다른 글

ESP32, spiffs  (0) 2018.08.23
ESP32, NVS, nvs_rw_blob  (0) 2018.08.23
ESP32, NVS 이해하기  (0) 2018.08.22
ESP32, TIMER, esp_timer  (0) 2018.08.22
ESP32, GPIO, gpio_intr  (0) 2018.08.22