From 462e9d4f81f68c4857cb4396750e305d3cbee1d1 Mon Sep 17 00:00:00 2001 From: Wu Jian Gang Date: Fri, 15 Jun 2018 01:07:00 +0800 Subject: [PATCH] feat(esp8266): Add phy init data in code Not support to config phy_init_data now, and need real code to use this data. --- components/esp8266/Kconfig | 36 +++++ components/esp8266/Makefile.projbuild | 39 +++++ components/esp8266/include/esp_phy_init.h | 37 +++++ components/esp8266/source/phy_init_data.h | 159 +++++++++++++++++++ components/partition_table/Kconfig.projbuild | 4 +- 5 files changed, 273 insertions(+), 2 deletions(-) create mode 100644 components/esp8266/include/esp_phy_init.h create mode 100644 components/esp8266/source/phy_init_data.h diff --git a/components/esp8266/Kconfig b/components/esp8266/Kconfig index a98c37f8..43fe2ded 100644 --- a/components/esp8266/Kconfig +++ b/components/esp8266/Kconfig @@ -5,3 +5,39 @@ config APP_OFFSET default 0x1000 endmenu + +menu PHY + +config ESP_PHY_CALIBRATION_AND_DATA_STORAGE + bool "Store phy calibration data in NVS" + default y + help + If this option is enabled, NVS will be initialized and calibration data will be loaded from there. + PHY calibration will be skipped on deep sleep wakeup. If calibration data is not found, full calibration + will be performed and stored in NVS. Normally, only partial calibration will be performed. + If this option is disabled, full calibration will be performed. + + If it's easy that your board calibrate bad data, choose 'n'. + Two cases for example, you should choose 'n': + 1.If your board is easy to be booted up with antenna disconnected. + 2.Because of your board design, each time when you do calibration, the result are too unstable. + If unsure, choose 'y'. + +config ESP_PHY_INIT_DATA_IN_PARTITION + bool "Use a partition to store PHY init data" + default n + help + If enabled, PHY init data will be loaded from a partition. + When using a custom partition table, make sure that PHY data + partition is included (type: 'data', subtype: 'phy'). + With default partition tables, this is done automatically. + If PHY init data is stored in a partition, it has to be flashed there, + otherwise runtime error will occur. + + If this option is not enabled, PHY init data will be embedded + into the application binary. + + If unsure, choose 'n'. + +endmenu # PHY + diff --git a/components/esp8266/Makefile.projbuild b/components/esp8266/Makefile.projbuild index afde6707..9a26e389 100644 --- a/components/esp8266/Makefile.projbuild +++ b/components/esp8266/Makefile.projbuild @@ -1,3 +1,5 @@ +ifdef CONFIG_ESP8266_LEGACY + BOOTLOADER_FIRMWARE_DIR := $(abspath $(COMPONENT_PATH))/firmware ESPTOOLPY_FLASHSIZE ?= $(CONFIG_ESPTOOLPY_FLASHSIZE) @@ -22,6 +24,43 @@ ESP_INIT_DATA_DEFAULT_BIN := $(BOOTLOADER_FIRMWARE_DIR)/esp_init_data_default.bi ESPTOOL_ALL_FLASH_ARGS += $(ESP_INIT_DATA_DEFAULT_BIN_OFFSET) $(ESP_INIT_DATA_DEFAULT_BIN) +else + +ifdef CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION + +PHY_INIT_DATA_OBJ = $(BUILD_DIR_BASE)/phy_init_data.o +PHY_INIT_DATA_BIN = $(BUILD_DIR_BASE)/phy_init_data.bin + +# Command to flash PHY init data partition +PHY_INIT_DATA_FLASH_CMD = $(ESPTOOLPY_SERIAL) write_flash $(CONFIG_PHY_DATA_OFFSET) $(PHY_INIT_DATA_BIN) +ESPTOOL_ALL_FLASH_ARGS += $(CONFIG_PHY_DATA_OFFSET) $(PHY_INIT_DATA_BIN) + +ESP8266_COMPONENT_PATH := $(COMPONENT_PATH) + +$(PHY_INIT_DATA_OBJ): $(ESP8266_COMPONENT_PATH)/source/phy_init_data.h $(BUILD_DIR_BASE)/include/sdkconfig.h + $(summary) CC $(notdir $@) + printf "#include \"source/phy_init_data.h\"\n" | $(CC) -I $(BUILD_DIR_BASE)/include -I $(ESP8266_COMPONENT_PATH) -I $(ESP8266_COMPONENT_PATH)/include -c -o $@ -xc - + +$(PHY_INIT_DATA_BIN): $(PHY_INIT_DATA_OBJ) + $(summary) BIN $(notdir $@) + $(OBJCOPY) -O binary $< $@ + +phy_init_data: $(PHY_INIT_DATA_BIN) + +phy_init_data-flash: $(BUILD_DIR_BASE)/phy_init_data.bin + @echo "Flashing PHY init data..." + $(PHY_INIT_DATA_FLASH_CMD) + +phy_init_data-clean: + rm -f $(PHY_INIT_DATA_BIN) $(PHY_INIT_DATA_OBJ) + +all: phy_init_data +flash: phy_init_data + +endif # CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION + +endif + # global CFLAGS for ESP8266 CFLAGS += -DMEMLEAK_DEBUG -DICACHE_FLASH diff --git a/components/esp8266/include/esp_phy_init.h b/components/esp8266/include/esp_phy_init.h new file mode 100644 index 00000000..35b979f7 --- /dev/null +++ b/components/esp8266/include/esp_phy_init.h @@ -0,0 +1,37 @@ +// Copyright 2018 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. + +#pragma once +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file PHY init parameters and API + */ + + +/** + * @brief Structure holding PHY init parameters + */ +typedef struct { + uint8_t params[128]; /*!< opaque PHY initialization parameters */ +} esp_phy_init_data_t; + +#ifdef __cplusplus +} +#endif + diff --git a/components/esp8266/source/phy_init_data.h b/components/esp8266/source/phy_init_data.h new file mode 100644 index 00000000..4fc62494 --- /dev/null +++ b/components/esp8266/source/phy_init_data.h @@ -0,0 +1,159 @@ +// Copyright 2018 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. + +#pragma once + +#include "esp_phy_init.h" +#include "sdkconfig.h" + +#define PHY_INIT_MAGIC "PHYINIT" + +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= { { + 0x05, + 0x00, + 0x04, + 0x02, + 0x05, + 0x05, + 0x05, + 0x02, + 0x05, + 0x00, + 0x04, + 0x05, + 0x05, + 0x04, + 0x05, + 0x05, + 0x04, + 0xfe, + 0xfd, + 0xff, + 0xf0, + 0xf0, + 0xf0, + 0xe0, + 0xe0, + 0xe0, + 0xe1, + 0x0a, + 0xff, + 0xff, + 0xf8, + 0x00, + 0xf8, + 0xf8, + 0x52, + 0x4e, + 0x4a, + 0x44, + 0x40, + 0x38, + 0x00, + 0x00, + 0x01, + 0x01, + 0x02, + 0x03, + 0x04, + 0x05, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x02, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0xe1, + 0x0a, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x01, + 0x93, + 0x43, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, +} }; + +static const char phy_init_magic_post[] = PHY_INIT_MAGIC; + diff --git a/components/partition_table/Kconfig.projbuild b/components/partition_table/Kconfig.projbuild index d2be8cea..61c2b238 100644 --- a/components/partition_table/Kconfig.projbuild +++ b/components/partition_table/Kconfig.projbuild @@ -42,7 +42,7 @@ config PARTITION_TABLE_OFFSET config PARTITION_TABLE_CUSTOM_PHY_DATA_OFFSET hex "PHY data partition offset" if PARTITION_TABLE_CUSTOM - depends on ESP32_PHY_INIT_DATA_IN_PARTITION + depends on ESP_PHY_INIT_DATA_IN_PARTITION default 0xf000 help If using a custom partition table, specify the offset in the flash @@ -63,7 +63,7 @@ config APP_OFFSET default 0x10000 # this is the factory app offset used by the default tables config PHY_DATA_OFFSET - depends on ESP32_PHY_INIT_DATA_IN_PARTITION + depends on ESP_PHY_INIT_DATA_IN_PARTITION hex default PARTITION_TABLE_CUSTOM_PHY_DATA_OFFSET if PARTITION_TABLE_CUSTOM default 0xf000 # this is the factory app offset used by the default tables