Setting Up Non-Volatile Memory


The entry point of the application serves to carry out three main tasks. Firstly, the app instantiates Non-Volatile Storage (Flash Memory) utilizing functions defined within the nvs_flash.h header file .

Throughout our server, we utilize an instance of esp_err_t ret to store any potential errors that may occur during the process of instantiating the Bluetooth server. For example:

esp_err_t ret;
ret = nvs_flash_init();  // Attempt to instantiate the Non-Volatile Storage
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
    ESP_ERROR_CHECK(nvs_flash_erase());
    ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);

The Non-Volatile Memory is necessary as the ESP32 requires it to store PHY calibration data as well as key-value pairs across reboots .