Skip to content

Commit e73e6bb

Browse files
committed
Merge branch 'bugfix/console_example_nvs_init' into 'master'
console example: initialize nvs on startup See merge request !1766
2 parents 23992d2 + 24b07a3 commit e73e6bb

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

examples/system/console/main/console_example_main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "argtable3/argtable3.h"
1919
#include "cmd_decl.h"
2020
#include "esp_vfs_fat.h"
21+
#include "nvs.h"
22+
#include "nvs_flash.h"
2123

2224
static const char* TAG = "example";
2325

@@ -45,6 +47,16 @@ static void initialize_filesystem()
4547
}
4648
#endif // CONFIG_STORE_HISTORY
4749

50+
static void initialize_nvs()
51+
{
52+
esp_err_t err = nvs_flash_init();
53+
if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
54+
ESP_ERROR_CHECK( nvs_flash_erase() );
55+
err = nvs_flash_init();
56+
}
57+
ESP_ERROR_CHECK(err);
58+
}
59+
4860
static void initialize_console()
4961
{
5062
/* Disable buffering on stdin and stdout */
@@ -94,6 +106,8 @@ static void initialize_console()
94106

95107
void app_main()
96108
{
109+
initialize_nvs();
110+
97111
#if CONFIG_STORE_HISTORY
98112
initialize_filesystem();
99113
#endif

0 commit comments

Comments
 (0)