RF calibration

ESP32-S3 supports three RF calibration methods during RF initialization:

  1. Partial calibration

  2. Full calibration

  3. No calibration

Partial calibration

During RF initialization, the partial calibration method is used by default for RF calibration. It is done based on the full calibration data which is stored in the NVS. To use this method, please go to menuconfig and enable CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE.

Full calibration

Full calibration is triggered in the follwing conditions:

  1. NVS does not exist.

  2. The NVS partition to store calibration data is erased.

  3. Hardware MAC address is changed.

  4. PHY library version is changed.

  5. The RF calibration data loaded from the NVS partition is broken.

It takes about 100ms more than partial calibration. If boot duration is not critical, it is suggested to use the full calibration method. To switch to the full calibration method, go to menuconfig and disable CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE. If you use the default method of RF calibration, there are two ways to add the function of triggering full calibration as a last-resort remedy.

  1. Erase the NVS partition if you don’t mind all of the data stored in the NVS partition is erased. That is indeed the easiest way.

  2. Call API esp_phy_erase_cal_data_in_nvs() before initializing WiFi and BT/BLE based on some conditions (e.g. an option provided in some diagnostic mode). In this case, only phy namespace of the NVS partition is erased.

No calibration

No calibration method is only used when the device wakes up from deep sleep.

PHY initialization data

The PHY initialization data is used for RF calibration. There are two ways to get the PHY initialization data.

One is the default initialization data which is located in the header file components/esp_phy/esp32s3/include/phy_init_data.h.

It is embedded into the application binary after compiling and then stored into read-only memory (DROM). To use the default initialization data, please go to menuconfig and disable CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION.

Another is the initialization data which is stored in a partition. When using a custom partition table, make sure that PHY data partition is included (type: data, subtype: phy). With default partition table, this is done automatically. If initialization data is stored in a partition, it has to be flashed there, otherwise runtime error will occur. To switch to the initialization data stored in a partition, go to menuconfig and enable CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION.

API Reference

Header File

Functions

const esp_phy_init_data_t *esp_phy_get_init_data(void)

Get PHY init data.

If “Use a partition to store PHY init data” option is set in menuconfig, This function will load PHY init data from a partition. Otherwise, PHY init data will be compiled into the application itself, and this function will return a pointer to PHY init data located in read-only memory (DROM).

If “Use a partition to store PHY init data” option is enabled, this function may return NULL if the data loaded from flash is not valid.

备注

Call esp_phy_release_init_data to release the pointer obtained using this function after the call to esp_wifi_init.

返回

pointer to PHY init data structure

void esp_phy_release_init_data(const esp_phy_init_data_t *data)

Release PHY init data.

参数

data – pointer to PHY init data structure obtained from esp_phy_get_init_data function

esp_err_t esp_phy_load_cal_data_from_nvs(esp_phy_calibration_data_t *out_cal_data)

Function called by esp_phy_init to load PHY calibration data.

This is a convenience function which can be used to load PHY calibration data from NVS. Data can be stored to NVS using esp_phy_store_cal_data_to_nvs function.

If calibration data is not present in the NVS, or data is not valid (was obtained for a chip with a different MAC address, or obtained for a different version of software), this function will return an error.

If “Initialize PHY in startup code” option is set in menuconfig, this function will be used to load calibration data. To provide a different mechanism for loading calibration data, disable “Initialize PHY in startup code” option in menuconfig and call esp_phy_init function from the application. For an example usage of esp_phy_init and this function, see esp_phy_store_cal_data_to_nvs function in cpu_start.c

参数

out_cal_data – pointer to calibration data structure to be filled with loaded data.

返回

ESP_OK on success

esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t *cal_data)

Function called by esp_phy_init to store PHY calibration data.

This is a convenience function which can be used to store PHY calibration data to the NVS. Calibration data is returned by esp_phy_init function. Data saved using this function to the NVS can later be loaded using esp_phy_store_cal_data_to_nvs function.

If “Initialize PHY in startup code” option is set in menuconfig, this function will be used to store calibration data. To provide a different mechanism for storing calibration data, disable “Initialize PHY in startup code” option in menuconfig and call esp_phy_init function from the application.

参数

cal_data – pointer to calibration data which has to be saved.

返回

ESP_OK on success

esp_err_t esp_phy_erase_cal_data_in_nvs(void)

Erase PHY calibration data which is stored in the NVS.

This is a function which can be used to trigger full calibration as a last-resort remedy if partial calibration is used. It can be called in the application based on some conditions (e.g. an option provided in some diagnostic mode).

返回

ESP_OK on success

返回

others on fail. Please refer to NVS API return value error number.

void esp_phy_enable(void)

Enable PHY and RF module.

PHY and RF module should be enabled in order to use WiFi or BT. Now PHY and RF enabling job is done automatically when start WiFi or BT. Users should not call this API in their application.

void esp_phy_disable(void)

Disable PHY and RF module.

PHY module should be disabled in order to shutdown WiFi or BT. Now PHY and RF disabling job is done automatically when stop WiFi or BT. Users should not call this API in their application.

void esp_phy_load_cal_and_init(void)

Load calibration data from NVS and initialize PHY and RF module.

void esp_phy_pd_mem_init(void)

Initialize backup memory for Phy power up/down.

void esp_phy_pd_mem_deinit(void)

Deinitialize backup memory for Phy power up/down.

void esp_phy_common_clock_enable(void)

Enable WiFi/BT common clock.

void esp_phy_common_clock_disable(void)

Disable WiFi/BT common clock.

int64_t esp_phy_rf_get_on_ts(void)

Get the time stamp when PHY/RF was switched on.

返回

return 0 if PHY/RF is never switched on. Otherwise return time in microsecond since boot when phy/rf was last switched on

esp_err_t esp_phy_update_country_info(const char *country)

Update the corresponding PHY init type according to the country code of Wi-Fi.

参数

country – country code

返回

ESP_OK on success.

返回

esp_err_t code describing the error on fail

char *get_phy_version_str(void)

Get PHY lib version.

返回

PHY lib version.

Structures

struct esp_phy_init_data_t

Structure holding PHY init parameters.

Public Members

uint8_t params[128]

opaque PHY initialization parameters

struct esp_phy_calibration_data_t

Opaque PHY calibration data.

Public Members

uint8_t version[4]

PHY version

uint8_t mac[6]

The MAC address of the station

uint8_t opaque[1894]

calibration data

Enumerations

enum esp_phy_calibration_mode_t

PHY calibration mode.

Values:

enumerator PHY_RF_CAL_PARTIAL

Do part of RF calibration. This should be used after power-on reset.

enumerator PHY_RF_CAL_NONE

Don’t do any RF calibration. This mode is only suggested to be used after deep sleep reset.

enumerator PHY_RF_CAL_FULL

Do full RF calibration. Produces best results, but also consumes a lot of time and current. Suggested to be used once.