Page 1 of 2

ESP32 store calibration data failed(0x1105)

Posted: Wed Jan 19, 2022 9:24 am
by zazas321
Hello. I have been developing on the ESP32 as usual and noticed that I am getting this error and a warning. I have not noticed this before.
The error happens when I initialise BLE:

Code: Select all

I (3922) BTDM_INIT: BT controller compile version [6a07b06]
I (3922) system_api: Base MAC address is not set
I (3922) system_api: read default base MAC address from EFUSE
I (3932) phy_init: phy_version 4670,719f9f6,Feb 18 2021,17:07:07
W (4092) phy_init: saving new calibration data because of checksum failure, mode(0)
E (4442) phy_init: store_cal_data_to_nvs_handle: store calibration data failed(0x1105)
I use custom partition table (my ESP32 is 8MB flash version)

Code: Select all

nvs,      data, nvs,     0x9000,  0x4000,
otadata,  data, ota,     0xd000,  0x2000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000,  0x200000,
ota_0,    app,  ota_0,           , 0x100000,
ota_1,    app,  ota_1,           , 0x100000,
Could someone help me understand why would this happen?


This is my app_main:

Code: Select all

 app_main(void)
{
    static httpd_handle_t server = NULL;
    esp_err_t ret;
    ret = nvs_flash_init();
    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);
    ADC_Init();
    NVS_open();
    SPI_init_eeprom();
    EEPROM_setup();
    spi_mutex = xSemaphoreCreateBinary(); /
    xSemaphoreGive(spi_mutex); // give the semaphore immediately after creating so that my task can take it
    i2c_mutex = xSemaphoreCreateBinary(); // i2c mutex decalred as extern global in PCA9539
    xSemaphoreGive(i2c_mutex); // give the semaphore immediately after creating so that my task can take it
    i2c_setup(); // this setups i2c bus and setups all the required pins
    BLE_setup();//happens if this is called
    UART1_setup();


    xTaskCreate(UART0_task,"UART0_task",5000,NULL,1,NULL); // receiving commands from main uart


}

my BLE_setup :

Code: Select all

void BLE_setup()
{
    printf("BLE SETUP \n");
    esp_err_t ret;
    ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
    //ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_BLE));

    esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
    ret = esp_bt_controller_init(&bt_cfg);
    if (ret) {
        ESP_LOGE(GATTS_TABLE_TAG, "%s init controller failed: %s", __func__, esp_err_to_name(ret));
        return;
    }
    ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
    if (ret) {
        ESP_LOGE(GATTS_TABLE_TAG, "%s enable controller failed: %s", __func__, esp_err_to_name(ret));
        return;
    }

    ESP_LOGI(GATTS_TABLE_TAG, "%s init bluetooth", __func__);
    ret = esp_bluedroid_init();
    if (ret) {
        ESP_LOGE(GATTS_TABLE_TAG, "%s init bluetooth failed: %s", __func__, esp_err_to_name(ret));
        return;
    }
    ret = esp_bluedroid_enable();
    if (ret) {
        ESP_LOGE(GATTS_TABLE_TAG, "%s enable bluetooth failed: %s", __func__, esp_err_to_name(ret));
        return;
    }
    const uint8_t* point = esp_bt_dev_get_address();
    for (int i = 0; i < 6; i++) {
        char str[3];
        sprintf(str, "%02X", (int)point[i]);
        printf(str);
        if (i < 5){
            printf(":");
        }
    }


    ret = esp_ble_gatts_register_callback(gatts_event_handler);
    if (ret){
        ESP_LOGE(GATTS_TABLE_TAG, "gatts register error, error code = %x", ret);
        return;
    }
    ret = esp_ble_gap_register_callback(gap_event_handler);
    if (ret){
        ESP_LOGE(GATTS_TABLE_TAG, "gap register error, error code = %x", ret);
        return;
    }
    ret = esp_ble_gatts_app_register(ELSTAT_CUSTOM_APP_ID);
    if (ret){
        ESP_LOGE(GATTS_TABLE_TAG, "gatts app register error, error code = %x", ret);
        return;
    }

    /* set the security iocap & auth_req & key size & init key response key parameters to the stack*/
    esp_ble_auth_req_t auth_req = ESP_LE_AUTH_REQ_SC_MITM_BOND;     //bonding with peer device after authentication
    esp_ble_io_cap_t iocap = ESP_IO_CAP_OUT;           //set the IO capability to No output No input
    uint8_t key_size = 16;      //the key size should be 7~16 bytes
    uint8_t init_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK;
    uint8_t rsp_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK;
    //set static passkey
    //uint32_t passkey = 123456;
    uint8_t auth_option = ESP_BLE_ONLY_ACCEPT_SPECIFIED_AUTH_DISABLE;
    uint8_t oob_support = ESP_BLE_OOB_DISABLE;
    esp_ble_gap_set_security_param(ESP_BLE_SM_SET_STATIC_PASSKEY, &BLE_passkey, sizeof(uint32_t));
    esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &auth_req, sizeof(uint8_t));
    esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t));
    esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &key_size, sizeof(uint8_t));
    esp_ble_gap_set_security_param(ESP_BLE_SM_ONLY_ACCEPT_SPECIFIED_SEC_AUTH, &auth_option, sizeof(uint8_t));
    esp_ble_gap_set_security_param(ESP_BLE_SM_OOB_SUPPORT, &oob_support, sizeof(uint8_t));
    /* If your BLE device acts as a Slave, the init_key means you hope which types of key of the master should distribute to you,
    and the response key means which key you can distribute to the master;
    If your BLE device acts as a master, the response key means you hope which types of key of the slave should distribute to you,
    and the init key means which key you can distribute to the slave. */
    esp_ble_gap_set_security_param(ESP_BLE_SM_SET_INIT_KEY, &init_key, sizeof(uint8_t));
    esp_ble_gap_set_security_param(ESP_BLE_SM_SET_RSP_KEY, &rsp_key, sizeof(uint8_t));

    

    /* Just show how to clear all the bonded devices
     * Delay 30s, clear all the bonded devices
     *
     * vTaskDelay(30000 / portTICK_PERIOD_MS);
     * remove_all_bonded_devices();
     */


}


Re: ESP32 store calibration data failed(0x1105)

Posted: Wed Jan 19, 2022 10:40 am
by zazas321
UPDATE:

I have confirmed that this is only happening to one device that I was using the most. The other devices when flashed with the exact same code does not produce this error so this must be hardware related issue.

1.Is it possible that I have somehow managed to corrupt it? What could have possibly gone wrong that this only happens to this device but not others

2. What exactly this error means? Even though this error happens (I havent done extensive testing ), my program seems to be running as usual. What problems could this cause me?

Re: ESP32 store calibration data failed(0x1105)

Posted: Wed Jan 19, 2022 11:07 am
by boarchuz
0x1105 = ESP_ERR_NVS_NOT_ENOUGH_SPACE
Calibration data is almost 2kB, your NVS partition is small, and you use this particular device a lot. NVS is full.

https://docs.espressif.com/projects/esp ... alibration
Full calibration is relatively slow and uses a lot of power. Given this data can't be saved and restored, this will need to be done every time WiFi/BT is initialised (ie. every boot/wake).

Re: ESP32 store calibration data failed(0x1105)

Posted: Wed Jan 19, 2022 11:40 am
by zazas321
Thank you very much for the response. I have some additional questions

1. What is this calibration data exactly? How important is it for the program? Can it work without this?

2. Can I just simply allocate a few more KB in my partition. Would that fix the issue? Is it only temporary fix?

3. Does it fill up overtime? Why is it not full on some other devices.?

Re: ESP32 store calibration data failed(0x1105)

Posted: Wed Jan 19, 2022 11:55 am
by chegewara
1. speedup system start, as its faster to read calibration data rather than do it every time
2. sure, but you will have to move nvs partition to the end of flash or change all partitions offset
3. its because, like you said, the device you are working with most the time; the nvs partition is most likely full of other stored values from other projects; idf.py erase_flash should fix it

PS what is your flash size, because you are allocating more than 4MB

Re: ESP32 store calibration data failed(0x1105)

Posted: Wed Jan 19, 2022 12:18 pm
by boarchuz
zazas321 wrote:
Wed Jan 19, 2022 11:40 am
1What is this calibration data exactly?
It's not documented, unfortunately. Some kind of tuning parameters for RF transmission vs power.

If you'd like this to change, please add a comment here: https://github.com/espressif/esp-idf/issues/7324
NVS failure is another good case.

Re: ESP32 store calibration data failed(0x1105)

Posted: Wed Jan 19, 2022 12:31 pm
by zazas321
This is concerning me because once I finish programming the device, it will be out on the field doing what its supposed to do and I dont this to cause me some trouble later. So my 2 solutions are:

1. Increase the size of the partition for the PHY (I assume this is only temporary because it is going to fill overtime)
2. call esp_phy_erase_cal_data_in_nvs() before initialising WiFi or BLE

Re: ESP32 store calibration data failed(0x1105)

Posted: Wed Jan 19, 2022 12:36 pm
by chegewara
PHY calibration is done only one time, so it wont fill over time.
If you afraid of that then maybe leave this nvs partition just for that (and some wifi stored data) and to have another NVS partition you could use for all data you will store in app?

Re: ESP32 store calibration data failed(0x1105)

Posted: Wed Jan 19, 2022 3:07 pm
by WiFive

Re: ESP32 store calibration data failed(0x1105)

Posted: Thu Jan 20, 2022 5:35 am
by zazas321
chegewara wrote:
Wed Jan 19, 2022 12:36 pm
PHY calibration is done only one time, so it wont fill over time.
If you afraid of that then maybe leave this nvs partition just for that (and some wifi stored data) and to have another NVS partition you could use for all data you will store in app?

Can you clarify what do you mean? I thought tahts wht I have:

Code: Select all

vs,      data, nvs,     0x9000,  0x4000,
otadata,  data, ota,     0xd000,  0x2000,
phy_init, data, phy,     0xf000,  0x1000,
factory,  app,  factory, 0x10000,  0x200000,
ota_0,    app,  ota_0,           , 0x100000,
ota_1,    app,  ota_1,           , 0x100000,
I have 2MB for the app and just 0x4000 for the nvs.