ESP32-C3 supports three RF calibration methods during RF initialization:
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 is triggered in the follwing conditions:
NVS does not exist.
The NVS partition to store calibration data is erased.
Hardware MAC address is changed.
PHY library version is changed.
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.
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.
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 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/esp32c3/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.
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
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.
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.
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.
Enable BTBB module.
BTBB module should be enabled in order to use IEEE802154 or BT. Now BTBB enabling job is done automatically when start IEEE802154 or BT. Users should not call this API in their application.
Load calibration data from NVS and initialize PHY and RF module.
Initialize backup memory for Phy power up/down.
Deinitialize backup memory for Phy power up/down Set phy_init_flag if all modems deinit on ESP32C3.
Enable WiFi/BT common clock.
Disable WiFi/BT common clock.
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
Get PHY lib version.
PHY lib version.
Structure holding PHY init parameters.
opaque PHY initialization parameters
- uint8_t params
Opaque PHY calibration data.
PHY calibration mode.
Do part of RF calibration. This should be used after power-on reset.
Don’t do any RF calibration. This mode is only suggested to be used after deep sleep reset.
Do full RF calibration. Produces best results, but also consumes a lot of time and current. Suggested to be used once.
- enumerator PHY_RF_CAL_PARTIAL