diff --git a/components/esp_phy/CMakeLists.txt b/components/esp_phy/CMakeLists.txt index 9f3064e125..a604c446ea 100644 --- a/components/esp_phy/CMakeLists.txt +++ b/components/esp_phy/CMakeLists.txt @@ -14,13 +14,29 @@ else() set(srcs "src/phy_init.c") endif() -idf_component_register(SRCS "${srcs}" - INCLUDE_DIRS "include" "${idf_target}/include" - PRIV_REQUIRES nvs_flash - LDFRAGMENTS "${ldfragments}") - idf_build_get_property(build_dir BUILD_DIR) +if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN) + if(NOT EXISTS "${build_dir}/phy_multiple_init_data.bin") + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${idf_target}/phy_multiple_init_data.bin DESTINATION "${build_dir}") + endif() +endif() + +if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED) + idf_component_register(SRCS "${srcs}" + INCLUDE_DIRS "include" "${idf_target}/include" + PRIV_REQUIRES nvs_flash + LDFRAGMENTS "${ldfragments}" + EMBED_FILES "${build_dir}/phy_multiple_init_data.bin" + ) +else() + idf_component_register(SRCS "${srcs}" + INCLUDE_DIRS "include" "${idf_target}/include" + PRIV_REQUIRES nvs_flash + LDFRAGMENTS "${ldfragments}" + ) +endif() + set(target_name "${idf_target}") target_link_libraries(${COMPONENT_LIB} PUBLIC "-L \"${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}\"") @@ -47,12 +63,15 @@ if(link_binary_libs) endif() endif() -if(CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION) +if(CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION) idf_component_get_property(esp_common_dir esp_common COMPONENT_DIR) partition_table_get_partition_info(phy_partition_offset "--partition-type data --partition-subtype phy" "offset") - if(CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN) - set(phy_init_data_bin "${CMAKE_CURRENT_SOURCE_DIR}/phy_multiple_init_data.bin") + if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN) + set(phy_init_data_bin "${build_dir}/phy_multiple_init_data.bin") + if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED) + set(COMPONENT_EMBED_FILES "${build_dir}/phy_multiple_init_data.bin") + endif() else() set(phy_init_data_bin "${build_dir}/phy_init_data.bin") diff --git a/components/esp_phy/Kconfig b/components/esp_phy/Kconfig index e3bb40f3db..49a51eec33 100644 --- a/components/esp_phy/Kconfig +++ b/components/esp_phy/Kconfig @@ -1,6 +1,6 @@ menu "PHY" - config ESP32_PHY_CALIBRATION_AND_DATA_STORAGE + config ESP_PHY_CALIBRATION_AND_DATA_STORAGE bool "Store phy calibration data in NVS" default y help @@ -15,7 +15,7 @@ menu "PHY" 2.Because of your board design, each time when you do calibration, the result are too unstable. If unsure, choose 'y'. - menuconfig ESP32_PHY_INIT_DATA_IN_PARTITION + menuconfig ESP_PHY_INIT_DATA_IN_PARTITION bool "Use a partition to store PHY init data" default n help @@ -31,20 +31,20 @@ menu "PHY" If unsure, choose 'n'. - config ESP32_PHY_DEFAULT_INIT_IF_INVALID + config ESP_PHY_DEFAULT_INIT_IF_INVALID bool "Reset default PHY init data if invalid" default n - depends on ESP32_PHY_INIT_DATA_IN_PARTITION + depends on ESP_PHY_INIT_DATA_IN_PARTITION help If enabled, PHY init data will be restored to default if it cannot be verified successfully to avoid endless bootloops. If unsure, choose 'n'. - if ESP32_PHY_INIT_DATA_IN_PARTITION - config ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN + if ESP_PHY_INIT_DATA_IN_PARTITION + config ESP_PHY_MULTIPLE_INIT_DATA_BIN bool "Support multiple PHY init data bin" - depends on ESP32_PHY_INIT_DATA_IN_PARTITION + depends on ESP_PHY_INIT_DATA_IN_PARTITION default n help If enabled, the corresponding PHY init data type can be automatically switched @@ -57,9 +57,17 @@ menu "PHY" 3. Country configured by API esp_wifi_set_country() and the parameter policy is WIFI_COUNTRY_POLICY_AUTO. - config ESP32_PHY_INIT_DATA_ERROR + config ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED + bool "Support embedded multiple phy init data bin to app bin" + depends on ESP_PHY_MULTIPLE_INIT_DATA_BIN + default n + help + If enabled, multiple phy init data bin will embedded into app bin + If not enabled, multiple phy init data bin will still leave alone, and need to be flashed by users. + + config ESP_PHY_INIT_DATA_ERROR bool "Terminate operation when PHY init data error" - depends on ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN + depends on ESP_PHY_MULTIPLE_INIT_DATA_BIN default n help If enabled, when an error occurs while the PHY init data is updated, @@ -67,7 +75,7 @@ menu "PHY" If not enabled, the PHY init data will not be updated when an error occurs. endif - config ESP32_PHY_MAX_WIFI_TX_POWER + config ESP_PHY_MAX_WIFI_TX_POWER int "Max WiFi TX power (dBm)" range 10 20 default 20 @@ -75,11 +83,11 @@ menu "PHY" Set maximum transmit power for WiFi radio. Actual transmit power for high data rates may be lower than this setting. - config ESP32_PHY_MAX_TX_POWER + config ESP_PHY_MAX_TX_POWER int - default ESP32_PHY_MAX_WIFI_TX_POWER + default ESP_PHY_MAX_WIFI_TX_POWER - config ESP32_PHY_MAC_BB_PD + config ESP_PHY_MAC_BB_PD bool "Power down MAC and baseband of Wi-Fi and Bluetooth when PHY is disabled" depends on ((IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3) && FREERTOS_USE_TICKLESS_IDLE) default n @@ -89,7 +97,7 @@ menu "PHY" by a small amount but increases RAM use by approximately 4 KB(Wi-Fi only), 2 KB(Bluetooth only) or 5.3 KB(Wi-Fi + Bluetooth). - config ESP32_REDUCE_PHY_TX_POWER + config ESP_PHY_REDUCE_TX_POWER bool "Reduce PHY TX power when brownout reset" depends on ESP32_BROWNOUT_DET default y diff --git a/components/esp_phy/Makefile.projbuild b/components/esp_phy/Makefile.projbuild index d759446c3e..285d4b4276 100644 --- a/components/esp_phy/Makefile.projbuild +++ b/components/esp_phy/Makefile.projbuild @@ -1,9 +1,9 @@ -ifdef CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION +ifdef CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION ESP_PHY_COMPONENT_PATH := $(COMPONENT_PATH) -ifdef CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN -PHY_INIT_DATA_BIN = $(ESP_PHY_COMPONENT_PATH)/phy_multiple_init_data.bin +ifdef CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN +PHY_INIT_DATA_BIN = $(ESP_PHY_COMPONENT_PATH)/$(IDF_TARGET)/phy_multiple_init_data.bin else PHY_INIT_DATA_OBJ = $(BUILD_DIR_BASE)/phy_init_data.o PHY_INIT_DATA_BIN = $(BUILD_DIR_BASE)/phy_init_data.bin @@ -27,7 +27,7 @@ phy_init_data-flash: $(PHY_INIT_DATA_BIN) @echo "Flashing PHY init data..." $(PHY_INIT_DATA_FLASH_CMD) -ifndef CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN +ifndef CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN phy_init_data-clean: rm -f $(PHY_INIT_DATA_BIN) $(PHY_INIT_DATA_OBJ) @@ -37,4 +37,4 @@ endif all: phy_init_data flash: phy_init_data -endif # CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION +endif # CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION diff --git a/components/esp_phy/esp32/include/phy_init_data.h b/components/esp_phy/esp32/include/phy_init_data.h index 3d633a9084..36f5440caa 100644 --- a/components/esp_phy/esp32/include/phy_init_data.h +++ b/components/esp_phy/esp32/include/phy_init_data.h @@ -1,16 +1,8 @@ -// Copyright 2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef PHY_INIT_DATA_H #define PHY_INIT_DATA_H /* don't use #pragma once here, we compile this file sometimes */ @@ -23,11 +15,11 @@ #define PHY_INIT_MAGIC "PHYINIT" // define the lowest tx power as LOWEST_PHY_TX_POWER -#define PHY_TX_POWER_LOWEST LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 52) +#define PHY_TX_POWER_LOWEST LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 52) #define PHY_TX_POWER_OFFSET 44 #define PHY_TX_POWER_NUM 5 -#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN #define PHY_CRC_ALGORITHM 1 #define PHY_COUNTRY_CODE_LEN 2 #define PHY_INIT_DATA_TYPE_OFFSET 126 @@ -83,12 +75,12 @@ static const esp_phy_init_data_t phy_init_data= { { 0x18, 0x18, 0x18, - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 40, 78), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 40, 72), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 40, 66), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 40, 60), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 40, 56), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 40, 52), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 40, 78), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 40, 72), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 40, 66), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 40, 60), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 40, 56), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 40, 52), 0, 1, 1, @@ -150,7 +142,7 @@ static const esp_phy_init_data_t phy_init_data= { { static const char phy_init_magic_post[] = PHY_INIT_MAGIC; -#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN /** * @brief PHY init data control infomation structure */ diff --git a/components/esp_phy/phy_multiple_init_data.bin b/components/esp_phy/esp32/phy_multiple_init_data.bin similarity index 100% rename from components/esp_phy/phy_multiple_init_data.bin rename to components/esp_phy/esp32/phy_multiple_init_data.bin diff --git a/components/esp_phy/esp32c3/include/phy_init_data.h b/components/esp_phy/esp32c3/include/phy_init_data.h index bc5d1edd2a..7e458c4311 100644 --- a/components/esp_phy/esp32c3/include/phy_init_data.h +++ b/components/esp_phy/esp32c3/include/phy_init_data.h @@ -1,16 +1,8 @@ -// Copyright 2016-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef PHY_INIT_DATA_H #define PHY_INIT_DATA_H /* don't use #pragma once here, we compile this file sometimes */ @@ -27,11 +19,11 @@ extern "C" { #define PHY_INIT_MAGIC "PHYINIT" // define the lowest tx power as LOWEST_PHY_TX_POWER -#define PHY_TX_POWER_LOWEST LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 52) +#define PHY_TX_POWER_LOWEST LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 52) #define PHY_TX_POWER_OFFSET 44 #define PHY_TX_POWER_NUM 5 -#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN #define PHY_CRC_ALGORITHM 1 #define PHY_COUNTRY_CODE_LEN 2 #define PHY_INIT_DATA_TYPE_OFFSET 126 @@ -46,20 +38,20 @@ static const char __attribute__((section(".rodata"))) phy_init_magic_pre[] = PHY static const esp_phy_init_data_t phy_init_data= { { 0x00, 0x00, - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x50), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x50), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x50), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x4c), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x4c), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x48), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x4c), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x48), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x48), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x44), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x4a), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x46), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x46), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x42), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x50), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x50), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x50), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4c), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4c), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x48), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4c), + 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, 0x4a), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x46), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x46), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x42), 0x00, 0x00, 0x00, @@ -160,7 +152,7 @@ static const esp_phy_init_data_t phy_init_data= { { static const char __attribute__((section(".rodata"))) phy_init_magic_post[] = PHY_INIT_MAGIC; -#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN /** * @brief PHY init data control infomation structure */ diff --git a/components/esp_phy/esp32c3/phy_multiple_init_data.bin b/components/esp_phy/esp32c3/phy_multiple_init_data.bin new file mode 100644 index 0000000000..0f754a2c49 Binary files /dev/null and b/components/esp_phy/esp32c3/phy_multiple_init_data.bin differ diff --git a/components/esp_phy/esp32s2/include/phy_init_data.h b/components/esp_phy/esp32s2/include/phy_init_data.h index a17b7b910b..55f0cdc491 100644 --- a/components/esp_phy/esp32s2/include/phy_init_data.h +++ b/components/esp_phy/esp32s2/include/phy_init_data.h @@ -1,16 +1,8 @@ -// Copyright 2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef PHY_INIT_DATA_H #define PHY_INIT_DATA_H /* don't use #pragma once here, we compile this file sometimes */ @@ -27,11 +19,11 @@ extern "C" { #define PHY_INIT_MAGIC "PHYINIT" // define the lowest tx power as LOWEST_PHY_TX_POWER -#define PHY_TX_POWER_LOWEST LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 52) +#define PHY_TX_POWER_LOWEST LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 52) #define PHY_TX_POWER_OFFSET 44 #define PHY_TX_POWER_NUM 5 -#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN #define PHY_CRC_ALGORITHM 1 #define PHY_COUNTRY_CODE_LEN 2 #define PHY_INIT_DATA_TYPE_OFFSET 126 @@ -88,12 +80,12 @@ static const esp_phy_init_data_t phy_init_data= { { 0x18, 0x18, 0x18, - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 84), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 72), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 66), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 60), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 56), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 52), + 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, @@ -155,7 +147,7 @@ static const esp_phy_init_data_t phy_init_data= { { static const char phy_init_magic_post[] = PHY_INIT_MAGIC; -#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN /** * @brief PHY init data control infomation structure */ diff --git a/components/esp_phy/esp32s2/phy_multiple_init_data.bin b/components/esp_phy/esp32s2/phy_multiple_init_data.bin new file mode 100644 index 0000000000..61ce8eb8e9 Binary files /dev/null and b/components/esp_phy/esp32s2/phy_multiple_init_data.bin differ diff --git a/components/esp_phy/esp32s3/include/phy_init_data.h b/components/esp_phy/esp32s3/include/phy_init_data.h index 8624b3e7a7..88f56282d5 100644 --- a/components/esp_phy/esp32s3/include/phy_init_data.h +++ b/components/esp_phy/esp32s3/include/phy_init_data.h @@ -1,16 +1,8 @@ -// Copyright 2016-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #ifndef PHY_INIT_DATA_H #define PHY_INIT_DATA_H /* don't use #pragma once here, we compile this file sometimes */ @@ -27,11 +19,11 @@ extern "C" { #define PHY_INIT_MAGIC "PHYINIT" // define the lowest tx power as LOWEST_PHY_TX_POWER -#define PHY_TX_POWER_LOWEST LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 52) +#define PHY_TX_POWER_LOWEST LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 52) #define PHY_TX_POWER_OFFSET 44 #define PHY_TX_POWER_NUM 5 -#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN #define PHY_CRC_ALGORITHM 1 #define PHY_COUNTRY_CODE_LEN 2 #define PHY_INIT_DATA_TYPE_OFFSET 126 @@ -46,20 +38,20 @@ static const char phy_init_magic_pre[] = PHY_INIT_MAGIC; static const esp_phy_init_data_t phy_init_data= { { 0x00, 0x00, - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x50), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x50), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x50), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x4c), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x4c), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x48), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x4c), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x48), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x48), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x44), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x4a), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x46), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x46), - LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 0x42), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x50), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x50), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x50), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4c), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4c), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x48), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4c), + 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, 0x4a), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x46), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x46), + LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x42), 0x00, 0x00, 0x00, @@ -160,7 +152,7 @@ static const esp_phy_init_data_t phy_init_data= { { static const char phy_init_magic_post[] = PHY_INIT_MAGIC; -#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN /** * @brief PHY init data control infomation structure */ diff --git a/components/esp_phy/esp32s3/phy_multiple_init_data.bin b/components/esp_phy/esp32s3/phy_multiple_init_data.bin new file mode 100644 index 0000000000..0f754a2c49 Binary files /dev/null and b/components/esp_phy/esp32s3/phy_multiple_init_data.bin differ diff --git a/components/esp_phy/include/esp_phy_init.h b/components/esp_phy/include/esp_phy_init.h index f85d8b38b1..04068c7f38 100644 --- a/components/esp_phy/include/esp_phy_init.h +++ b/components/esp_phy/include/esp_phy_init.h @@ -1,16 +1,8 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once #include @@ -48,7 +40,7 @@ typedef enum { PHY_RF_CAL_FULL = 0x00000002 /*!< Do full RF calibration. Produces best results, but also consumes a lot of time and current. Suggested to be used once. */ } esp_phy_calibration_mode_t; -#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN /** * @brief PHY init data type */ @@ -220,7 +212,7 @@ int64_t esp_phy_rf_get_on_ts(void); esp_err_t esp_phy_update_country_info(const char *country); -#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN /** * @brief Apply PHY init bin to PHY * @return ESP_OK on success. diff --git a/components/esp_phy/include/phy.h b/components/esp_phy/include/phy.h index 51b972bb6c..c2a49ed203 100644 --- a/components/esp_phy/include/phy.h +++ b/components/esp_phy/include/phy.h @@ -1,16 +1,8 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once #include "esp_phy_init.h" diff --git a/components/esp_phy/sdkconfig.rename b/components/esp_phy/sdkconfig.rename index 64085678ce..17cee6d513 100644 --- a/components/esp_phy/sdkconfig.rename +++ b/components/esp_phy/sdkconfig.rename @@ -1,5 +1,14 @@ # sdkconfig replacement configurations for deprecated options formatted as # CONFIG_DEPRECATED_OPTION CONFIG_NEW_OPTION -CONFIG_MAC_BB_PD CONFIG_ESP32_PHY_MAC_BB_PD -CONFIG_REDUCE_PHY_TX_POWER CONFIG_ESP32_REDUCE_PHY_TX_POWER +CONFIG_MAC_BB_PD CONFIG_ESP32_PHY_MAC_BB_PD +CONFIG_REDUCE_PHY_TX_POWER CONFIG_ESP32_REDUCE_PHY_TX_POWER +CONFIG_ESP32_PHY_MAC_BB_PD CONFIG_ESP_PHY_MAC_BB_PD +CONFIG_ESP32_REDUCE_PHY_TX_POWER CONFIG_ESP_PHY_REDUCE_TX_POWER +CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE +CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION +CONFIG_ESP32_PHY_DEFAULT_INIT_IF_INVALID CONFIG_ESP_PHY_DEFAULT_INIT_IF_INVALID +CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN +CONFIG_ESP32_PHY_INIT_DATA_ERROR CONFIG_ESP_PHY_INIT_DATA_ERROR +CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER CONFIG_ESP_PHY_MAX_WIFI_TX_POWER +CONFIG_ESP32_PHY_MAX_TX_POWER CONFIG_ESP_PHY_MAX_TX_POWER diff --git a/components/esp_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c index 86e9925374..cac6bc9ebf 100644 --- a/components/esp_phy/src/phy_init.c +++ b/components/esp_phy/src/phy_init.c @@ -1,16 +1,8 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include @@ -78,7 +70,11 @@ static uint32_t* s_phy_digital_regs_mem = NULL; uint32_t* s_mac_bb_pd_mem = NULL; #endif -#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED +extern uint8_t multi_phy_init_data_bin_start[] asm("_binary_phy_multiple_init_data_bin_start"); +extern uint8_t multi_phy_init_data_bin_end[] asm("_binary_phy_multiple_init_data_bin_end"); +#endif /* The following static variables are only used by Wi-Fi tasks, so they can be handled without lock */ static phy_init_data_type_t s_phy_init_data_type = 0; @@ -317,12 +313,25 @@ IRAM_ATTR void esp_mac_bb_power_down(void) #endif // PHY init data handling functions -#if CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION +#if CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION #include "esp_partition.h" const esp_phy_init_data_t* esp_phy_get_init_data(void) { - const esp_partition_t* partition = esp_partition_find_first( + esp_err_t err = ESP_OK; + const esp_partition_t* partition = NULL; +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED + size_t init_data_store_length = sizeof(phy_init_magic_pre) + + sizeof(esp_phy_init_data_t) + sizeof(phy_init_magic_post); + uint8_t* init_data_store = (uint8_t*) malloc(init_data_store_length); + if (init_data_store == NULL) { + ESP_LOGE(TAG, "failed to allocate memory for updated country code PHY init data"); + return NULL; + } + memcpy(init_data_store, multi_phy_init_data_bin_start, init_data_store_length); + ESP_LOGI(TAG, "loading embedded multiple PHY init data"); +#else + partition = esp_partition_find_first( ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_PHY, NULL); if (partition == NULL) { ESP_LOGE(TAG, "PHY data partition not found"); @@ -337,17 +346,18 @@ const esp_phy_init_data_t* esp_phy_get_init_data(void) return NULL; } // read phy data from flash - esp_err_t err = esp_partition_read(partition, 0, init_data_store, init_data_store_length); + err = esp_partition_read(partition, 0, init_data_store, init_data_store_length); if (err != ESP_OK) { ESP_LOGE(TAG, "failed to read PHY data partition (0x%x)", err); free(init_data_store); return NULL; } +#endif // verify data if (memcmp(init_data_store, PHY_INIT_MAGIC, sizeof(phy_init_magic_pre)) != 0 || memcmp(init_data_store + init_data_store_length - sizeof(phy_init_magic_post), PHY_INIT_MAGIC, sizeof(phy_init_magic_post)) != 0) { -#ifndef CONFIG_ESP32_PHY_DEFAULT_INIT_IF_INVALID +#ifndef CONFIG_ESP_PHY_DEFAULT_INIT_IF_INVALID ESP_LOGE(TAG, "failed to validate PHY data partition"); free(init_data_store); return NULL; @@ -372,9 +382,9 @@ const esp_phy_init_data_t* esp_phy_get_init_data(void) free(init_data_store); return NULL; } -#endif // CONFIG_ESP32_PHY_DEFAULT_INIT_IF_INVALID +#endif // CONFIG_ESP_PHY_DEFAULT_INIT_IF_INVALID } -#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN if ((*(init_data_store + (sizeof(phy_init_magic_pre) + PHY_SUPPORT_MULTIPLE_BIN_OFFSET)))) { s_multiple_phy_init_data_bin = true; ESP_LOGI(TAG, "Support multiple PHY init data bins"); @@ -391,7 +401,7 @@ void esp_phy_release_init_data(const esp_phy_init_data_t* init_data) free((uint8_t*) init_data - sizeof(phy_init_magic_pre)); } -#else // CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION +#else // CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION // phy_init_data.h will declare static 'phy_init_data' variable initialized with default init data @@ -405,7 +415,7 @@ void esp_phy_release_init_data(const esp_phy_init_data_t* init_data) { // no-op } -#endif // CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION +#endif // CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION // PHY calibration data handling functions @@ -561,7 +571,7 @@ static esp_err_t store_cal_data_to_nvs_handle(nvs_handle_t handle, return err; } -#if CONFIG_ESP32_REDUCE_PHY_TX_POWER +#if CONFIG_ESP_PHY_REDUCE_TX_POWER // TODO: fix the esp_phy_reduce_tx_power unused warning for esp32s2 - IDF-759 static void __attribute((unused)) esp_phy_reduce_tx_power(esp_phy_init_data_t* init_data) { @@ -586,7 +596,7 @@ void esp_phy_load_cal_and_init(void) abort(); } -#if CONFIG_ESP32_REDUCE_PHY_TX_POWER +#if CONFIG_ESP_PHY_REDUCE_TX_POWER const esp_phy_init_data_t* phy_init_data = esp_phy_get_init_data(); if (phy_init_data == NULL) { ESP_LOGE(TAG, "failed to obtain PHY init data"); @@ -611,7 +621,7 @@ void esp_phy_load_cal_and_init(void) } #endif -#ifdef CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE +#ifdef CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE esp_phy_calibration_mode_t calibration_mode = PHY_RF_CAL_PARTIAL; uint8_t sta_mac[6]; if (esp_rom_get_reset_reason(0) == RESET_REASON_CORE_DEEP_SLEEP) { @@ -640,7 +650,7 @@ void esp_phy_load_cal_and_init(void) register_chipv7_phy(init_data, cal_data, PHY_RF_CAL_FULL); #endif -#if CONFIG_ESP32_REDUCE_PHY_TX_POWER +#if CONFIG_ESP_PHY_REDUCE_TX_POWER esp_phy_release_init_data(phy_init_data); free(init_data); #else @@ -650,7 +660,7 @@ void esp_phy_load_cal_and_init(void) free(cal_data); // PHY maintains a copy of calibration data, so we can free this } -#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN static esp_err_t phy_crc_check_init_data(uint8_t* init_data, const uint8_t* checksum, size_t init_data_length) { uint32_t crc_data = 0; @@ -716,14 +726,17 @@ static esp_err_t phy_get_multiple_init_data(const esp_partition_t* partition, ESP_LOGE(TAG, "failed to allocate memory for PHY init data control info"); return ESP_FAIL; } - - esp_err_t err = esp_partition_read(partition, init_data_store_length, init_data_control_info, sizeof(phy_control_info_data_t)); + esp_err_t err = ESP_OK; +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED + memcpy(init_data_control_info, multi_phy_init_data_bin_start + init_data_store_length, sizeof(phy_control_info_data_t)); +#else + err = esp_partition_read(partition, init_data_store_length, init_data_control_info, sizeof(phy_control_info_data_t)); if (err != ESP_OK) { free(init_data_control_info); ESP_LOGE(TAG, "failed to read PHY control info data partition (0x%x)", err); return ESP_FAIL; } - +#endif if ((init_data_control_info->check_algorithm) == PHY_CRC_ALGORITHM) { err = phy_crc_check_init_data(init_data_control_info->multiple_bin_checksum, init_data_control_info->control_info_checksum, sizeof(phy_control_info_data_t) - sizeof(init_data_control_info->control_info_checksum)); @@ -745,6 +758,9 @@ static esp_err_t phy_get_multiple_init_data(const esp_partition_t* partition, return ESP_FAIL; } +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED + memcpy(init_data_multiple, multi_phy_init_data_bin_start + init_data_store_length + sizeof(phy_control_info_data_t), sizeof(esp_phy_init_data_t) * init_data_control_info->number); +#else err = esp_partition_read(partition, init_data_store_length + sizeof(phy_control_info_data_t), init_data_multiple, sizeof(esp_phy_init_data_t) * init_data_control_info->number); if (err != ESP_OK) { @@ -753,7 +769,7 @@ static esp_err_t phy_get_multiple_init_data(const esp_partition_t* partition, ESP_LOGE(TAG, "failed to read PHY init data multiple bin partition (0x%x)", err); return ESP_FAIL; } - +#endif if ((init_data_control_info->check_algorithm) == PHY_CRC_ALGORITHM) { err = phy_crc_check_init_data(init_data_multiple, init_data_control_info->multiple_bin_checksum, sizeof(esp_phy_init_data_t) * init_data_control_info->number); @@ -785,6 +801,19 @@ static esp_err_t phy_get_multiple_init_data(const esp_partition_t* partition, esp_err_t esp_phy_update_init_data(phy_init_data_type_t init_data_type) { +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED + esp_err_t err = ESP_OK; + const esp_partition_t* partition = NULL; + size_t init_data_store_length = sizeof(phy_init_magic_pre) + + sizeof(esp_phy_init_data_t) + sizeof(phy_init_magic_post); + uint8_t* init_data_store = (uint8_t*) malloc(init_data_store_length); + if (init_data_store == NULL) { + ESP_LOGE(TAG, "failed to allocate memory for updated country code PHY init data"); + return ESP_ERR_NO_MEM; + } + memcpy(init_data_store, multi_phy_init_data_bin_start, init_data_store_length); + ESP_LOGI(TAG, "load embedded multi phy init data"); +#else const esp_partition_t* partition = esp_partition_find_first( ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_PHY, NULL); if (partition == NULL) { @@ -805,6 +834,7 @@ esp_err_t esp_phy_update_init_data(phy_init_data_type_t init_data_type) ESP_LOGE(TAG, "failed to read updated country code PHY data partition (0x%x)", err); return ESP_FAIL; } +#endif if (memcmp(init_data_store, PHY_INIT_MAGIC, sizeof(phy_init_magic_pre)) != 0 || memcmp(init_data_store + init_data_store_length - sizeof(phy_init_magic_post), PHY_INIT_MAGIC, sizeof(phy_init_magic_post)) != 0) { @@ -818,7 +848,7 @@ esp_err_t esp_phy_update_init_data(phy_init_data_type_t init_data_type) err = phy_get_multiple_init_data(partition, init_data_store, init_data_store_length, init_data_type); if (err != ESP_OK) { free(init_data_store); -#if CONFIG_ESP32_PHY_INIT_DATA_ERROR +#if CONFIG_ESP_PHY_INIT_DATA_ERROR abort(); #else return ESP_FAIL; @@ -848,7 +878,7 @@ esp_err_t esp_phy_update_init_data(phy_init_data_type_t init_data_type) esp_err_t esp_phy_update_country_info(const char *country) { -#if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN +#if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN uint8_t phy_init_data_type_map = 0; if (!s_multiple_phy_init_data_bin) { diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index 0c3f24cc83..681c8bfeb7 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit 0c3f24cc83d595f60e3b785e3eb098c3bc5ce2d3 +Subproject commit 681c8bfeb739c2fcd579e404b1df8b19acc07497 diff --git a/docs/en/api-guides/RF_calibration.rst b/docs/en/api-guides/RF_calibration.rst index 3d81b9eb19..df81000eec 100644 --- a/docs/en/api-guides/RF_calibration.rst +++ b/docs/en/api-guides/RF_calibration.rst @@ -13,7 +13,7 @@ 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 :ref:`CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE`. +To use this method, please go to ``menuconfig`` and enable :ref:`CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE`. Full calibration ---------------- @@ -31,7 +31,7 @@ Full calibration is triggered in the follwing conditions: 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 :ref:`CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE`. +To switch to the full calibration method, go to ``menuconfig`` and disable :ref:`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. @@ -51,10 +51,10 @@ There are two ways to get the PHY initialization data. One is the default initialization data which is located in the header file :idf_file:`components/esp_phy/{IDF_TARGET_PATH_NAME}/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 :ref:`CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION`. +To use the default initialization data, please go to ``menuconfig`` and disable :ref:`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 :ref:`CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION`. +To switch to the initialization data stored in a partition, go to ``menuconfig`` and enable :ref:`CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION`. diff --git a/docs/en/api-guides/partition-tables.rst b/docs/en/api-guides/partition-tables.rst index f0ec74944c..0cdebb72be 100644 --- a/docs/en/api-guides/partition-tables.rst +++ b/docs/en/api-guides/partition-tables.rst @@ -109,7 +109,7 @@ See enum :cpp:type:`esp_partition_subtype_t` for the full list of subtypes defin - ``phy`` (1) is for storing PHY initialisation data. This allows PHY to be configured per-device, instead of in firmware. - In the default configuration, the phy partition is not used and PHY initialisation data is compiled into the app itself. As such, this partition can be removed from the partition table to save space. - - To load PHY data from this partition, open the project configuration menu (``idf.py menuconfig``) and enable :ref:`CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION` option. You will also need to flash your devices with phy init data as the esp-idf build system does not do this automatically. + - To load PHY data from this partition, open the project configuration menu (``idf.py menuconfig``) and enable :ref:`CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION` option. You will also need to flash your devices with phy init data as the esp-idf build system does not do this automatically. - ``nvs`` (2) is for the :doc:`Non-Volatile Storage (NVS) API <../api-reference/storage/nvs_flash>`. - NVS is used to store per-device PHY calibration data (different to initialisation data). diff --git a/docs/zh_CN/api-guides/partition-tables.rst b/docs/zh_CN/api-guides/partition-tables.rst index 2efde1f858..1b380f6354 100644 --- a/docs/zh_CN/api-guides/partition-tables.rst +++ b/docs/zh_CN/api-guides/partition-tables.rst @@ -109,7 +109,7 @@ SubType 字段长度为 8 bit,内容与具体分区 Type 有关。目前,esp - ``phy`` (1) 分区用于存放 PHY 初始化数据,从而保证可以为每个设备单独配置 PHY,而非必须采用固件中的统一 PHY 初始化数据。 - 默认配置下,phy 分区并不启用,而是直接将 phy 初始化数据编译至应用程序中,从而节省分区表空间(直接将此分区删掉)。 - - 如果需要从此分区加载 phy 初始化数据,请打开项目配置菜单(``idf.py menuconfig``),并且使能 :ref:`CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION` 选项。此时,您还需要手动将 phy 初始化数据烧至设备 flash(esp-idf 编译系统并不会自动完成该操作)。 + - 如果需要从此分区加载 phy 初始化数据,请打开项目配置菜单(``idf.py menuconfig``),并且使能 :ref:`CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION` 选项。此时,您还需要手动将 phy 初始化数据烧至设备 flash(esp-idf 编译系统并不会自动完成该操作)。 - ``nvs`` (2) 是专门给 :doc:`非易失性存储 (NVS) API <../api-reference/storage/nvs_flash>` 使用的分区。 - 用于存储每台设备的 PHY 校准数据(注意,并不是 PHY 初始化数据)。 diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index bb101de637..1280cb7471 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -884,17 +884,9 @@ components/esp_netif/private_include/esp_netif_private.h components/esp_netif/test/test_esp_netif.c components/esp_netif/test_apps/component_ut_test.py components/esp_netif/test_apps/main/esp_netif_test.c -components/esp_phy/esp32/include/phy_init_data.h -components/esp_phy/esp32c3/include/phy_init_data.h components/esp_phy/esp32h2/include/phy_init_data.h -components/esp_phy/esp32s2/include/phy_init_data.h -components/esp_phy/esp32s3/include/phy_init_data.h -components/esp_phy/include/esp_phy_init.h -components/esp_phy/include/phy.h -components/esp_phy/src/phy_init.c components/esp_phy/src/phy_init_esp32hxx.c components/esp_phy/test/test_phy_rtc.c -components/esp_pm/include/esp32/pm.h components/esp_pm/include/esp32c3/pm.h components/esp_pm/include/esp32h2/pm.h components/esp_pm/include/esp32s2/pm.h diff --git a/tools/test_apps/phy/phy_multi_init_data_test/CMakeLists.txt b/tools/test_apps/phy/phy_multi_init_data_test/CMakeLists.txt new file mode 100644 index 0000000000..9c3b369e90 --- /dev/null +++ b/tools/test_apps/phy/phy_multi_init_data_test/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(phy_multi_init_data_test) diff --git a/tools/test_apps/phy/phy_multi_init_data_test/app_test.py b/tools/test_apps/phy/phy_multi_init_data_test/app_test.py new file mode 100644 index 0000000000..dbe0d75346 --- /dev/null +++ b/tools/test_apps/phy/phy_multi_init_data_test/app_test.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 +import glob +import os + +import tiny_test_fw +import ttfw_idf +from tiny_test_fw import Utility + + +@ttfw_idf.idf_custom_test(env_tag='Example_GENERIC', group='test-apps') +def test_phy_multi_init_data_bin(env, _): + # type: (tiny_test_fw.Env.Env, None) -> None + config_files = glob.glob(os.path.join(os.path.dirname(__file__), 'sdkconfig.ci.*')) + config_names = [os.path.basename(s).replace('sdkconfig.ci.', '') for s in config_files] + for name in config_names: + dut = env.get_dut('phy_multi_init_data_test', 'tools/test_apps/phy/phy_multi_init_data_test',app_config_name=name) + dut.start_app() + + if 'CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED' in dut.app.get_sdkconfig().keys(): + Utility.console_log('multi init data bin embed test') + dut.expect('load embedded multi phy init data') + else: + Utility.console_log('multi init data bin test') + dut.expect('Support multiple PHY init data bins') + + dut.expect('wifi_init finished') + Utility.console_log('Test Success') + + +if __name__ == '__main__': + test_phy_multi_init_data_bin() diff --git a/tools/test_apps/phy/phy_multi_init_data_test/main/CMakeLists.txt b/tools/test_apps/phy/phy_multi_init_data_test/main/CMakeLists.txt new file mode 100644 index 0000000000..ebe797b1c5 --- /dev/null +++ b/tools/test_apps/phy/phy_multi_init_data_test/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "phy_init_data_main.c" + INCLUDE_DIRS ".") diff --git a/tools/test_apps/phy/phy_multi_init_data_test/main/phy_init_data_main.c b/tools/test_apps/phy/phy_multi_init_data_test/main/phy_init_data_main.c new file mode 100644 index 0000000000..8c9953b1d3 --- /dev/null +++ b/tools/test_apps/phy/phy_multi_init_data_test/main/phy_init_data_main.c @@ -0,0 +1,55 @@ +/* + * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +/* test phy init data bin options + + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ +#include +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/event_groups.h" +#include "esp_system.h" +#include "esp_wifi.h" +#include "esp_event.h" +#include "esp_log.h" +#include "nvs_flash.h" + +static const char *TAG = "phy init"; +static EventGroupHandle_t s_wifi_event_group; + +void wifi_init(void) +{ + s_wifi_event_group = xEventGroupCreate(); + + ESP_ERROR_CHECK(esp_netif_init()); + + ESP_ERROR_CHECK(esp_event_loop_create_default()); + esp_netif_create_default_wifi_sta(); + + wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); + ESP_ERROR_CHECK(esp_wifi_init(&cfg)); + ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) ); + ESP_ERROR_CHECK(esp_wifi_start() ); + + ESP_LOGI(TAG, "wifi_init finished."); +} + +void app_main(void) +{ + //Initialize NVS + esp_err_t 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); + + wifi_init(); +} diff --git a/tools/test_apps/phy/phy_multi_init_data_test/sdkconfig.ci.phy_multiple_init_data b/tools/test_apps/phy/phy_multi_init_data_test/sdkconfig.ci.phy_multiple_init_data new file mode 100644 index 0000000000..05d129b95e --- /dev/null +++ b/tools/test_apps/phy/phy_multi_init_data_test/sdkconfig.ci.phy_multiple_init_data @@ -0,0 +1,3 @@ +CONFIG_ESP_PHY_DEFAULT_INIT_IF_INVALID=y +CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION=y +CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN=y diff --git a/tools/test_apps/phy/phy_multi_init_data_test/sdkconfig.ci.phy_multiple_init_data_embed b/tools/test_apps/phy/phy_multi_init_data_test/sdkconfig.ci.phy_multiple_init_data_embed new file mode 100644 index 0000000000..6246d196ee --- /dev/null +++ b/tools/test_apps/phy/phy_multi_init_data_test/sdkconfig.ci.phy_multiple_init_data_embed @@ -0,0 +1,4 @@ +CONFIG_ESP_PHY_DEFAULT_INIT_IF_INVALID=y +CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION=y +CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN=y +CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED=y diff --git a/tools/test_apps/system/build_test/sdkconfig.ci.phy_multiple_init_data b/tools/test_apps/system/build_test/sdkconfig.ci.phy_multiple_init_data index 8136f0c247..c1a4c0dce6 100644 --- a/tools/test_apps/system/build_test/sdkconfig.ci.phy_multiple_init_data +++ b/tools/test_apps/system/build_test/sdkconfig.ci.phy_multiple_init_data @@ -1,2 +1,2 @@ -CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION=y -CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN=y +CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION=y +CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN=y