Skip to content

Commit 8904f52

Browse files
committed
Allow phy to be initialized only if WiFi/BLE is used/enabled
fixes: #72
1 parent 57c3650 commit 8904f52

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

Diff for: cores/esp32/esp32-hal-misc.c

+45
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,51 @@
1818
#include "freertos/task.h"
1919
#include "esp_attr.h"
2020

21+
#if !CONFIG_ESP32_PHY_AUTO_INIT
22+
#include "nvs_flash.h"
23+
#include "esp_phy_init.h"
24+
#include "rom/rtc.h"
25+
void arduino_phy_init()
26+
{
27+
static bool initialized = false;
28+
if(initialized){
29+
return;
30+
}
31+
nvs_flash_init();
32+
esp_phy_calibration_mode_t calibration_mode = PHY_RF_CAL_PARTIAL;
33+
if (rtc_get_reset_reason(0) == DEEPSLEEP_RESET) {
34+
calibration_mode = PHY_RF_CAL_NONE;
35+
}
36+
const esp_phy_init_data_t* init_data = esp_phy_get_init_data();
37+
if (init_data == NULL) {
38+
printf("failed to obtain PHY init data\n");
39+
abort();
40+
}
41+
esp_phy_calibration_data_t* cal_data =
42+
(esp_phy_calibration_data_t*) calloc(sizeof(esp_phy_calibration_data_t), 1);
43+
if (cal_data == NULL) {
44+
printf("failed to allocate memory for RF calibration data\n");
45+
abort();
46+
}
47+
esp_err_t err = esp_phy_load_cal_data_from_nvs(cal_data);
48+
if (err != ESP_OK) {
49+
printf("failed to load RF calibration data, falling back to full calibration\n");
50+
calibration_mode = PHY_RF_CAL_FULL;
51+
}
52+
53+
esp_phy_init(init_data, calibration_mode, cal_data);
54+
55+
if (calibration_mode != PHY_RF_CAL_NONE) {
56+
err = esp_phy_store_cal_data_to_nvs(cal_data);
57+
} else {
58+
err = ESP_OK;
59+
}
60+
esp_phy_release_init_data(init_data);
61+
free(cal_data); // PHY maintains a copy of calibration data, so we can free this
62+
initialized = true;
63+
}
64+
#endif
65+
2166
uint32_t IRAM_ATTR micros()
2267
{
2368
uint32_t ccount;

Diff for: cores/esp32/esp32-hal.h

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ uint32_t millis();
6565
void delay(uint32_t);
6666
void delayMicroseconds(uint32_t us);
6767

68+
#if !CONFIG_ESP32_PHY_AUTO_INIT
69+
void arduino_phy_init();
70+
#endif
71+
6872
#if !CONFIG_AUTOSTART_ARDUINO
6973
void initArduino();
7074
#endif

Diff for: libraries/WiFi/src/WiFiGeneric.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ extern "C" {
5252
static bool _esp_wifi_initalized = false;
5353
extern void initWiFi()
5454
{
55+
#if !CONFIG_ESP32_PHY_AUTO_INIT
56+
arduino_phy_init();
57+
#endif
5558
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
5659
tcpip_adapter_init();
5760
esp_event_loop_init(&WiFiGenericClass::_eventCallback, NULL);

Diff for: tools/sdk/include/config/sdkconfig.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
#define CONFIG_PARTITION_TABLE_CUSTOM_FILENAME "partitions.csv"
5959
#define CONFIG_FREERTOS_ISR_STACKSIZE 1536
6060
#define CONFIG_OPTIMIZATION_LEVEL_DEBUG 1
61-
#define CONFIG_ESP32_PHY_AUTO_INIT 1
61+
#define CONFIG_ESP32_PHY_AUTO_INIT 0
6262
#define CONFIG_SYSTEM_EVENT_QUEUE_SIZE 32
6363
#define CONFIG_ESPTOOLPY_BAUD_921600B 1
6464
#define CONFIG_APP_OFFSET 0x10000

Diff for: tools/sdk/lib/libesp32.a

498 KB
Binary file not shown.

0 commit comments

Comments
 (0)