feat(esp8266): Add phy init data in code

Not support to config phy_init_data now, and need real code to use this data.
This commit is contained in:
Wu Jian Gang
2018-06-15 01:07:00 +08:00
parent 845179a695
commit 462e9d4f81
5 changed files with 273 additions and 2 deletions

View File

@ -5,3 +5,39 @@ config APP_OFFSET
default 0x1000 default 0x1000
endmenu 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

View File

@ -1,3 +1,5 @@
ifdef CONFIG_ESP8266_LEGACY
BOOTLOADER_FIRMWARE_DIR := $(abspath $(COMPONENT_PATH))/firmware BOOTLOADER_FIRMWARE_DIR := $(abspath $(COMPONENT_PATH))/firmware
ESPTOOLPY_FLASHSIZE ?= $(CONFIG_ESPTOOLPY_FLASHSIZE) 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) 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 # global CFLAGS for ESP8266
CFLAGS += -DMEMLEAK_DEBUG -DICACHE_FLASH CFLAGS += -DMEMLEAK_DEBUG -DICACHE_FLASH

View File

@ -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 <stdint.h>
#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

View File

@ -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;

View File

@ -42,7 +42,7 @@ config PARTITION_TABLE_OFFSET
config PARTITION_TABLE_CUSTOM_PHY_DATA_OFFSET config PARTITION_TABLE_CUSTOM_PHY_DATA_OFFSET
hex "PHY data partition offset" if PARTITION_TABLE_CUSTOM 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 default 0xf000
help help
If using a custom partition table, specify the offset in the flash 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 default 0x10000 # this is the factory app offset used by the default tables
config PHY_DATA_OFFSET config PHY_DATA_OFFSET
depends on ESP32_PHY_INIT_DATA_IN_PARTITION depends on ESP_PHY_INIT_DATA_IN_PARTITION
hex hex
default PARTITION_TABLE_CUSTOM_PHY_DATA_OFFSET if PARTITION_TABLE_CUSTOM default PARTITION_TABLE_CUSTOM_PHY_DATA_OFFSET if PARTITION_TABLE_CUSTOM
default 0xf000 # this is the factory app offset used by the default tables default 0xf000 # this is the factory app offset used by the default tables