From 7a9947f3c62b7d96c8a0051d1617f2f17bf4c830 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Fri, 7 Jan 2022 19:59:41 +0800 Subject: [PATCH] esp_phy: Update ESP32S2 phy lib to support eco1 chip --- .../src/bootloader_efuse_esp32s2.c | 5 +- components/efuse/esp32s2/esp_efuse_fields.c | 4 +- .../esp_phy/esp32s2/include/phy_init_data.h | 133 ++++++++++-------- components/esp_phy/include/phy.h | 9 +- components/esp_phy/lib | 2 +- components/esp_phy/src/phy_init.c | 6 +- 6 files changed, 95 insertions(+), 64 deletions(-) diff --git a/components/bootloader_support/src/bootloader_efuse_esp32s2.c b/components/bootloader_support/src/bootloader_efuse_esp32s2.c index 0b4334cf43..0ecabe7078 100644 --- a/components/bootloader_support/src/bootloader_efuse_esp32s2.c +++ b/components/bootloader_support/src/bootloader_efuse_esp32s2.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -12,8 +12,7 @@ uint8_t bootloader_common_get_chip_revision(void) { // should return the same value as esp_efuse_get_chip_ver() - /* No other revisions for ESP32-S2 */ - return 0; + return REG_GET_FIELD(EFUSE_RD_MAC_SPI_SYS_3_REG, EFUSE_WAFER_VERSION); } uint32_t bootloader_common_get_chip_ver_pkg(void) diff --git a/components/efuse/esp32s2/esp_efuse_fields.c b/components/efuse/esp32s2/esp_efuse_fields.c index 76c62d86e4..cd4af669b4 100644 --- a/components/efuse/esp32s2/esp_efuse_fields.c +++ b/components/efuse/esp32s2/esp_efuse_fields.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -25,7 +25,7 @@ uint8_t esp_efuse_get_chip_ver(void) { // should return the same value as bootloader_common_get_chip_revision() uint32_t chip_ver = 0; - // TODO: ESP32S2 does not have this field + esp_efuse_read_field_blob(ESP_EFUSE_WAFER_VERSION, &chip_ver, ESP_EFUSE_WAFER_VERSION[0]->bit_count); return chip_ver; } diff --git a/components/esp_phy/esp32s2/include/phy_init_data.h b/components/esp_phy/esp32s2/include/phy_init_data.h index 55f0cdc491..e1aa8d4613 100644 --- a/components/esp_phy/esp32s2/include/phy_init_data.h +++ b/components/esp_phy/esp32s2/include/phy_init_data.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -36,64 +36,76 @@ static const char phy_init_magic_pre[] = PHY_INIT_MAGIC; * @brief Structure containing default recommended PHY initialization parameters. */ static const esp_phy_init_data_t phy_init_data= { { - 3, - 0, - 0x04, - 0x05, - 0x04, - 0x05, - 0x05, - 0x04, - 0x06, - 0x06, - 0x06, - 0x05, - 0x06, + 0x80, + 0x00, + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4E), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4E), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x48), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x48), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x48), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x48), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x48), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x48), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x44), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x44), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x48), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x48), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x44), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x42), 0x00, 0x00, 0x00, - 0x00, - 0x05, - 0x09, - 0x06, - 0x05, - 0x03, - 0x06, - 0x05, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0x00, - 0xf4, - 0xf8, - 0xf8, - 0xf0, - 0xf0, - 0xf0, - 0xe0, - 0xe0, - 0xe0, - 0x18, - 0x18, - 0x18, - LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 84), - LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 72), - LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 66), - LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 60), - LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 56), - LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 52), - 0, - 1, - 1, - 2, - 2, - 3, - 4, - 5, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, 0, 0, 0, @@ -143,6 +155,15 @@ static const esp_phy_init_data_t phy_init_data= { { 0, 0, 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0xf1 } }; static const char phy_init_magic_post[] = PHY_INIT_MAGIC; diff --git a/components/esp_phy/include/phy.h b/components/esp_phy/include/phy.h index e6aa21db50..c8d1018288 100644 --- a/components/esp_phy/include/phy.h +++ b/components/esp_phy/include/phy.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -99,6 +99,13 @@ void phy_freq_mem_backup(bool backup_en, uint32_t *mem); void phy_bbpll_en_usb(bool en); #endif +#if CONFIG_IDF_TARGET_ESP32S2 +/** + * @brief Phy version select for ESP32S2 + */ +void phy_eco_version_sel(uint8_t chip_ver); +#endif + #ifdef __cplusplus } #endif diff --git a/components/esp_phy/lib b/components/esp_phy/lib index 4779ddaaf2..913918a349 160000 --- a/components/esp_phy/lib +++ b/components/esp_phy/lib @@ -1 +1 @@ -Subproject commit 4779ddaaf29e1d6aa2d26980103a1c1bbaa29462 +Subproject commit 913918a349a1f55a0e92f9ba4f842196792c6b1b diff --git a/components/esp_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c index 015030b0b5..3cb3ee53e7 100644 --- a/components/esp_phy/src/phy_init.c +++ b/components/esp_phy/src/phy_init.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -17,6 +17,7 @@ #include "esp_log.h" #include "nvs.h" #include "nvs_flash.h" +#include "esp_efuse.h" #include "sdkconfig.h" #include "freertos/FreeRTOS.h" #include "freertos/portmacro.h" @@ -623,6 +624,9 @@ void esp_phy_load_cal_and_init(void) char * phy_version = get_phy_version_str(); ESP_LOGI(TAG, "phy_version %s", phy_version); +#if CONFIG_IDF_TARGET_ESP32S2 + phy_eco_version_sel(esp_efuse_get_chip_ver()); +#endif esp_phy_calibration_data_t* cal_data = (esp_phy_calibration_data_t*) calloc(sizeof(esp_phy_calibration_data_t), 1); if (cal_data == NULL) {