diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 068dfb7bc..52087c822 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -42,7 +42,7 @@ build_ssc: - git clone $GITLAB_SSH_SERVER/yinling/SSC.git - cd SSC # try checkout same branch - - git checkout "${CI_BUILD_REF_NAME}_8266" || echo "Using default branch..." + - git checkout release/v3.0_8266 || echo "Using default branch..." - ./gen_misc_rtos.sh push_master_to_github: diff --git a/README.md b/README.md index 7328d4db2..8532b6728 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,4 @@ # ** IMPORTANT NOTICE ** -## New release features -### v2.0.0 -1. Optimized memory distribution and usage, with an increased available memory of **70 KB**, up by approximately **20 KB** compared to the previous SDK; -2. Optimized protocol libraries, including the lwIP, ESPCONN, mbedTLS, OpenSSL and MQTT; -3. Optimized Wi-Fi functionality with enhanced reliability, and added support for active/passive scanning; -4. Updated boot loader to version 1.7 with increased stability; -5. Added support for the 64-Mbit and 128-Mbit SPI flash; -6. Added 5 new demos, i.e. websocket demo, Wi-Fi station machine demo, openssl server demo, openssl client demo and mqtt demo. - -For detail, you can refer to [v2.0.0](https://github.com/espressif/ESP8266_RTOS_SDK/releases/tag/v2.0.0) release notes. ## About this repository A new branching model is applied to this repository, which consists of a master branch and release branches. diff --git a/SUPPORT_POLICY_CN.md b/SUPPORT_POLICY_CN.md new file mode 100644 index 000000000..4dceb76ab --- /dev/null +++ b/SUPPORT_POLICY_CN.md @@ -0,0 +1,54 @@ +有关 ESP8266 RTOS SDK 的最新支持政策,详见 [支持期限政策](./SUPPORT_POLICY_CN.md)。 +支持期限政策 +================= + +* [English Version](./SUPPORT_POLICY_EN.md) + +ESP8266 RTOS SDK 的每个主要版本和次要版本(如 V3.0、V3.1 等)自其首次稳定版本发布之日起将维护 18 个月。 + +维护意味着 ESP8266 RTOS SDK 团队将会对 GitHub 上的发布分支继续进行 bug 修复、安全修补等,并根据需求定期发布新的 bugfix 版本。 + +在某一版本支持期限结束,停止更新维护 (EOL) 前,建议用户升级到较新的 ESP8266 RTOS SDK 版本。根据《支持期限政策》,我们将停止对 EOL 版本进行 bug 修复。 + +《支持期限政策》不适用于预发布版本(包括 beta、preview、`-rc` 和 `-dev` 版本等)。有时,在发布的版本中存在被标记为 "Preview" 的特定功能,则该功能也不在支持期限内。 + +长期支持版本 +------------ + +有些发布版本(例如 ESP8266 RTOS SDK V3.1)属于长期支持 (LTS) 版本。LTS 版本将自其首次稳定版本发布之日起维护 30 个月(2.5 年)。 + +关于长期维护版本,在 github 上面正式的`第1次`发布该版本 release 的时候,会在标题上额外标注 `(LTS)`,例如: + +``` +ESP8266 RTOS SDK Release v3.4 (LTS) +``` + +后续的维护版本不会再额外标注 `(LTS)`,例如: + +``` +ESP8266 RTOS SDK Release v3.4.1 +``` + +示例 +----- + +ESP8266 RTOS SDK V3.1 于 2019 年 01 月发布,属于 LTS 版本,自正式发布日开始将维护 30 个月至 2021 年 07 月停止。 + +- V3.1 的首个发布版本为 2019 年 01 月发布的 `v3.1`。 +- ESP8266 RTOS SDK 团队将持续进行 bug 修复、安全修补等更新,并 backport 至分支 `release/v3.1`。 +- 定期从 release 分支创建稳定的 bugfix 版本,比如,`v3.1.1`、`v3.1.2` 等,并建议用户保持使用最新的 bugfix 版本。 +- V3.1 的 bugfix 版本发布将持续 30 个月至 2021 年 07 月,届时所有 V3.1.x 将停止更新维护。 + +现有版本 +-------- + +ESP8266 RTOS SDK V3.3 及所有后续更新版本都将遵守该《支持期限政策》。每一版本发布时将同时公布其支持期限。 + +对于该政策公布之日前发布的其他版本,应适用下述支持期限: + +- ESP8266 RTOS SDK V3.3.x 将维护至 2021 年 12 月。 +- ESP8266 RTOS SDK V3.2.x 将维护至 2020 年 12 月。 +- ESP8266 RTOS SDK V3.1.x 作为长期维护版本,将维护至 2021 年 7 月。 +- ESP8266 RTOS SDK V3.0.x 将维护至 2020 年 10 月。 +- ESP8266 RTOS SDK V2.1.x 作为长期维护版本,将维护至 2021 年 4 月。 +- ESP8266 RTOS SDK V2.0.x 及之前的版本均已停止更新维护 (EOL)。 \ No newline at end of file diff --git a/SUPPORT_POLICY_EN.md b/SUPPORT_POLICY_EN.md new file mode 100644 index 000000000..cb8c5533e --- /dev/null +++ b/SUPPORT_POLICY_EN.md @@ -0,0 +1,56 @@ +The latest support policy for ESP8266 RTOS SDK can be found at [Support Policy](./SUPPORT_POLICY_EN.md). + +Support Period Policy +================= + +* [中文版](./SUPPORT_POLICY_CN.md) + +Each ESP8266 RTOS SDK major and minor release (V3.0, V3.1, etc) is supported for 18 months after the initial stable release date. + +Supported means that the ESP8266 RTOS SDK team will continue to apply bug fixes, security fixes, etc to the release branch on GitHub, and periodically make new bugfix releases as needed. + +Users are encouraged to upgrade to a newer ESP8266 RTOS SDK release before the support period finishes and the release becomes End of Life (EOL). It is our policy to not continue fixing bugs in End of Life releases. + +Pre-release versions (betas, previews, -rc and -dev versions, etc) are not covered by any support period. Sometimes a particular feature is marked as "Preview" in a release, which means it is also not covered by the support period. + + +Long Term Support releases +------------ + +Some releases (for example, ESP8266 RTOS SDK V3.1) are designated Long Term Support (LTS). LTS releases are supported for 30 months (2.5 years) after the initial stable release date. + +We will add a `(LTS)` tag when we release a long term support version on GitHub at the first time. For example: + +``` +ESP8266 RTOS SDK Release v3.4 (LTS) +``` + +But we will not add `(LTS)` tag to the following bug fix versions. For example: + +``` +ESP8266 RTOS SDK Release v3.4.1 +``` + +Example +----- + +ESP8266 RTOS SDK V3.1 was released in January 2019 and is a Long Term Support (LTS) release, meaning it will be supported for 30 months until July 2021. + +- The first V3.1 release was `v3.1` in January 2019. +- The ESP8266 RTOS SDK team continues to backport bug fixes, security fixes, etc to the release branch `release/v3.1`。 +- Periodically stable bugfix releases are created from the release branch. For example `v3.1.1`、`v3.1.2`, etc. Users are encouraged to always update to the latest bugfix release. +- V3.1 bugfix releases continue until July 2021, when all V3.1.x releases become End of Life. + +Existing Releases +-------- + +ESP8266 RTOS SDK V3.3 and all newer releases will follow this support period policy. The support period for each release will be announced when the release is made. + +For releases made before the support period policy was announced, the following support periods apply: + +- ESP8266 RTOS SDK V3.2.x will be supported until December 2021. +- ESP8266 RTOS SDK V3.2.x will be supported until December 2020. +- ESP8266 RTOS SDK V3.1.x is Long Term Support (LTS) release, will be supported until July 2021. +- ESP8266 RTOS SDK V3.0.x will be supported until October 2020. +- ESP8266 RTOS SDK V2.1.x is Long Term Support (LTS) release, will be supported until April 2021. +- ESP8266 RTOS SDK V2.0.x and earlier versions are already End of Life. diff --git a/components/app_update/esp_ota_ops.c b/components/app_update/esp_ota_ops.c index 1b0d9f2c5..9210e76fa 100644 --- a/components/app_update/esp_ota_ops.c +++ b/components/app_update/esp_ota_ops.c @@ -303,7 +303,6 @@ static esp_err_t esp_rewrite_ota_data(esp_partition_subtype_t subtype) uint16_t ota_app_count = 0; uint32_t i = 0; uint32_t seq; - const void *result = NULL; find_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL); if (find_partition != NULL) { @@ -327,6 +326,7 @@ static esp_err_t esp_rewrite_ota_data(esp_partition_subtype_t subtype) return ESP_ERR_INVALID_ARG; } #ifdef CONFIG_TARGET_PLATFORM_ESP32 + const void *result = NULL; static spi_flash_mmap_memory_t ota_data_map; ret = esp_partition_mmap(find_partition, 0, find_partition->size, SPI_FLASH_MMAP_DATA, &result, &ota_data_map); if (ret != ESP_OK) { @@ -343,13 +343,13 @@ static esp_err_t esp_rewrite_ota_data(esp_partition_subtype_t subtype) ret = spi_flash_read(find_partition->address, &s_ota_select[0], sizeof(ota_select)); if (ret != ESP_OK) { ESP_LOGE(TAG, "read failed"); - return NULL; + return ret; } ret = spi_flash_read(find_partition->address + 0x1000, &s_ota_select[1], sizeof(ota_select)); if (ret != ESP_OK) { ESP_LOGE(TAG, "read failed"); - return NULL; + return ret; } #endif @@ -465,7 +465,6 @@ const esp_partition_t *esp_ota_get_boot_partition(void) esp_err_t ret; const esp_partition_t *find_partition = NULL; - const void *result = NULL; uint16_t ota_app_count = 0; find_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL); @@ -475,6 +474,7 @@ const esp_partition_t *esp_ota_get_boot_partition(void) } #ifdef CONFIG_TARGET_PLATFORM_ESP32 + const void *result = NULL; static spi_flash_mmap_memory_t ota_data_map; ret = esp_partition_mmap(find_partition, 0, find_partition->size, SPI_FLASH_MMAP_DATA, &result, &ota_data_map); if (ret != ESP_OK) { diff --git a/components/bootloader/subproject/main/component.mk b/components/bootloader/subproject/main/component.mk index fd4cc90c4..76688a32d 100644 --- a/components/bootloader/subproject/main/component.mk +++ b/components/bootloader/subproject/main/component.mk @@ -10,6 +10,6 @@ LINKER_SCRIPTS := \ $(IDF_PATH)/components/esp8266/ld/esp8266.rom.ld \ esp8266.bootloader.rom.ld -COMPONENT_ADD_LDFLAGS += -L $(COMPONENT_PATH) $(addprefix -T ,$(LINKER_SCRIPTS)) +COMPONENT_ADD_LDFLAGS += -L $(IDF_PATH)/components/esp8266/lib -lcore -L $(COMPONENT_PATH) $(addprefix -T ,$(LINKER_SCRIPTS)) COMPONENT_ADD_LINKER_DEPS := $(LINKER_SCRIPTS) diff --git a/components/bootloader/subproject/main/esp8266.bootloader.rom.ld b/components/bootloader/subproject/main/esp8266.bootloader.rom.ld index 948b8a9cb..a9e485592 100644 --- a/components/bootloader/subproject/main/esp8266.bootloader.rom.ld +++ b/components/bootloader/subproject/main/esp8266.bootloader.rom.ld @@ -1,6 +1,7 @@ PROVIDE ( ets_memcpy = 0x400018b4 ); -PROVIDE ( ets_printf = 0x400024cc ); PROVIDE ( SPIRead = 0x40004b1c ); -PROVIDE ( xthal_get_ccount = 0x4000dd38 ); \ No newline at end of file +PROVIDE ( xthal_get_ccount = 0x4000dd38 ); +PROVIDE ( uart_div_modify = 0x400039d8 ); +PROVIDE ( ets_io_vprintf = 0x40001f00 ); \ No newline at end of file diff --git a/components/bootloader_support/src/bootloader_init.c b/components/bootloader_support/src/bootloader_init.c index c876f0f41..adcb8292e 100644 --- a/components/bootloader_support/src/bootloader_init.c +++ b/components/bootloader_support/src/bootloader_init.c @@ -547,6 +547,14 @@ void __assert_func(const char *file, int line, const char *func, const char *exp #include "esp_flash_partitions.h" #include "bootloader_flash.h" +#include "esp8266/uart_register.h" +#include "esp8266/eagle_soc.h" +#include "esp8266/gpio_register.h" +#include "esp8266/pin_mux_register.h" +#include "esp8266/rom_functions.h" + +#define BOOTLOADER_CONSOLE_CLK_FREQ 52 * 1000 * 1000 + extern int _bss_start; extern int _bss_end; extern int _data_start; @@ -558,6 +566,38 @@ static esp_err_t bootloader_main(); static void print_flash_info(const esp_image_header_t* pfhdr); static void update_flash_config(const esp_image_header_t* pfhdr); +static void uart_console_configure(void) +{ +#if CONFIG_CONSOLE_UART_SWAP_IO + while (READ_PERI_REG(UART_STATUS(0)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S)); + + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_UART0_CTS); + PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_UART0_RTS); + + // UART0: TXD <-> RTS and RXD <-> CTS + SET_PERI_REG_MASK(UART_SWAP_REG, 0x4); +#endif + +#if CONFIG_CONSOLE_UART_NUM == 1 + PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK); + + CLEAR_PERI_REG_MASK(UART_CONF1(CONFIG_CONSOLE_UART_NUM), UART_RX_FLOW_EN); + CLEAR_PERI_REG_MASK(UART_CONF0(CONFIG_CONSOLE_UART_NUM), UART_TX_FLOW_EN); + + WRITE_PERI_REG(UART_CONF0(CONFIG_CONSOLE_UART_NUM), + 0 // None parity + | (1 << 4) // 1-bit stop + | (3 << 2) // 8-bit data + | 0 // None flow control + | 0); // None Inverse + + SET_PERI_REG_MASK(UART_CONF0(CONFIG_CONSOLE_UART_NUM), UART_RXFIFO_RST | UART_TXFIFO_RST); + CLEAR_PERI_REG_MASK(UART_CONF0(CONFIG_CONSOLE_UART_NUM), UART_RXFIFO_RST | UART_TXFIFO_RST); +#endif + + uart_div_modify(CONFIG_CONSOLE_UART_NUM, BOOTLOADER_CONSOLE_CLK_FREQ / CONFIG_CONSOLE_UART_BAUDRATE); +} + esp_err_t bootloader_init() { //Clear bss @@ -571,6 +611,8 @@ esp_err_t bootloader_init() static esp_err_t bootloader_main() { + uart_console_configure(); + esp_image_header_t fhdr; if (bootloader_flash_read(ESP_BOOTLOADER_OFFSET, &fhdr, sizeof(esp_image_header_t), true) != ESP_OK) { ESP_LOGE(TAG, "failed to load bootloader header!"); @@ -581,6 +623,9 @@ static esp_err_t bootloader_main() ESP_LOGI(TAG, "compile time " __TIME__ ); + extern void phy_reg_default(void); + phy_reg_default(); + print_flash_info(&fhdr); update_flash_config(&fhdr); diff --git a/components/esp8266/CMakeLists.txt b/components/esp8266/CMakeLists.txt index 1072abb34..6bcf76ad3 100644 --- a/components/esp8266/CMakeLists.txt +++ b/components/esp8266/CMakeLists.txt @@ -11,8 +11,8 @@ register_component() target_link_libraries(${COMPONENT_NAME} "-L ${CMAKE_CURRENT_SOURCE_DIR}/lib") if(NOT CONFIG_NO_BLOBS) - target_link_libraries(${COMPONENT_NAME} airkiss crypto espnow gcc hal core mirom - net80211 phy pp pwm smartconfig ssc wpa cirom) + target_link_libraries(${COMPONENT_NAME} crypto gcc hal core + net80211 phy pp smartconfig ssc wpa) endif() target_link_libraries(${COMPONENT_NAME} "-u call_user_start") diff --git a/components/esp8266/Kconfig b/components/esp8266/Kconfig index 84cbd91f9..a69952cc0 100644 --- a/components/esp8266/Kconfig +++ b/components/esp8266/Kconfig @@ -35,6 +35,34 @@ config SOC_FULL_ICACHE Enable this option, full 32 KB iram instead of 16 KB iram will be used as icache, so the heap use can use may reduce a lot. +choice CONSOLE_UART_NUM + prompt "UART peripheral to use for console output (0-1)" + default CONSOLE_UART_CUSTOM_NUM_0 + help + Configrate output console UART for "ets_printf", "printf", "ESP_LOGX" and so on. + +config CONSOLE_UART_CUSTOM_NUM_0 + bool "UART0" +config CONSOLE_UART_CUSTOM_NUM_1 + bool "UART1" +endchoice + +config CONSOLE_UART_NUM + int + default 0 if CONSOLE_UART_CUSTOM_NUM_0 + default 1 if CONSOLE_UART_CUSTOM_NUM_1 + +config CONSOLE_UART_BAUDRATE + int "UART console baud rate" + default 74880 + range 1200 4000000 + +config CONSOLE_UART_SWAP_IO + bool "Swap UART0 I/O pins" + default n + help + Enable this option, UART0's I/O pins are swaped: TXD <-> RTS, RTX <-> CTS. + endmenu menu WIFI diff --git a/components/esp8266/component.mk b/components/esp8266/component.mk index dbac7f727..251d657a0 100644 --- a/components/esp8266/component.mk +++ b/components/esp8266/component.mk @@ -11,8 +11,8 @@ COMPONENT_SRCDIRS := driver source LIBS ?= ifndef CONFIG_NO_BLOBS -LIBS += airkiss crypto espnow gcc hal core net80211 \ - phy pp pwm smartconfig ssc wpa +LIBS += crypto gcc hal core net80211 \ + phy pp smartconfig ssc wpa endif #Linker scripts used to link the final application. diff --git a/components/esp8266/driver/gpio.c b/components/esp8266/driver/gpio.c index a1c5d5460..aee84cca9 100644 --- a/components/esp8266/driver/gpio.c +++ b/components/esp8266/driver/gpio.c @@ -86,7 +86,10 @@ static gpio_isr_func_t *gpio_isr_func = NULL; esp_err_t gpio_pullup_en(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); - GPIO_CHECK(!RTC_GPIO_IS_VALID_GPIO(gpio_num), "The RTC GPIO of esp8266 can not be pulled up.", ESP_ERR_INVALID_ARG); + + if (RTC_GPIO_IS_VALID_GPIO(gpio_num)) { + return ESP_OK; + } gpio_pin_reg_t pin_reg; pin_reg.val = READ_PERI_REG(GPIO_PIN_REG(gpio_num)); @@ -98,7 +101,10 @@ esp_err_t gpio_pullup_en(gpio_num_t gpio_num) esp_err_t gpio_pullup_dis(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); - GPIO_CHECK(!RTC_GPIO_IS_VALID_GPIO(gpio_num), "The RTC GPIO of esp8266 can not be pulled up.", ESP_ERR_INVALID_ARG); + + if (RTC_GPIO_IS_VALID_GPIO(gpio_num)) { + return ESP_OK; + } gpio_pin_reg_t pin_reg; pin_reg.val = READ_PERI_REG(GPIO_PIN_REG(gpio_num)); @@ -110,7 +116,10 @@ esp_err_t gpio_pullup_dis(gpio_num_t gpio_num) esp_err_t gpio_pulldown_en(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); - GPIO_CHECK(RTC_GPIO_IS_VALID_GPIO(gpio_num), "The GPIO of esp8266 can not be pulled down except RTC GPIO.", ESP_ERR_INVALID_ARG); + + if (!RTC_GPIO_IS_VALID_GPIO(gpio_num)) { + return ESP_OK; + } gpio_pin_reg_t pin_reg; pin_reg.val = READ_PERI_REG(GPIO_PIN_REG(gpio_num)); @@ -122,7 +131,10 @@ esp_err_t gpio_pulldown_en(gpio_num_t gpio_num) esp_err_t gpio_pulldown_dis(gpio_num_t gpio_num) { GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); - GPIO_CHECK(RTC_GPIO_IS_VALID_GPIO(gpio_num), "The GPIO of esp8266 can not be pulled down except RTC GPIO.", ESP_ERR_INVALID_ARG); + + if (!RTC_GPIO_IS_VALID_GPIO(gpio_num)) { + return ESP_OK; + } gpio_pin_reg_t pin_reg; pin_reg.val = READ_PERI_REG(GPIO_PIN_REG(gpio_num)); diff --git a/components/esp8266/include/airkiss.h b/components/esp8266/include/airkiss.h deleted file mode 100644 index 79d2d9a06..000000000 --- a/components/esp8266/include/airkiss.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - * airkiss.h - * - * Created on: 2015-1-26 - * Author: peterfan - */ - -#ifndef AIRKISS_H_ -#define AIRKISS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - - -typedef void* (*airkiss_memset_fn) (void* ptr, int value, unsigned int num); -typedef void* (*airkiss_memcpy_fn) (void* dst, const void* src, unsigned int num); -typedef int (*airkiss_memcmp_fn) (const void* ptr1, const void* ptr2, unsigned int num); -typedef int (*airkiss_printf_fn) (const char* format, ...); - - - -typedef struct -{ - airkiss_memset_fn memset; - airkiss_memcpy_fn memcpy; - airkiss_memcmp_fn memcmp; - airkiss_printf_fn printf; - -} airkiss_config_t; - -/** \defgroup WiFi_APIs WiFi Related APIs - * @brief WiFi APIs - */ - -/** @addtogroup WiFi_APIs - * @{ - */ - -/** \defgroup AirKiss_APIs AirKiss APIs - * @brief AirKiss APIs - * - * API airkiss_lan_recv and airkiss_lan_pack are provided for the function that AirKiss can detect - * the ESP8266 devices in LAN, more details about AirKiss please refer to WeChat : http://iot.weixin.qq.com. - * - * Workflow : Create a UDP transmission. When UDP data is received, call API airkiss_lan_recv and - * input the UDP data, if the airkiss_lan_recv returns AIRKISS_LAN_SSDP_REQ, airkiss_lan_pack - * can be called to make a response packet. - * - */ - -/** @addtogroup AirKiss_APIs - * @{ - */ - -/** - * @brief Get the version information of AirKiss lib. - * - * @attention The lenth of version is unknown - * - * @param null. - * - * @return the version information of AirKiss lib - */ - -const char* airkiss_version(void); - - -typedef enum -{ - /** the length of the data buffer is lack*/ - AIRKISS_LAN_ERR_OVERFLOW = -5, - - /** Do not support the type of instruction */ - AIRKISS_LAN_ERR_CMD = -4, - - /** Error reading data package */ - AIRKISS_LAN_ERR_PAKE = -3, - - /** Error function passing parameters */ - AIRKISS_LAN_ERR_PARA = -2, - - /** Packet data error */ - AIRKISS_LAN_ERR_PKG = -1, - - /** Message format is correct */ - AIRKISS_LAN_CONTINUE = 0, - - /** Find equipment request packet is received */ - AIRKISS_LAN_SSDP_REQ = 1, - - /** Packet packaging complete */ - AIRKISS_LAN_PAKE_READY = 2 - - -} airkiss_lan_ret_t; - - -typedef enum -{ - AIRKISS_LAN_SSDP_REQ_CMD = 0x1, - AIRKISS_LAN_SSDP_RESP_CMD = 0x1001, - AIRKISS_LAN_SSDP_NOTIFY_CMD = 0x1002 -} airkiss_lan_cmdid_t; - -/** - * @brief Parse the UDP packet sent by AirKiss. - * - * @param const void* body : the start of the UDP message body data pointer. - * @param unsigned short length : the effective length of data. - * @param const airkiss_config_t* config : input struct airkiss_config_t - * - * @return >=0 : succeed (reference airkiss_lan_ret_t) - * @return <0 : error code (reference airkiss_lan_ret_t) - */ - -int airkiss_lan_recv(const void* body, unsigned short length, const airkiss_config_t* config); - - -/** - * @brief Packaging the UDP packet. - * - * @param airkiss_lan_cmdid_t ak_lan_cmdid : type of the packet. - * @param void* appid : Vendor's Wechat public number id, got from WeChat. - * @param void* deviceid : device model id, got from WeChat. - * @param void* _datain : user data waiting for packet assembly. - * @param unsigned short inlength : the lenth of user data. - * @param void* _dataout : data buffer addr, to store the packet got by _datain packet assembly. - * @param unsigned short* outlength : the size of data buffer. - * @param const airkiss_config_t* config : input struct airkiss_config_t - * - * @return >=0 : succeed (reference airkiss_lan_ret_t) - * @return <0 : error code (reference airkiss_lan_ret_t) - */ - -int airkiss_lan_pack(airkiss_lan_cmdid_t ak_lan_cmdid, void* appid, void* deviceid, void* _datain, unsigned short inlength, void* _dataout, unsigned short* outlength, const airkiss_config_t* config); - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* AIRKISS_H_ */ diff --git a/components/esp8266/include/espnow.h b/components/esp8266/include/espnow.h deleted file mode 100644 index 81e738861..000000000 --- a/components/esp8266/include/espnow.h +++ /dev/null @@ -1,353 +0,0 @@ -/* - * ESPRSSIF MIT License - * - * Copyright (c) 2015 - * - * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, - * it is free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#ifndef __ESPNOW_H__ -#define __ESPNOW_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** \defgroup ESPNow_APIs ESP-NOW APIs - * @brief ESP-NOW APIs - * - * @attention 1. ESP-NOW do not support broadcast and multicast. - * @attention 2. ESP-NOW is targeted to Smart-Light project, so it is suggested - * that slave role corresponding to soft-AP or soft-AP+station mode, - * controller role corresponding to station mode. - * @attention 3. When ESP8266 is in soft-AP+station mode, it will communicate through - * station interface if it is in slave role, and communicate through - * soft-AP interface if it is in controller role. - * @attention 4. ESP-NOW can not wake ESP8266 up from sleep, so if the target ESP8266 - * station is in sleep, ESP-NOW communication will fail. - * @attention 5. In station mode, ESP8266 supports 10 encrypt ESP-NOW peers at most, - * with the unencrypted peers, it can be 20 peers in total at most. - * @attention 6. In the soft-AP mode or soft-AP + station mode, the ESP8266 supports - * 6 encrypt ESP-NOW peers at most, with the unencrypted peers, it can - * be 20 peers in total at most. - * - */ - -/** @addtogroup ESPNow_APIs - * @{ - */ - -enum esp_now_role { - ESP_NOW_ROLE_IDLE = 0, - ESP_NOW_ROLE_CONTROLLER, - ESP_NOW_ROLE_SLAVE, - ESP_NOW_ROLE_MAX, -}; - -/** - * @brief ESP-NOW send callback. - * - * @attention The status will be OK, if ESP-NOW send packet successfully. But users - * need to make sure by themselves that key of communication is correct. - * - * @param uint8_t *mac_addr : MAC address of target device - * @param uint8_t *data : data received - * @param uint8_t len : data length - * - * @return null - */ -typedef void (*esp_now_recv_cb_t)(uint8_t *mac_addr, uint8_t *data, uint8_t len); - -/** - * @brief ESP-NOW send callback. - * - * @attention The status will be OK, if ESP-NOW send packet successfully. But users - * need to make sure by themselves that key of communication is correct. - * - * @param uint8_t *mac_addr : MAC address of target device - * @param uint8_t status : status of ESP-NOW sending packet, 0, OK; 1, fail. - * - * @return null - */ -typedef void (*esp_now_send_cb_t)(uint8_t *mac_addr, uint8_t status); - -/** - * @brief ESP-NOW initialization. - * - * @param null - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_init(void); - -/** - * @brief Deinitialize ESP-NOW. - * - * @param null - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_deinit(void); - -/** - * @brief Register ESP-NOW send callback. - * - * @param esp_now_send_cb_t cb : send callback - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_register_send_cb(esp_now_send_cb_t cb); - -/** - * @brief Unregister ESP-NOW send callback. - * - * @param null - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_unregister_send_cb(void); - -/** - * @brief Register ESP-NOW receive callback. - * - * @param esp_now_recv_cb_t cb : receive callback - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_register_recv_cb(esp_now_recv_cb_t cb); - -/** - * @brief Unregister ESP-NOW receive callback. - * - * @param null - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_unregister_recv_cb(void); - -/** - * @brief Send ESP-NOW packet. - * - * @param uint8 *da : destination MAC address. - * If it's NULL, send packet to all MAC addresses recorded - * by ESP-NOW; otherwise, send packet to target MAC address. - * @param uint8 *data : data need to send - * @param uint8 len : data length - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_send(uint8_t *da, uint8_t *data, uint8_t len); - -/** - * @brief Add an ESP-NOW peer, store MAC address of target device into ESP-NOW MAC list. - * - * @param uint8 *mac_addr : MAC address of device - * @param uint8 role : role type of device, enum esp_now_role - * @param uint8 channel : channel of device - * @param uint8 *key : 16 bytes key which is needed for ESP-NOW communication - * @param uint8 key_len : length of key, has to be 16 bytes now - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_add_peer(uint8_t *mac_addr, uint8_t role, uint8_t channel, uint8_t *key, uint8_t key_len); - -/** - * @brief Delete an ESP-NOW peer, delete MAC address of the device from ESP-NOW MAC list. - * - * @param u8 *mac_addr : MAC address of device - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_del_peer(uint8_t *mac_addr); - -/** - * @brief Set ESP-NOW role of device itself. - * - * @param uint8_t role : role type of device, enum esp_now_role. - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_set_self_role(uint8_t role); - -/** - * @brief Get ESP-NOW role of device itself. - * - * @param uint8 role : role type of device, enum esp_now_role. - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_get_self_role(void); - -/** - * @brief Set ESP-NOW role for a target device. If it is set multiple times, - * new role will cover the old one. - * - * @param uint8 *mac_addr : MAC address of device. - * @param uint8 role : role type, enum esp_now_role. - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_set_peer_role(uint8_t *mac_addr, uint8_t role); - -/** - * @brief Get ESP-NOW role of a target device. - * - * @param uint8_t *mac_addr : MAC address of device. - * - * @return ESP_NOW_ROLE_CONTROLLER, role type : controller - * @return ESP_NOW_ROLE_SLAVE, role type : slave - * @return otherwise : fail - */ -int32_t esp_now_get_peer_role(uint8_t *mac_addr); - -/** - * @brief Record channel information of a ESP-NOW device. - * - * When communicate with this device, - * - call esp_now_get_peer_channel to get its channel first, - * - then call wifi_set_channel to be in the same channel and do communication. - * - * @param uint8_t *mac_addr : MAC address of target device. - * @param uint8_t channel : channel, usually to be 1 ~ 13, some area may use channel 14. - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_set_peer_channel(uint8_t *mac_addr, uint8_t channel); - -/** - * @brief Get channel information of a ESP-NOW device. - * - * @attention ESP-NOW communication needs to be at the same channel. - * - * @param uint8_t *mac_addr : MAC address of target device. - * - * @return 1 ~ 13 (some area may get 14) : channel number - * @return Non-0 : fail - */ -int32_t esp_now_get_peer_channel(uint8_t *mac_addr); - -/** - * @brief Set ESP-NOW key for a target device. - * - * If it is set multiple times, new key will cover the old one. - * - * @param uint8_t *mac_addr : MAC address of target device. - * @param uint8_t *key : 16 bytes key which is needed for ESP-NOW communication, - * if it is NULL, current key will be reset to be none. - * @param uint8_t key_len : key length, has to be 16 bytes now - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_set_peer_key(uint8_t *mac_addr, uint8_t *key, uint8_t key_len); - -/** - * @brief Get ESP-NOW key of a target device. - * - * If it is set multiple times, new key will cover the old one. - * - * @param uint8_t *mac_addr : MAC address of target device. - * @param uint8_t *key : pointer of key, buffer size has to be 16 bytes at least - * @param uint8_t key_len : key length - * - * @return 0 : succeed - * @return > 0 : find target device but can't get key - * @return < 0 : fail - */ -int32_t esp_now_get_peer_key(uint8_t *mac_addr, uint8_t *key, uint8_t *key_len); - -/** - * @brief Get MAC address of ESP-NOW device. - * - * Get MAC address of ESP-NOW device which is pointed now, and move - * the pointer to next one in ESP-NOW MAC list or move the pointer to - * the first one in ESP-NOW MAC list. - * - * @attention 1. This API can not re-entry - * @attention 2. Parameter has to be true when you call it the first time. - * - * @param bool restart : true, move pointer to the first one in ESP-NOW MAC list; - * false, move pointer to the next one in ESP-NOW MAC list - * - * @return NULL, no ESP-NOW devices exist - * @return Otherwise, MAC address of ESP-NOW device which is pointed now - */ -uint8_t *esp_now_fetch_peer(bool restart); - -/** - * @brief Check if target device exists or not. - * - * @param uint8 *mac_addr : MAC address of target device. - * - * @return 0 : device does not exist - * @return < 0 : error occur, check fail - * @return > 0 : device exists - */ -int32_t esp_now_is_peer_exist(uint8_t *mac_addr); - -/** - * @brief Get the total number of ESP-NOW devices which are associated, and the - * number count of encrypted devices. - * - * @param uint8 *all_cnt : total number of ESP-NOW devices which are associated. - * @param uint8 *encryp_cnt : number count of encrypted devices - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_get_cnt_info(uint8_t *all_cnt, uint8_t *encrypt_cnt); - -/** - * @brief Set the encrypt key of communication key. - * - * All ESP-NOW devices share the same encrypt key. If users do not set - * the encrypt key, ESP-NOW communication key will be encrypted by a default key. - * - * @param uint8 *key : pointer of encrypt key. - * @param uint8 len : key length, has to be 16 bytes now. - * - * @return 0 : succeed - * @return Non-0 : fail - */ -int32_t esp_now_set_kok(uint8_t *key, uint8_t len); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/esp8266/include/pwm.h b/components/esp8266/include/pwm.h deleted file mode 100644 index 95b8f85fc..000000000 --- a/components/esp8266/include/pwm.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * ESPRSSIF MIT License - * - * Copyright (c) 2015 - * - * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, - * it is free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#ifndef __PWM_H__ -#define __PWM_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** \defgroup Driver_APIs Driver APIs - * @brief Driver APIs - */ - -/** @addtogroup Driver_APIs - * @{ - */ - -/** \defgroup PWM_Driver_APIs PWM Driver APIs - * @brief PWM driver APIs - */ - -/** @addtogroup PWM_Driver_APIs - * @{ - */ - -struct pwm_param { - uint32_t period; /**< PWM period */ - uint32_t freq; /**< PWM frequency */ - uint32_t duty[8]; /**< PWM duty */ -}; - -#define PWM_DEPTH 1023 - -/** - * @brief PWM function initialization, including GPIO, frequency and duty cycle. - * - * @attention This API can be called only once. - * - * @param uint32_t period : pwm frequency - * @param uint32_t *duty : duty cycle - * @param uint32_t pwm_channel_num : PWM channel number - * @param uint32_t (*pin_info_list)[3] : GPIO parameter of PWM channel, it is a pointer - * of n x 3 array which defines GPIO register, IO - * reuse of corresponding pin and GPIO number. - * - * @return null - */ -void pwm_init(uint32_t period, uint32_t *duty, uint32_t pwm_channel_num, uint32_t(*pin_info_list)[3]); - -/** - * @brief Set the duty cycle of a PWM channel. - * - * Set the time that high level signal will last, duty depends on period, - * the maximum value can be 1023. - * - * - * @attention After set configuration, pwm_start needs to be called to take effect. - * - * @param uint32_t duty : duty cycle - * @param uint8_t channel : PWM channel number - * - * @return null - */ -void pwm_set_duty(uint32_t duty, uint8_t channel); - -/** - * @brief Get the duty cycle of a PWM channel. - * - * @param uint8_t channel : PWM channel number - * - * @return Duty cycle of PWM output. - */ -uint32_t pwm_get_duty(uint8_t channel); - -/** - * @brief Set PWM period, unit : us. - * - * For example, for 1KHz PWM, period is 1000 us. - * - * @attention After set configuration, pwm_start needs to be called to take effect. - * - * @param uint32 period : PWM period, unit : us. - * - * @return null - */ -void pwm_set_period(uint32_t period); - -/** - * @brief Get PWM period, unit : us. - * - * @param null - * - * @return PWM period, unit : us. - */ -uint32_t pwm_get_period(void); - -/** - * @brief Starts PWM. - * - * @attention This function needs to be called after PWM configuration is changed. - * - * @param null - * - * @return null - */ -void pwm_start(void); - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/esp8266/include/upgrade.h b/components/esp8266/include/upgrade.h deleted file mode 100644 index 186f0f5d6..000000000 --- a/components/esp8266/include/upgrade.h +++ /dev/null @@ -1,152 +0,0 @@ -/* - * ESPRSSIF MIT License - * - * Copyright (c) 2015 - * - * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, - * it is free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#ifndef __UPGRADE_H__ -#define __UPGRADE_H__ - -#include -#include - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** \defgroup System_APIs System APIs - * @brief System APIs - */ - -/** @addtogroup System_APIs - * @{ - */ - -/** \defgroup Upgrade_APIs Upgrade APIs - * @brief Firmware upgrade (FOTA) APIs - */ - -/** @addtogroup Upgrade_APIs - * @{ - */ - -#define SPI_FLASH_SEC_SIZE 4096 /**< SPI Flash sector size */ - -#define USER_BIN1 0x00 /**< firmware, user1.bin */ -#define USER_BIN2 0x01 /**< firmware, user2.bin */ - -#define UPGRADE_FLAG_IDLE 0x00 /**< flag of upgrading firmware, idle */ -#define UPGRADE_FLAG_START 0x01 /**< flag of upgrading firmware, start upgrade */ -#define UPGRADE_FLAG_FINISH 0x02 /**< flag of upgrading firmware, finish upgrading */ - -#define UPGRADE_FW_BIN1 0x00 /**< firmware, user1.bin */ -#define UPGRADE_FW_BIN2 0x01 /**< firmware, user2.bin */ - -/** - * @brief Callback of upgrading firmware through WiFi. - * - * @param void * arg : information about upgrading server - * - * @return null - */ -typedef void (*upgrade_states_check_callback)(void *arg); - -//#define UPGRADE_SSL_ENABLE - -struct upgrade_server_info { - struct sockaddr_in sockaddrin; /**< socket of upgrading */ - upgrade_states_check_callback check_cb; /**< callback of upgrading */ - uint32_t check_times; /**< time out of upgrading, unit : ms */ - uint8_t pre_version[16]; /**< previous version of firmware */ - uint8_t upgrade_version[16]; /**< the new version of firmware */ - uint8_t *url; /**< the url of upgrading server */ - void *pclient_param; - uint8_t upgrade_flag; /**< true, upgrade succeed; false, upgrade fail */ -}; - -/** - * @brief Upgrade function initialization. - * - * @param null - * - * @return null - */ -void system_upgrade_init(void); - -/** - * @brief Upgrade function de-initialization. - * - * @param null - * - * @return null - */ -void system_upgrade_deinit(void); - -/** - * @brief Upgrade function de-initialization. - * - * @param uint8 *data : segment of the firmware bin data - * @param uint32 len : length of the segment bin data - * - * @return null - */ -bool system_upgrade(uint8_t *data, uint32_t len); - -#ifdef UPGRADE_SSL_ENABLE - -/** - * @brief Start upgrade firmware through WiFi with SSL connection. - * - * @param struct upgrade_server_info *server : the firmware upgrade server info - * - * @return true : succeed - * @return false : fail - */ -bool system_upgrade_start_ssl(struct upgrade_server_info *server); -#else - -/** - * @brief Start upgrade firmware through WiFi with normal connection. - * - * @param struct upgrade_server_info *server : the firmware upgrade server info - * - * @return true : succeed - * @return false : fail - */ - -bool system_upgrade_start(struct upgrade_server_info *server); -#endif - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/esp8266/lib/VERSION b/components/esp8266/lib/VERSION index 6d162bbb7..5fdca6f02 100644 --- a/components/esp8266/lib/VERSION +++ b/components/esp8266/lib/VERSION @@ -1,9 +1,8 @@ gwen: - crypto: 8943c89 - espnow: 8943c89 - core: f4f0d3d - net80211: df6a8ab - pp: 830c0c8 - pwm: 0181338 - smartconfig:86a18f3 - wpa: f59f0e0 \ No newline at end of file + crypto: 9099d86 + core: 9099d86 + net80211: cd2e2b2 + pp: 9099d86 + smartconfig: 2.8.0 + wpa: 9099d86 + phy: 1058.15 diff --git a/components/esp8266/lib/libairkiss.a b/components/esp8266/lib/libairkiss.a deleted file mode 100644 index cfdcc8423..000000000 Binary files a/components/esp8266/lib/libairkiss.a and /dev/null differ diff --git a/components/esp8266/lib/libcirom.a b/components/esp8266/lib/libcirom.a deleted file mode 100644 index a93892963..000000000 Binary files a/components/esp8266/lib/libcirom.a and /dev/null differ diff --git a/components/esp8266/lib/libcore.a b/components/esp8266/lib/libcore.a old mode 100644 new mode 100755 index a7165fe09..2527eff3a Binary files a/components/esp8266/lib/libcore.a and b/components/esp8266/lib/libcore.a differ diff --git a/components/esp8266/lib/libcrypto.a b/components/esp8266/lib/libcrypto.a index 754e4250f..ef31aa110 100644 Binary files a/components/esp8266/lib/libcrypto.a and b/components/esp8266/lib/libcrypto.a differ diff --git a/components/esp8266/lib/libespnow.a b/components/esp8266/lib/libespnow.a deleted file mode 100644 index 5bf7aba72..000000000 Binary files a/components/esp8266/lib/libespnow.a and /dev/null differ diff --git a/components/esp8266/lib/libnet80211.a b/components/esp8266/lib/libnet80211.a index 6e646b6bf..48d72c7d2 100644 Binary files a/components/esp8266/lib/libnet80211.a and b/components/esp8266/lib/libnet80211.a differ diff --git a/components/esp8266/lib/libphy.a b/components/esp8266/lib/libphy.a old mode 100644 new mode 100755 index deafe2dd1..8af1692af Binary files a/components/esp8266/lib/libphy.a and b/components/esp8266/lib/libphy.a differ diff --git a/components/esp8266/lib/libpp.a b/components/esp8266/lib/libpp.a index ae97345cb..75c454445 100644 Binary files a/components/esp8266/lib/libpp.a and b/components/esp8266/lib/libpp.a differ diff --git a/components/esp8266/lib/libpwm.a b/components/esp8266/lib/libpwm.a deleted file mode 100644 index 2b403f4e1..000000000 Binary files a/components/esp8266/lib/libpwm.a and /dev/null differ diff --git a/components/esp8266/lib/libsmartconfig.a b/components/esp8266/lib/libsmartconfig.a index d93b3167c..dbffaafda 100644 Binary files a/components/esp8266/lib/libsmartconfig.a and b/components/esp8266/lib/libsmartconfig.a differ diff --git a/components/esp8266/lib/libwpa.a b/components/esp8266/lib/libwpa.a index b5872f350..8db232705 100644 Binary files a/components/esp8266/lib/libwpa.a and b/components/esp8266/lib/libwpa.a differ diff --git a/components/esp8266/source/ets_printf.c b/components/esp8266/source/ets_printf.c index d3c430130..06e90c46c 100644 --- a/components/esp8266/source/ets_printf.c +++ b/components/esp8266/source/ets_printf.c @@ -14,26 +14,24 @@ #include +#include "sdkconfig.h" + #include "esp_attr.h" #include "esp8266/eagle_soc.h" #include "esp8266/uart_register.h" #include "esp8266/rom_functions.h" -#ifndef CONFIG_ETS_PUTC_UART -#define CONFIG_ETS_PUTC_UART 0 -#endif - int IRAM_ATTR ets_putc(int c) { while (1) { - uint32_t fifo_cnt = READ_PERI_REG(UART_STATUS(CONFIG_ETS_PUTC_UART)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S); + uint32_t fifo_cnt = READ_PERI_REG(UART_STATUS(CONFIG_CONSOLE_UART_NUM)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S); if ((fifo_cnt >> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) < 126) break; } - WRITE_PERI_REG(UART_FIFO(CONFIG_ETS_PUTC_UART) , c); + WRITE_PERI_REG(UART_FIFO(CONFIG_CONSOLE_UART_NUM) , c); return c; } diff --git a/components/esp8266/source/phy.h b/components/esp8266/source/phy.h index 6c2d7a766..32c5376d4 100644 --- a/components/esp8266/source/phy.h +++ b/components/esp8266/source/phy.h @@ -30,7 +30,7 @@ void write_data_to_rtc(uint8_t *); void get_data_from_rtc(uint8_t *); -uint8_t chip_init(uint8_t* init_data, uint8_t *mac); +uint8_t chip_init(uint8_t* init_data, uint8_t *mac, uint32_t uart_baudrate); #ifdef __cplusplus } diff --git a/components/esp8266/source/phy_init.c b/components/esp8266/source/phy_init.c index 544c75068..099fb45d5 100644 --- a/components/esp8266/source/phy_init.c +++ b/components/esp8266/source/phy_init.c @@ -84,7 +84,7 @@ esp_err_t esp_phy_rf_init(const esp_phy_init_data_t *init_data, esp_phy_calibrat } esp_efuse_mac_get_default(sta_mac); - chip_init(local_init_data, sta_mac); + chip_init(local_init_data, sta_mac, CONFIG_CONSOLE_UART_BAUDRATE); get_data_from_rtc((uint8_t *)calibration_data); memcpy(rx_gain_dc_table, calibration_data->rx_gain_dc_table, 4 * 125); diff --git a/components/esp8266/source/system_api.c b/components/esp8266/source/system_api.c index 5dab12036..a941b57f1 100644 --- a/components/esp8266/source/system_api.c +++ b/components/esp8266/source/system_api.c @@ -36,7 +36,7 @@ esp_err_t esp_base_mac_addr_set(uint8_t *mac) { if (mac == NULL) { ESP_LOGE(TAG, "Base MAC address is NULL"); - abort(); + return ESP_ERR_INVALID_ARG; } memcpy(base_mac_addr, mac, 6); @@ -65,6 +65,7 @@ esp_err_t esp_efuse_mac_get_default(uint8_t* mac) uint8_t efuse_crc = 0; uint8_t calc_crc = 0; uint8_t version; + uint8_t use_default = 1; efuse[0] = REG_READ(EFUSE_DATA0_REG); efuse[1] = REG_READ(EFUSE_DATA1_REG); @@ -82,6 +83,8 @@ esp_err_t esp_efuse_mac_get_default(uint8_t* mac) mac[1] = efuse[3] >> 8; mac[2] = efuse[3]; + use_default = 0; + tmp_mac[0] = mac[2]; tmp_mac[1] = mac[1]; tmp_mac[2] = mac[0]; @@ -89,28 +92,28 @@ esp_err_t esp_efuse_mac_get_default(uint8_t* mac) efuse_crc = efuse[2] >> 24; calc_crc = esp_crc8(tmp_mac, 3); - if (efuse_crc != calc_crc) { - ESP_LOGE(TAG, "High MAC CRC error, efuse_crc = 0x%02x; calc_crc = 0x%02x", efuse_crc, calc_crc); - return ESP_ERR_INVALID_MAC; - } + if (efuse_crc != calc_crc) + use_default = 1; - version = (efuse[1] >> EFUSE_VERSION_S) & EFUSE_VERSION_V; + if (!use_default) { + version = (efuse[1] >> EFUSE_VERSION_S) & EFUSE_VERSION_V; - if (version == EFUSE_VERSION_1 || version == EFUSE_VERSION_2) { - tmp_mac[0] = mac[5]; - tmp_mac[1] = mac[4]; - tmp_mac[2] = mac[3]; - tmp_mac[3] = efuse[1] >> 16; + if (version == EFUSE_VERSION_1 || version == EFUSE_VERSION_2) { + tmp_mac[0] = mac[5]; + tmp_mac[1] = mac[4]; + tmp_mac[2] = mac[3]; + tmp_mac[3] = efuse[1] >> 16; - efuse_crc = efuse[0] >> 16; - calc_crc = esp_crc8(tmp_mac, 4); + efuse_crc = efuse[0] >> 16; + calc_crc = esp_crc8(tmp_mac, 4); - if (efuse_crc != calc_crc) { - ESP_LOGE(TAG, "CRC8 error, efuse_crc = 0x%02x; calc_crc = 0x%02x", efuse_crc, calc_crc); - return ESP_ERR_INVALID_MAC; + if (efuse_crc != calc_crc) + use_default = 1; } } - } else { + } + + if (use_default) { mac[0] = 0x18; mac[1] = 0xFE; mac[2] = 0x34; diff --git a/components/freertos/port/esp8266/include/freertos/portmacro.h b/components/freertos/port/esp8266/include/freertos/portmacro.h index d04b4558c..0c1ad6951 100644 --- a/components/freertos/port/esp8266/include/freertos/portmacro.h +++ b/components/freertos/port/esp8266/include/freertos/portmacro.h @@ -167,6 +167,8 @@ void PortEnableInt_NoNest( void ); #define portENTER_CRITICAL() vPortEnterCritical() #define portEXIT_CRITICAL() vPortExitCritical() +#define xPortGetCoreID() 0 + // no need to disable/enable lvl1 isr again in ISR //#define portSET_INTERRUPT_MASK_FROM_ISR() PortDisableInt_NoNest() //#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) PortEnableInt_NoNest() diff --git a/components/freertos/port/esp8266/panic.c b/components/freertos/port/esp8266/panic.c index 57719aea0..8917aad64 100644 --- a/components/freertos/port/esp8266/panic.c +++ b/components/freertos/port/esp8266/panic.c @@ -57,17 +57,55 @@ typedef struct task_info StackType_t *pxEndOfStack; } task_info_t; -static void IRAM_ATTR panic_stack(StackType_t *start_stk, StackType_t *end_stk) +static void panic_data32(uint32_t data, int hex) +{ + char buf[12]; + size_t off = 0; + + if (!data) + buf[off++] = '0'; + else { + while (data) { + char tmp = data % hex; + + if (tmp >= 10) + tmp = tmp - 10 + 'a'; + else + tmp = tmp + '0'; + + data = data / hex; + + buf[off++] = tmp; + } + } + + if (hex == 16) { + while (off < 8) + buf[off++] = '0'; + } + + while (off) + ets_putc(buf[--off]); +} + +static void panic_str(const char *s) +{ + while (*s) + ets_putc(*s++); +} + +static void panic_stack(StackType_t *start_stk, StackType_t *end_stk) { uint32_t *start = (uint32_t *)start_stk, *end = (uint32_t *)end_stk; size_t i, j; size_t size = end - start + 1; - ets_printf("%10s", " "); + panic_str(" "); for (i = 0; i < STACK_VOL_NUM; i++) { - ets_printf("%-8x ", i * sizeof(StackType_t)); + panic_data32(i * sizeof(StackType_t), 16); + panic_str(" "); } - ets_printf("\n\n"); + panic_str("\r\n\r\n"); for (i = 0; i < size; i += STACK_VOL_NUM) { size_t len = size > i ? size - i : STACK_VOL_NUM - (i - size); @@ -75,12 +113,14 @@ static void IRAM_ATTR panic_stack(StackType_t *start_stk, StackType_t *end_stk) if (len > STACK_VOL_NUM) len = STACK_VOL_NUM; - ets_printf("%-10x", &start[i]); + panic_data32((uint32_t)&start[i], 16); + panic_str(" "); for (j = 0; j < len; j++) { - ets_printf("%08x ",start[i + j]); + panic_data32((uint32_t)start[i + j], 16); + panic_str(" "); } - ets_printf("\n"); + panic_str("\r\n"); } } @@ -91,54 +131,59 @@ static void IRAM_ATTR panic_stack(StackType_t *start_stk, StackType_t *end_stk) * * @return none */ -void IRAM_ATTR panicHandler(void *frame) +void panic_info(void *frame) { - // for panic the function that disable cache - Cache_Read_Enable_New(); - task_info_t *task; int *regs = (int *)frame; int x, y; const char *sdesc[] = { - "PC", "PS", "A0", "A1", - "A2", "A3", "A4", "A5", - "A6", "A7", "A8", "A9", - "A10", "A11", "A12", "A13", - "A14", "A15", "SAR", "EXCCAUSE" + " PC", " PS", " A0", " A1", + " A2", " A3", " A4", " A5", + " A6", " A7", " A8", " A9", + " A10", " A11", " A12", " A13", + " A14", " A15", " SAR", "EXCCAUSE" }; extern int _Pri_3_NMICount; - /* NMI can interrupt exception. */ - ETS_INTR_LOCK(); - - ets_printf("\r\n\r\n"); + panic_str("\r\n\r\n"); if (_Pri_3_NMICount == -1) { - ets_printf("Soft watch dog triggle:\r\n\r\n"); + panic_str("Soft watch dog triggle:\r\n\r\n"); show_critical_info(); } else if (xPortInIsrContext()) - ets_printf("Core 0 was running in ISR context:\r\n\r\n"); + panic_str("Core 0 was running in ISR context:\r\n\r\n"); if ((task = (task_info_t *)xTaskGetCurrentTaskHandle())) { StackType_t *pdata = task->pxStack; StackType_t *end = task->pxEndOfStack + 4; - ets_printf("Task stack [%s] stack from [%p] to [%p], total [%d] size\r\n\r\n", - task->pcTaskName, pdata, end, end - pdata + 4); + // "Task stack [%s] stack from [%p] to [%p], total [%d] size\r\n\r\n" + panic_str("Task stack ["); + panic_str(task->pcTaskName); + panic_str("] stack from ["); + panic_data32((uint32_t)pdata, 16); + panic_str("] to ["); + panic_data32((uint32_t)end, 16); + panic_str("], total ["); + panic_data32((uint32_t)(end - pdata + 4), 10); + panic_str("] size\r\n\r\n"); panic_stack(pdata, end); - ets_printf("\r\n\r\n"); + panic_str("\r\n\r\n"); } else { - ets_printf("No task\r\n\r\n"); + panic_str("No task\r\n\r\n"); } for (x = 0; x < 20; x += 4) { for (y = 0; y < 4; y++) { - ets_printf("%8s: 0x%08x ", sdesc[x + y], regs[x + y + 1]); + panic_str(sdesc[x + y]); + panic_str(": 0x"); + panic_data32((uint32_t)regs[x + y + 1], 16); + panic_str(" "); } - ets_printf("\r\n"); + panic_str("\r\n"); } /* @@ -150,6 +195,22 @@ void IRAM_ATTR panicHandler(void *frame) while (1); } +void IRAM_ATTR panicHandler(void *frame) +{ + int cnt = 10; + + /* NMI can interrupt exception. */ + vPortEnterCritical(); + while (cnt--) { + REG_WRITE(INT_ENA_WDEV, 0); + } + + // for panic the function that disable cache + Cache_Read_Enable_New(); + + panic_info(frame); +} + void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression) { printf("ESP_ERROR_CHECK failed: esp_err_t 0x%x at %p\n", rc, __builtin_return_address(0)); diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 299030413..2da6e05d6 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -189,6 +189,12 @@ config LWIP_DHCPS_MAX_STATION_NUM After this number is exceeded, DHCP server removes of the oldest device from it's address pool, without notification. +config LWIP_ESP_DHCP_OPTION + bool "Enable DHCP option60 and option61 in discovery and request state" + default n + help + Maybe some routers need add those option to get IP address. + Enable this config to add option60 and option61 in discovery and request state endmenu #DHCP menuconfig LWIP_AUTOIP diff --git a/components/lwip/lwip/src/core/ipv4/dhcp.c b/components/lwip/lwip/src/core/ipv4/dhcp.c index 0cf97b034..2aff669b7 100644 --- a/components/lwip/lwip/src/core/ipv4/dhcp.c +++ b/components/lwip/lwip/src/core/ipv4/dhcp.c @@ -209,6 +209,12 @@ static void dhcp_option_hostname(struct dhcp *dhcp, struct netif *netif); /* always add the DHCP options trailer to end and pad */ static void dhcp_option_trailer(struct dhcp *dhcp); +#if ESP_DHCP_OPTION +/* set dhcp option61 */ +static void dhcp_option_clientid(struct dhcp *dhcp, struct netif *netif); +/* set dhcp option60 */ +static void dhcp_option_vendor(struct dhcp *dhcp, struct netif *netif); +#endif /** Ensure DHCP PCB is allocated and bound */ static err_t dhcp_inc_pcb_refcount(void) @@ -362,6 +368,10 @@ dhcp_select(struct netif *netif) /* create and initialize the DHCP message header */ result = dhcp_create_msg(netif, dhcp, DHCP_REQUEST); if (result == ERR_OK) { +#if ESP_DHCP_OPTION + dhcp_option_clientid(dhcp, netif); + dhcp_option_vendor(dhcp, netif); +#endif dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif)); @@ -972,6 +982,10 @@ dhcp_discover(struct netif *netif) if (result == ERR_OK) { LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_discover: making request\n")); +#if ESP_DHCP_OPTION + dhcp_option_clientid(dhcp, netif); + dhcp_option_vendor(dhcp, netif); +#endif dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif)); @@ -979,6 +993,11 @@ dhcp_discover(struct netif *netif) for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) { dhcp_option_byte(dhcp, dhcp_discover_request_options[i]); } + +#if LWIP_NETIF_HOSTNAME + dhcp_option_hostname(dhcp, netif); +#endif /* LWIP_NETIF_HOSTNAME */ + dhcp_option_trailer(dhcp); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_discover: realloc()ing\n")); @@ -1136,6 +1155,10 @@ dhcp_renew(struct netif *netif) /* create and initialize the DHCP message header */ result = dhcp_create_msg(netif, dhcp, DHCP_REQUEST); if (result == ERR_OK) { +#if ESP_DHCP_OPTION + dhcp_option_clientid(dhcp, netif); + dhcp_option_vendor(dhcp, netif); +#endif dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif)); @@ -1188,6 +1211,10 @@ dhcp_rebind(struct netif *netif) /* create and initialize the DHCP message header */ result = dhcp_create_msg(netif, dhcp, DHCP_REQUEST); if (result == ERR_OK) { +#if ESP_DHCP_OPTION + dhcp_option_clientid(dhcp, netif); + dhcp_option_vendor(dhcp, netif); +#endif dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN(netif)); @@ -1238,6 +1265,10 @@ dhcp_reboot(struct netif *netif) /* create and initialize the DHCP message header */ result = dhcp_create_msg(netif, dhcp, DHCP_REQUEST); if (result == ERR_OK) { +#if ESP_DHCP_OPTION + dhcp_option_clientid(dhcp, netif); + dhcp_option_vendor(dhcp, netif); +#endif dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN); dhcp_option_short(dhcp, DHCP_MAX_MSG_LEN_MIN_REQUIRED); @@ -1249,6 +1280,10 @@ dhcp_reboot(struct netif *netif) dhcp_option_byte(dhcp, dhcp_discover_request_options[i]); } +#if LWIP_NETIF_HOSTNAME + dhcp_option_hostname(dhcp, netif); +#endif /* LWIP_NETIF_HOSTNAME */ + dhcp_option_trailer(dhcp); pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len); @@ -1446,6 +1481,76 @@ dhcp_option_hostname(struct dhcp *dhcp, struct netif *netif) } #endif /* LWIP_NETIF_HOSTNAME */ +#if ESP_DHCP_OPTION +static void dhcp_option_clientid(struct dhcp *dhcp, struct netif *netif) +{ + if (netif) { + u8_t id_len = NETIF_MAX_HWADDR_LEN + 1; + dhcp_option(dhcp, DHCP_OPTION_CLIENT_ID, id_len); + dhcp_option_byte(dhcp, DHCP_HTYPE_ETH); + for (u8_t i = 0; i < NETIF_MAX_HWADDR_LEN; i++) { + dhcp_option_byte(dhcp, netif->hwaddr[i]); + } + } +} + +static u8_t vendor_class_len = 0; +static char *vendor_class_buf = NULL; +err_t dhcp_set_vendor_class_identifier(u8_t len, char *str) +{ + if (len == 0 || str == NULL) { + return ERR_ARG; + } + + if (vendor_class_buf) { + mem_free(vendor_class_buf); + vendor_class_buf = NULL; + } + + vendor_class_buf = (char *)mem_malloc(len + 1); + + if (vendor_class_buf == NULL) { + return ERR_MEM; + } + + vendor_class_len = len; + memcpy(vendor_class_buf, str, len); + return ERR_OK; +} + +static void dhcp_option_vendor(struct dhcp *dhcp, struct netif *netif) +{ + const char *p = NULL; + u8_t len = 0; + /* Shrink len to available bytes (need 2 bytes for OPTION_HOSTNAME + and 1 byte for trailer) */ + size_t available = DHCP_OPTIONS_LEN - dhcp->options_out_len - 3; + if (vendor_class_buf && vendor_class_len) { + p = vendor_class_buf; + LWIP_ASSERT("DHCP: vendor_class_len is too long!", vendor_class_len <= available); + len = vendor_class_len; + } else { //use hostname as vendor +#if LWIP_NETIF_HOSTNAME + if (netif->hostname != NULL) { + size_t namelen = strlen(netif->hostname); + if ((namelen > 0) && (namelen < 0xFF)) { + p = netif->hostname; + LWIP_ASSERT("DHCP: hostname is too long!", namelen <= available); + len = (u8_t) namelen; + } + } +#endif + } + + if (p) { + dhcp_option(dhcp, DHCP_OPTION_US, (u8_t)len); + while (len--) { + dhcp_option_byte(dhcp, *p++); + } + } +} +#endif + /** * Extract the DHCP message and the DHCP options. * diff --git a/components/lwip/lwip/src/include/lwip/prot/dhcp.h b/components/lwip/lwip/src/include/lwip/prot/dhcp.h index 112953cb8..02ed51d0a 100644 --- a/components/lwip/lwip/src/include/lwip/prot/dhcp.h +++ b/components/lwip/lwip/src/include/lwip/prot/dhcp.h @@ -175,6 +175,9 @@ typedef enum { #define DHCP_OVERLOAD_SNAME 2 #define DHCP_OVERLOAD_SNAME_FILE 3 +#if ESP_DHCP_OPTION +err_t dhcp_set_vendor_class_identifier(u8_t len, char *str); +#endif #ifdef __cplusplus } diff --git a/components/lwip/port/esp8266/freertos/sys_arch.c b/components/lwip/port/esp8266/freertos/sys_arch.c index 91fd63228..e3bc1b4c7 100644 --- a/components/lwip/port/esp8266/freertos/sys_arch.c +++ b/components/lwip/port/esp8266/freertos/sys_arch.c @@ -59,6 +59,8 @@ struct timeoutlist { //static u16_t nextthread = 0; int intlevel = 0; +static xTaskHandle s_tcpip_task_handle; + /*-----------------------------------------------------------------------------------*/ // Initialize sys arch void @@ -365,18 +367,27 @@ sys_now(void) sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio) { - xTaskHandle CreatedTask; portBASE_TYPE result; - result = xTaskCreate(thread, (const char *)name, stacksize, arg, prio, &CreatedTask); + result = xTaskCreate(thread, (const char *)name, stacksize, arg, prio, &s_tcpip_task_handle); if (result == pdPASS) { - return CreatedTask; + return s_tcpip_task_handle; } else { return NULL; } } +int sys_current_task_is_tcpip(void) +{ + return xTaskGetCurrentTaskHandle() == s_tcpip_task_handle ? 1 : 0; +} + +char *sys_current_task_name(void) +{ + return pcTaskGetTaskName(xTaskGetCurrentTaskHandle()); +} + /* This optional function does a "fast" critical region protection and returns the previous protection level. This function is only called during very short diff --git a/components/lwip/port/esp8266/freertos/udp_sync.c b/components/lwip/port/esp8266/freertos/udp_sync.c index d4ac78730..4a4039f32 100644 --- a/components/lwip/port/esp8266/freertos/udp_sync.c +++ b/components/lwip/port/esp8266/freertos/udp_sync.c @@ -22,7 +22,7 @@ #include "esp_log.h" -#if ESP_UDP +#if ESP_UDP && LWIP_NETIF_TX_SINGLE_PBUF #define UDP_SYNC_MAX MEMP_NUM_NETCONN #define UDP_SYNC_RETRY_MAX CONFIG_ESP_UDP_SYNC_RETRY_MAX @@ -40,15 +40,16 @@ typedef struct udp_sync { struct api_msg *msg; - int ret; + struct netif *netif; - int retry; + int8_t ret; + + uint8_t retry; } udp_sync_t; static const char *TAG = "udp_sync"; static size_t s_udp_sync_num; static udp_sync_t s_udp_sync[UDP_SYNC_MAX]; -static bool s_register_locked; static struct api_msg *s_cur_msg; /* @@ -57,7 +58,6 @@ static struct api_msg *s_cur_msg; void udp_sync_init(void) { memset(s_udp_sync, 0, sizeof(s_udp_sync)); - s_register_locked = false; s_udp_sync_num = 0; } @@ -68,18 +68,13 @@ void udp_sync_regitser(void *in_msg) { s_cur_msg = in_msg; - if (s_register_locked == true) - return ; - struct api_msg *msg = (struct api_msg *)in_msg; int s = msg->conn->socket; if (s < 0 || s >= UDP_SYNC_MAX) { ESP_LOGE(TAG, "UDP sync register error, socket is %d", s); - return ; } else if (s_udp_sync[s].msg) { ESP_LOGE(TAG, "UDP sync register error, msg is %p", s_udp_sync[s].msg); - return ; } s_udp_sync_num++; @@ -88,6 +83,25 @@ void udp_sync_regitser(void *in_msg) s_udp_sync[s].msg = msg; } +static void _udp_sync_ack_ret(int s, struct api_msg *msg) +{ + /* Only cache when low-level has no buffer to send packet */ + if (s_udp_sync[s].ret != ERR_MEM || s_udp_sync[s].retry >= UDP_SYNC_RETRY_MAX) { + + ESP_LOGD(TAG, "UDP sync ret %d retry %d", s_udp_sync[s].ret, s_udp_sync[s].retry); + + s_udp_sync[s].msg = NULL; + s_udp_sync[s].retry = 0; + s_udp_sync[s].ret = ERR_OK; + s_udp_sync_num--; + + TCPIP_APIMSG_ACK(msg); + } else { + s_udp_sync[s].retry++; + ESP_LOGD(TAG, "UDP sync ack error, errno %d", s_udp_sync[s].ret); + } +} + /* * @brief ack the message */ @@ -98,26 +112,11 @@ void udp_sync_ack(void *in_msg) if (s < 0 || s >= UDP_SYNC_MAX) { ESP_LOGE(TAG, "UDP sync ack error, socket is %d", s); - return ; } else if (!s_udp_sync[s].msg) { ESP_LOGE(TAG, "UDP sync ack error, msg is NULL"); - return ; } - /* Only cache when low-level has no buffer to send packet */ - if (s_udp_sync[s].ret != ERR_MEM || s_udp_sync[s].retry >= UDP_SYNC_RETRY_MAX) { - s_udp_sync[s].msg = NULL; - s_udp_sync[s].retry = 0; - s_udp_sync[s].ret = ERR_OK; - s_udp_sync_num--; - - ESP_LOGD(TAG, "UDP sync ret %d", s_udp_sync[s].ret); - - TCPIP_APIMSG_ACK(msg); - } else { - s_udp_sync[s].retry++; - ESP_LOGD(TAG, "UDP sync ack error, errno %d", s_udp_sync[s].ret); - } + _udp_sync_ack_ret(s, msg); s_cur_msg = NULL; } @@ -125,12 +124,12 @@ void udp_sync_ack(void *in_msg) /* * @brief set the current message send result */ -void udp_sync_set_ret(int ret) +void udp_sync_set_ret(void *netif, int ret) { /* Only poll and regitser can set current message */ - if (!s_cur_msg) { + if (!s_cur_msg || !sys_current_task_is_tcpip()) { /* You may use it to debug */ - //ESP_LOGE(TAG, "UDP sync ack error, current message is NULL"); + //ESP_LOGE(TAG, "UDP sync ack error, current message is %p, task name is %s", s_cur_msg, sys_current_task_name()); return ; } @@ -139,15 +138,28 @@ void udp_sync_set_ret(int ret) if (s < 0 || s >= UDP_SYNC_MAX) { ESP_LOGE(TAG, "UDP sync ack error, socket is %d", s); - return ; } else if (!s_udp_sync[s].msg) { ESP_LOGE(TAG, "UDP sync ack error, msg is NULL"); - return ; } + s_udp_sync[s].netif = netif; s_udp_sync[s].ret = ret; } +static void udp_sync_send(struct api_msg *msg) +{ + struct pbuf *p = msg->msg.b->p; + int s = msg->conn->socket; + struct netif *netif = s_udp_sync[s].netif; + + s_cur_msg = msg; + + netif->linkoutput(netif, p); + _udp_sync_ack_ret(s, msg); + + s_cur_msg = NULL; +} + /* * @brief process the sync */ @@ -156,19 +168,34 @@ void udp_sync_proc(void) if (!s_udp_sync_num) return ; - s_register_locked = true; for (int i = 0; i < UDP_SYNC_MAX; i++) { if (!s_udp_sync[i].msg) continue; - lwip_netconn_do_send(s_udp_sync[i].msg); -#if 0 - //Todo: Add this later - if (s_udp_sync[i].ret != ERR_OK) + udp_sync_send(s_udp_sync[i].msg); + + if (s_udp_sync[i].ret == ERR_MEM) break; -#endif } - s_register_locked = false; +} + +/* + * @brief NULL function and just as sync message + */ +static void udp_sync_trigger_null(void *p) +{ + +} + +/* + * @brief trigger a UDP sync process + */ +void udp_sync_trigger(void) +{ + if (!s_udp_sync_num) + return ; + + tcpip_callback_with_block((tcpip_callback_fn)udp_sync_trigger_null, NULL, 0); } #endif /* ESP_UDP */ diff --git a/components/lwip/port/esp8266/include/arch/sys_arch.h b/components/lwip/port/esp8266/include/arch/sys_arch.h index 8bf1b568b..4b3bd8a82 100644 --- a/components/lwip/port/esp8266/include/arch/sys_arch.h +++ b/components/lwip/port/esp8266/include/arch/sys_arch.h @@ -57,6 +57,10 @@ void sys_thread_sem_deinit(void); sys_sem_t* sys_thread_sem_get(void); err_t sys_mutex_trylock(sys_mutex_t *pxMutex); +int sys_current_task_is_tcpip(void); + +char *sys_current_task_name(void); + #define LWIP_NETCONN_THREAD_SEM_ALLOC() sys_thread_sem_init() #define LWIP_NETCONN_THREAD_SEM_FREE() sys_thread_sem_deinit() #define LWIP_NETCONN_THREAD_SEM_GET() sys_thread_sem_get() diff --git a/components/lwip/port/esp8266/include/lwipopts.h b/components/lwip/port/esp8266/include/lwipopts.h index e9c8b14ea..0b143acae 100644 --- a/components/lwip/port/esp8266/include/lwipopts.h +++ b/components/lwip/port/esp8266/include/lwipopts.h @@ -2226,4 +2226,5 @@ void *memp_malloc_ll(size_t type); #endif #endif +#define ESP_DHCP_OPTION CONFIG_LWIP_ESP_DHCP_OPTION #endif /* __LWIP_HDR_LWIPOPTS_H__ */ diff --git a/components/lwip/port/esp8266/include/udp_sync.h b/components/lwip/port/esp8266/include/udp_sync.h index 29184fbfe..055361e36 100644 --- a/components/lwip/port/esp8266/include/udp_sync.h +++ b/components/lwip/port/esp8266/include/udp_sync.h @@ -43,7 +43,7 @@ void udp_sync_ack(void *in_msg); * * @param ret current message send result */ -void udp_sync_set_ret(int ret); +void udp_sync_set_ret(void *netif, int ret); /* * @brief process the sync @@ -52,6 +52,11 @@ void udp_sync_set_ret(int ret); */ void udp_sync_proc(void); +/* + * @brief trigger a UDP sync process + */ +void udp_sync_trigger(void); + #ifdef __cplusplus } #endif diff --git a/components/lwip/port/esp8266/netif/ethernetif.c b/components/lwip/port/esp8266/netif/ethernetif.c index 45a7a5d64..4c9162bbb 100644 --- a/components/lwip/port/esp8266/netif/ethernetif.c +++ b/components/lwip/port/esp8266/netif/ethernetif.c @@ -208,6 +208,10 @@ static int low_level_send_cb(esp_aio_t *aio) pbuf_free(pbuf); +#if ESP_UDP + udp_sync_trigger(); +#endif + return 0; } @@ -303,7 +307,7 @@ static int8_t low_level_output(struct netif* netif, struct pbuf* p) */ err = esp_aio_sendto(&aio, NULL, 0); #if ESP_UDP - udp_sync_set_ret(err); + udp_sync_set_ret(netif, err); #endif if (err != ERR_OK) { if (err == ERR_MEM){ diff --git a/components/newlib/newlib/port/syscall.c b/components/newlib/newlib/port/syscall.c index 29eaacd2f..9c0145b8d 100644 --- a/components/newlib/newlib/port/syscall.c +++ b/components/newlib/newlib/port/syscall.c @@ -135,6 +135,10 @@ void _exit(int status) void abort(void) { - ESP_LOGE("ABORT","Error found and abort!"); - while(1); + ets_printf("abort() was called at PC %p on core %d\r\n", __builtin_return_address(0) - 3, xPortGetCoreID()); + + /* cause a exception to jump into panic function */ + while (1) { + *((int *)NULL) = 0; + } } \ No newline at end of file diff --git a/components/nvs_flash/src/nvs_item_hash_list.cpp b/components/nvs_flash/src/nvs_item_hash_list.cpp index e483c5969..845dd0910 100644 --- a/components/nvs_flash/src/nvs_item_hash_list.cpp +++ b/components/nvs_flash/src/nvs_item_hash_list.cpp @@ -60,7 +60,7 @@ void HashList::insert(const Item& item, size_t index) newBlock->mCount++; } -void HashList::erase(size_t index) +void HashList::erase(size_t index, bool itemShouldExist) { for (auto it = mBlockList.begin(); it != mBlockList.end();) { bool haveEntries = false; @@ -82,7 +82,9 @@ void HashList::erase(size_t index) ++it; } } - assert(false && "item should have been present in cache"); + if (itemShouldExist) { + assert(false && "item should have been present in cache"); + } } size_t HashList::find(size_t start, const Item& item) diff --git a/components/nvs_flash/src/nvs_item_hash_list.hpp b/components/nvs_flash/src/nvs_item_hash_list.hpp index 3f8dcc850..e759cd818 100644 --- a/components/nvs_flash/src/nvs_item_hash_list.hpp +++ b/components/nvs_flash/src/nvs_item_hash_list.hpp @@ -29,7 +29,7 @@ class HashList ~HashList(); void insert(const Item& item, size_t index); - void erase(const size_t index); + void erase(const size_t index, bool itemShouldExist=true); size_t find(size_t start, const Item& item); void clear(); diff --git a/components/nvs_flash/src/nvs_page.cpp b/components/nvs_flash/src/nvs_page.cpp index 2a17cff24..efadc1855 100644 --- a/components/nvs_flash/src/nvs_page.cpp +++ b/components/nvs_flash/src/nvs_page.cpp @@ -318,7 +318,6 @@ esp_err_t Page::eraseEntryAndSpan(size_t index) { auto state = mEntryTable.get(index); assert(state == EntryState::WRITTEN || state == EntryState::EMPTY); - mHashList.erase(index); size_t span = 1; if (state == EntryState::WRITTEN) { @@ -328,6 +327,7 @@ esp_err_t Page::eraseEntryAndSpan(size_t index) return rc; } if (item.calculateCrc32() != item.crc32) { + mHashList.erase(index, false); rc = alterEntryState(index, EntryState::ERASED); --mUsedEntryCount; ++mErasedEntryCount; @@ -335,6 +335,7 @@ esp_err_t Page::eraseEntryAndSpan(size_t index) return rc; } } else { + mHashList.erase(index); span = item.span; for (ptrdiff_t i = index + span - 1; i >= static_cast(index); --i) { if (mEntryTable.get(i) == EntryState::WRITTEN) { @@ -385,7 +386,7 @@ void Page::updateFirstUsedEntry(size_t index, size_t span) } } -esp_err_t Page::moveItem(Page& other) +esp_err_t Page::copyItems(Page& other) { if (mFirstUsedEntry == INVALID_ENTRY) { return ESP_ERR_NVS_NOT_FOUND; @@ -399,29 +400,41 @@ esp_err_t Page::moveItem(Page& other) } Item entry; - auto err = readEntry(mFirstUsedEntry, entry); - if (err != ESP_OK) { - return err; - } - other.mHashList.insert(entry, other.mNextFreeEntry); - err = other.writeEntry(entry); - if (err != ESP_OK) { - return err; - } + size_t readEntryIndex = mFirstUsedEntry; - size_t span = entry.span; - size_t end = mFirstUsedEntry + span; + while (readEntryIndex < ENTRY_COUNT) { - assert(mFirstUsedEntry != INVALID_ENTRY || span == 1); + if (mEntryTable.get(readEntryIndex) != EntryState::WRITTEN) { + assert(readEntryIndex != mFirstUsedEntry); + readEntryIndex++; + continue; + } + auto err = readEntry(readEntryIndex, entry); + if (err != ESP_OK) { + return err; + } - for (size_t i = mFirstUsedEntry + 1; i < end; ++i) { - readEntry(i, entry); + other.mHashList.insert(entry, other.mNextFreeEntry); err = other.writeEntry(entry); if (err != ESP_OK) { return err; } + size_t span = entry.span; + size_t end = readEntryIndex + span; + + assert(end <= ENTRY_COUNT); + + for (size_t i = readEntryIndex + 1; i < end; ++i) { + readEntry(i, entry); + err = other.writeEntry(entry); + if (err != ESP_OK) { + return err; + } + } + readEntryIndex = end; + } - return eraseEntryAndSpan(mFirstUsedEntry); + return ESP_OK; } esp_err_t Page::mLoadEntryTable() @@ -515,11 +528,6 @@ esp_err_t Page::mLoadEntryTable() return err; } - mHashList.insert(item, i); - - // search for potential duplicate item - size_t duplicateIndex = mHashList.find(0, item); - if (item.crc32 != item.calculateCrc32()) { err = eraseEntryAndSpan(i); if (err != ESP_OK) { @@ -529,6 +537,10 @@ esp_err_t Page::mLoadEntryTable() continue; } + mHashList.insert(item, i); + + // search for potential duplicate item + size_t duplicateIndex = mHashList.find(0, item); if (item.datatype == ItemType::BLOB || item.datatype == ItemType::SZ) { span = item.span; @@ -580,8 +592,6 @@ esp_err_t Page::mLoadEntryTable() return err; } - mHashList.insert(item, i); - if (item.crc32 != item.calculateCrc32()) { err = eraseEntryAndSpan(i); if (err != ESP_OK) { @@ -590,10 +600,20 @@ esp_err_t Page::mLoadEntryTable() } continue; } - assert(item.span > 0); + mHashList.insert(item, i); size_t span = item.span; + + if (item.datatype == ItemType::BLOB || item.datatype == ItemType::SZ) { + for (size_t j = i + 1; j < i + span; ++j) { + if (mEntryTable.get(j) != EntryState::WRITTEN) { + eraseEntryAndSpan(i); + break; + } + } + } + i += span - 1; } @@ -730,7 +750,11 @@ esp_err_t Page::findItem(uint8_t nsIndex, ItemType datatype, const char* key, si auto crc32 = item.calculateCrc32(); if (item.crc32 != crc32) { - eraseEntryAndSpan(i); + rc = eraseEntryAndSpan(i); + if (rc != ESP_OK) { + mState = PageState::INVALID; + return rc; + } continue; } diff --git a/components/nvs_flash/src/nvs_page.hpp b/components/nvs_flash/src/nvs_page.hpp index 7731e403a..413da4589 100644 --- a/components/nvs_flash/src/nvs_page.hpp +++ b/components/nvs_flash/src/nvs_page.hpp @@ -127,7 +127,7 @@ class Page : public intrusive_list_node esp_err_t markFreeing(); - esp_err_t moveItem(Page& other); + esp_err_t copyItems(Page& other); esp_err_t erase(); diff --git a/components/nvs_flash/src/nvs_pagemanager.cpp b/components/nvs_flash/src/nvs_pagemanager.cpp index 943f54f2f..31240d98b 100644 --- a/components/nvs_flash/src/nvs_pagemanager.cpp +++ b/components/nvs_flash/src/nvs_pagemanager.cpp @@ -67,7 +67,9 @@ esp_err_t PageManager::load(uint32_t baseSector, uint32_t sectorCount) if (lastItemIndex != SIZE_MAX) { auto last = PageManager::TPageListIterator(&lastPage); for (auto it = begin(); it != last; ++it) { - if (it->eraseItem(item.nsIndex, item.datatype, item.key) == ESP_OK) { + + if ((it->state() != Page::PageState::FREEING) && + (it->eraseItem(item.nsIndex, item.datatype, item.key) == ESP_OK)) { break; } } @@ -77,23 +79,26 @@ esp_err_t PageManager::load(uint32_t baseSector, uint32_t sectorCount) for (auto it = begin(); it!= end(); ++it) { if (it->state() == Page::PageState::FREEING) { Page* newPage = &mPageList.back(); - if (newPage->state() != Page::PageState::ACTIVE) { - auto err = activatePage(); + if (newPage->state() == Page::PageState::ACTIVE) { + auto err = newPage->erase(); if (err != ESP_OK) { return err; } - newPage = &mPageList.back(); + mPageList.erase(newPage); + mFreePageList.push_back(newPage); } - while (true) { - auto err = it->moveItem(*newPage); - if (err == ESP_ERR_NVS_NOT_FOUND) { - break; - } else if (err != ESP_OK) { - return err; - } + auto err = activatePage(); + if (err != ESP_OK) { + return err; + } + newPage = &mPageList.back(); + + err = it->copyItems(*newPage); + if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND) { + return err; } - auto err = it->erase(); + err = it->erase(); if (err != ESP_OK) { return err; } @@ -109,7 +114,7 @@ esp_err_t PageManager::load(uint32_t baseSector, uint32_t sectorCount) if (mFreePageList.size() == 0) { return ESP_ERR_NVS_NO_FREE_PAGES; } - + return ESP_OK; } @@ -125,17 +130,18 @@ esp_err_t PageManager::requestNewPage() } // find the page with the higest number of erased items - TPageListIterator maxErasedItemsPageIt; - size_t maxErasedItems = 0; + TPageListIterator maxUnusedItemsPageIt; + size_t maxUnusedItems = 0; for (auto it = begin(); it != end(); ++it) { - auto erased = it->getErasedEntryCount(); - if (erased > maxErasedItems) { - maxErasedItemsPageIt = it; - maxErasedItems = erased; + + auto unused = Page::ENTRY_COUNT - it->getUsedEntryCount(); + if (unused > maxUnusedItems) { + maxUnusedItemsPageIt = it; + maxUnusedItems = unused; } } - if (maxErasedItems == 0) { + if (maxUnusedItems == 0) { return ESP_ERR_NVS_NOT_ENOUGH_SPACE; } @@ -146,7 +152,8 @@ esp_err_t PageManager::requestNewPage() Page* newPage = &mPageList.back(); - Page* erasedPage = maxErasedItemsPageIt; + Page* erasedPage = maxUnusedItemsPageIt; + #ifndef NDEBUG size_t usedEntries = erasedPage->getUsedEntryCount(); #endif @@ -154,13 +161,9 @@ esp_err_t PageManager::requestNewPage() if (err != ESP_OK) { return err; } - while (true) { - err = erasedPage->moveItem(*newPage); - if (err == ESP_ERR_NVS_NOT_FOUND) { - break; - } else if (err != ESP_OK) { - return err; - } + err = erasedPage->copyItems(*newPage); + if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND) { + return err; } err = erasedPage->erase(); @@ -171,8 +174,8 @@ esp_err_t PageManager::requestNewPage() #ifndef NDEBUG assert(usedEntries == newPage->getUsedEntryCount()); #endif - - mPageList.erase(maxErasedItemsPageIt); + + mPageList.erase(maxUnusedItemsPageIt); mFreePageList.push_back(erasedPage); return ESP_OK; diff --git a/components/nvs_flash/test_nvs_host/test_nvs.cpp b/components/nvs_flash/test_nvs_host/test_nvs.cpp index f419256cf..c23f5d661 100644 --- a/components/nvs_flash/test_nvs_host/test_nvs.cpp +++ b/components/nvs_flash/test_nvs_host/test_nvs.cpp @@ -132,14 +132,14 @@ TEST_CASE("when writing and erasing, used/erased counts are updated correctly", CHECK(page.getErasedEntryCount() == 1); for (size_t i = 0; i < Page::ENTRY_COUNT - 2; ++i) { char name[16]; - snprintf(name, sizeof(name), "i%ld", i); + snprintf(name, sizeof(name), "i%ld", (long int)i); CHECK(page.writeItem(1, name, i) == ESP_OK); } CHECK(page.getUsedEntryCount() == Page::ENTRY_COUNT - 1); CHECK(page.getErasedEntryCount() == 1); for (size_t i = 0; i < Page::ENTRY_COUNT - 2; ++i) { char name[16]; - snprintf(name, sizeof(name), "i%ld", i); + snprintf(name, sizeof(name), "i%ld", (long int)i); CHECK(page.eraseItem(1, itemTypeOf(), name) == ESP_OK); } CHECK(page.getUsedEntryCount() == 1); @@ -153,7 +153,7 @@ TEST_CASE("when page is full, adding an element fails", "[nvs]") CHECK(page.load(0) == ESP_OK); for (size_t i = 0; i < Page::ENTRY_COUNT; ++i) { char name[16]; - snprintf(name, sizeof(name), "i%ld", i); + snprintf(name, sizeof(name), "i%ld", (long int)i); CHECK(page.writeItem(1, name, i) == ESP_OK); } CHECK(page.writeItem(1, "foo", 64UL) == ESP_ERR_NVS_PAGE_FULL); @@ -259,6 +259,25 @@ TEST_CASE("Page validates blob size", "[nvs]") TEST_ESP_OK(page.writeItem(1, ItemType::BLOB, "2", buf, Page::BLOB_MAX_SIZE)); } +TEST_CASE("Page handles invalid CRC of variable length items", "[nvs][cur]") +{ + SpiFlashEmulator emu(4); + { + Page page; + TEST_ESP_OK(page.load(0)); + char buf[128] = {0}; + TEST_ESP_OK(page.writeItem(1, ItemType::BLOB, "1", buf, sizeof(buf))); + } + // corrupt header of the item (64 is the offset of the first item in page) + uint32_t overwrite_buf = 0; + emu.write(64, &overwrite_buf, 4); + // load page again + { + Page page; + TEST_ESP_OK(page.load(0)); + } +} + TEST_CASE("can init PageManager in empty flash", "[nvs]") { SpiFlashEmulator emu(4); @@ -1123,7 +1142,7 @@ TEST_CASE("crc errors in item header are handled", "[nvs]") // add more items to make the page full for (size_t i = 0; i < Page::ENTRY_COUNT; ++i) { char item_name[Item::MAX_KEY_LENGTH + 1]; - snprintf(item_name, sizeof(item_name), "item_%ld", i); + snprintf(item_name, sizeof(item_name), "item_%ld", (long int)i); TEST_ESP_OK(storage.writeItem(1, item_name, static_cast(i))); } @@ -1246,6 +1265,27 @@ TEST_CASE("multiple partitions access check", "[nvs]") CHECK(v2 == 0xcafebabe); } +TEST_CASE("nvs page selection takes into account free entries also not just erased entries", "[nvs]") +{ + const size_t blob_size = Page::BLOB_MAX_SIZE; + uint8_t blob[blob_size] = {0}; + SpiFlashEmulator emu(3); + TEST_ESP_OK( nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, 0, 3) ); + nvs_handle handle; + TEST_ESP_OK( nvs_open("test", NVS_READWRITE, &handle) ); + // Fill first page + TEST_ESP_OK( nvs_set_blob(handle, "1a", blob, blob_size/3) ); + TEST_ESP_OK( nvs_set_blob(handle, "1b", blob, blob_size) ); + // Fill second page + TEST_ESP_OK( nvs_set_blob(handle, "2a", blob, blob_size) ); + TEST_ESP_OK( nvs_set_blob(handle, "2b", blob, blob_size) ); + + // The item below should be able to fit the first page. + TEST_ESP_OK( nvs_set_blob(handle, "3a", blob, 4) ); + TEST_ESP_OK( nvs_commit(handle) ); + nvs_close(handle); +} + TEST_CASE("dump all performance data", "[nvs]") { std::cout << "====================" << std::endl << "Dumping benchmarks" << std::endl; diff --git a/components/spi_flash/src/spi_flash.c b/components/spi_flash/src/spi_flash.c index 74fbaf68a..d1411705f 100644 --- a/components/spi_flash/src/spi_flash.c +++ b/components/spi_flash/src/spi_flash.c @@ -392,7 +392,7 @@ static bool spi_flash_check_wr_protect(void) } //GD25Q32C:0X16409D //GD25Q128 - else if(((flash_id&0xFFFFFFFF)==0X1640C8)||((flash_id&0xFFFFFFFF)==0X1840C8)) { + else if((flash_id & 0xFFFF) == 0x40C8) { if(spi_flash_read_status(&status)==0) { //Read status Ok if(status&SPI_GD25Q32_FLASH_WRITE_PROTECT_STATUS) { special_flash_write_status(0x01, status&(~(SPI_GD25Q32_FLASH_WRITE_PROTECT_STATUS)), 1, true); diff --git a/examples/system/ota/main/ota_example_main.c b/examples/system/ota/main/ota_example_main.c index cfbfc76d9..4f7694c72 100644 --- a/examples/system/ota/main/ota_example_main.c +++ b/examples/system/ota/main/ota_example_main.c @@ -212,6 +212,18 @@ static void ota_example_task(void *pvParameter) task_fatal_error(); } + update_partition = esp_ota_get_next_update_partition(NULL); + ESP_LOGI(TAG, "Writing to partition subtype %d at offset 0x%x", + update_partition->subtype, update_partition->address); + assert(update_partition != NULL); + + err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle); + if (err != ESP_OK) { + ESP_LOGE(TAG, "esp_ota_begin failed, error=%d", err); + task_fatal_error(); + } + ESP_LOGI(TAG, "esp_ota_begin succeeded"); + /*send GET request to http server*/ const char *GET_FORMAT = "GET %s HTTP/1.0\r\n" @@ -234,18 +246,6 @@ static void ota_example_task(void *pvParameter) ESP_LOGI(TAG, "Send GET request to server succeeded"); } - update_partition = esp_ota_get_next_update_partition(NULL); - ESP_LOGI(TAG, "Writing to partition subtype %d at offset 0x%x", - update_partition->subtype, update_partition->address); - assert(update_partition != NULL); - - err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle); - if (err != ESP_OK) { - ESP_LOGE(TAG, "esp_ota_begin failed, error=%d", err); - task_fatal_error(); - } - ESP_LOGI(TAG, "esp_ota_begin succeeded"); - bool resp_body_start = false, flag = true; /*deal with all receive packet*/ while (flag) { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy