From e99b4e85b92cdd9cc30e575bec9eac3aed4ebf37 Mon Sep 17 00:00:00 2001 From: Liu Zhi Fu Date: Thu, 3 May 2018 15:48:14 +0800 Subject: [PATCH] esp32: fix potential PHY calibration bug 1. Add error log if failed to store calibration version/mac/data 2. Change the NVS calibration version/mac/data store sequence --- components/esp32/phy_init.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/components/esp32/phy_init.c b/components/esp32/phy_init.c index 280a4f0942..1948e06bac 100644 --- a/components/esp32/phy_init.c +++ b/components/esp32/phy_init.c @@ -241,19 +241,34 @@ static esp_err_t store_cal_data_to_nvs_handle(nvs_handle handle, const esp_phy_calibration_data_t* cal_data) { esp_err_t err; - uint32_t cal_format_version = phy_get_rf_cal_version() & (~BIT(16)); - ESP_LOGV(TAG, "phy_get_rf_cal_version: %d\n", cal_format_version); - err = nvs_set_u32(handle, PHY_CAL_VERSION_KEY, cal_format_version); + + err = nvs_set_blob(handle, PHY_CAL_DATA_KEY, cal_data, sizeof(*cal_data)); if (err != ESP_OK) { + ESP_LOGE(TAG, "%s: store calibration data failed(0x%x)\n", __func__, err); return err; } + uint8_t sta_mac[6]; esp_efuse_mac_get_default(sta_mac); err = nvs_set_blob(handle, PHY_CAL_MAC_KEY, sta_mac, sizeof(sta_mac)); if (err != ESP_OK) { + ESP_LOGE(TAG, "%s: store calibration mac failed(0x%x)\n", __func__, err); return err; } - err = nvs_set_blob(handle, PHY_CAL_DATA_KEY, cal_data, sizeof(*cal_data)); + + uint32_t cal_format_version = phy_get_rf_cal_version() & (~BIT(16)); + ESP_LOGV(TAG, "phy_get_rf_cal_version: %d\n", cal_format_version); + err = nvs_set_u32(handle, PHY_CAL_VERSION_KEY, cal_format_version); + if (err != ESP_OK) { + ESP_LOGE(TAG, "%s: store calibration version failed(0x%x)\n", __func__, err); + return err; + } + + err = nvs_commit(handle); + if (err != ESP_OK) { + ESP_LOGE(TAG, "%s: store calibration nvs commit failed(0x%x)\n", __func__, err); + } + return err; }