From 622482eb769f5e9664c3638a02703bafb5dd80c8 Mon Sep 17 00:00:00 2001 From: Dong Heng Date: Wed, 15 Jan 2020 11:59:36 +0800 Subject: [PATCH] feat(esp_common): update esp_common 1. add Kconfig file and rename old global macro 2. move some independent files to esp_common --- .../bootloader/subproject/CMakeLists.txt | 2 +- components/bootloader/subproject/Makefile | 1 + .../bootloader_support/src/bootloader_init.c | 18 +-- components/esp8266/CMakeLists.txt | 2 +- components/esp8266/Kconfig | 116 --------------- components/esp8266/Makefile.projbuild | 2 +- components/esp8266/include/esp_event_loop.h | 2 +- components/esp8266/sdkconfig.rename | 17 +++ components/esp8266/source/ets_printf.c | 6 +- components/esp8266/source/phy_init.c | 4 +- components/esp8266/source/startup.c | 5 +- components/esp8266/source/task_wdt.c | 8 +- components/esp_common/CMakeLists.txt | 5 +- components/esp_common/Kconfig | 138 ++++++++++++++++++ .../{esp8266 => esp_common}/include/esp_err.h | 0 components/esp_common/include/esp_task.h | 47 ++++++ .../src}/esp_err_to_name.c | 0 .../esp_gdbstub/esp8266/gdbstub_esp8266.c | 2 +- components/newlib/newlib/port/esp_newlib.c | 2 +- .../console/main/console_example_main.c | 6 +- examples/system/factory-test/main/main.c | 8 +- .../components/unity/unity_platform.c | 2 +- 22 files changed, 241 insertions(+), 152 deletions(-) create mode 100644 components/esp8266/sdkconfig.rename create mode 100644 components/esp_common/Kconfig rename components/{esp8266 => esp_common}/include/esp_err.h (100%) create mode 100644 components/esp_common/include/esp_task.h rename components/{esp8266/source => esp_common/src}/esp_err_to_name.c (100%) diff --git a/components/bootloader/subproject/CMakeLists.txt b/components/bootloader/subproject/CMakeLists.txt index d88334f6..33ef8ce2 100644 --- a/components/bootloader/subproject/CMakeLists.txt +++ b/components/bootloader/subproject/CMakeLists.txt @@ -18,7 +18,7 @@ endif() set(COMPONENTS bootloader esptool_py partition_table esp8266 bootloader_support log spi_flash main) set(BOOTLOADER_BUILD 1) include("${IDF_PATH}/tools/cmake/project.cmake") -set(common_req log) +set(common_req log esp_common) if(LEGACY_INCLUDE_COMMON_HEADERS) list(APPEND common_req soc) endif() diff --git a/components/bootloader/subproject/Makefile b/components/bootloader/subproject/Makefile index ebd028c6..c7879431 100644 --- a/components/bootloader/subproject/Makefile +++ b/components/bootloader/subproject/Makefile @@ -16,6 +16,7 @@ CXXFLAGS = #We cannot include the esp8266 component directly but we need its includes. CFLAGS += -I $(IDF_PATH)/components/esp8266/include -I $(IDF_PATH)/components/util/include +CFLAGS += -I $(IDF_PATH)/components/esp_common/include # The bootloader pseudo-component is also included in this build, for its Kconfig.projbuild to be included. # diff --git a/components/bootloader_support/src/bootloader_init.c b/components/bootloader_support/src/bootloader_init.c index 3035b10b..134e9f81 100644 --- a/components/bootloader_support/src/bootloader_init.c +++ b/components/bootloader_support/src/bootloader_init.c @@ -568,7 +568,7 @@ static void update_flash_config(const esp_image_header_t* pfhdr); static void uart_console_configure(void) { -#if CONFIG_UART0_SWAP_IO +#if CONFIG_ESP_UART0_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); @@ -578,25 +578,25 @@ static void uart_console_configure(void) SET_PERI_REG_MASK(UART_SWAP_REG, 0x4); #endif -#if CONFIG_CONSOLE_UART_NUM == 1 +#if CONFIG_ESP_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); + CLEAR_PERI_REG_MASK(UART_CONF1(CONFIG_ESP_CONSOLE_UART_NUM), UART_RX_FLOW_EN); + CLEAR_PERI_REG_MASK(UART_CONF0(CONFIG_ESP_CONSOLE_UART_NUM), UART_TX_FLOW_EN); - WRITE_PERI_REG(UART_CONF0(CONFIG_CONSOLE_UART_NUM), + WRITE_PERI_REG(UART_CONF0(CONFIG_ESP_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); + SET_PERI_REG_MASK(UART_CONF0(CONFIG_ESP_CONSOLE_UART_NUM), UART_RXFIFO_RST | UART_TXFIFO_RST); + CLEAR_PERI_REG_MASK(UART_CONF0(CONFIG_ESP_CONSOLE_UART_NUM), UART_RXFIFO_RST | UART_TXFIFO_RST); #endif -#ifdef CONFIG_CONSOLE_UART_BAUDRATE - uart_div_modify(CONFIG_CONSOLE_UART_NUM, BOOTLOADER_CONSOLE_CLK_FREQ / CONFIG_CONSOLE_UART_BAUDRATE); +#ifdef CONFIG_ESP_CONSOLE_UART_BAUDRATE + uart_div_modify(CONFIG_ESP_CONSOLE_UART_NUM, BOOTLOADER_CONSOLE_CLK_FREQ / CONFIG_ESP_CONSOLE_UART_BAUDRATE); #endif } diff --git a/components/esp8266/CMakeLists.txt b/components/esp8266/CMakeLists.txt index f66fd36b..f4ffabba 100644 --- a/components/esp8266/CMakeLists.txt +++ b/components/esp8266/CMakeLists.txt @@ -25,7 +25,6 @@ else() "source/chip_boot.c" "source/backtrace.c" "source/esp_sleep.c" - "source/esp_err_to_name.c" "source/esp_timer.c" "source/esp_wifi_os_adapter.c" "source/esp_wifi.c" @@ -54,6 +53,7 @@ else() set(include_dirs "include" "include/driver") + set(requires "esp_common") set(priv_requires "wpa_supplicant" "log" "spi_flash" "tcpip_adapter" "esp_ringbuf" "bootloader_support" "nvs_flash" "util") set(fragments linker.lf ld/esp8266_fragments.lf ld/esp8266_bss_fragments.lf) diff --git a/components/esp8266/Kconfig b/components/esp8266/Kconfig index 55772425..37f4e726 100644 --- a/components/esp8266/Kconfig +++ b/components/esp8266/Kconfig @@ -94,67 +94,12 @@ config SOC_IRAM_SIZE default 0x8000 if SOC_FULL_ICACHE default 0xC000 if !SOC_FULL_ICACHE -choice CONSOLE_UART - prompt "UART for console output" - default CONSOLE_UART_DEFAULT - help - Select whether to use UART for console output (through stdout and stderr). - - - Default is to use UART0. - - If "Custom" is selected, UART0 or UART1 can be chosen. - - If "None" is selected, there will be no console output on any UART. - -config CONSOLE_UART_DEFAULT - bool "Default: UART0" -config CONSOLE_UART_CUSTOM - bool "Custom" -config CONSOLE_UART_NONE - bool "None" -endchoice - -choice CONSOLE_UART_NUM - prompt "UART peripheral to use for console output (0-1)" - depends on CONSOLE_UART_CUSTOM - 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_DEFAULT || CONSOLE_UART_NONE - 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" - depends on CONSOLE_UART_DEFAULT || CONSOLE_UART_CUSTOM - default 74880 - range 1200 4000000 - -config UART0_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. - config DISABLE_ROM_UART_PRINT bool "Disable ROM UART print" default n help "Disable main part of ROM UART print when rom bootloader process." -config PANIC_FULL_STACK - bool "Output full stack data of task" - default n - help - Output full stack data of task although some stack space is not used. - choice ESP_PANIC prompt "Panic handler behaviour" default ESP_PANIC_PRINT_REBOOT @@ -189,51 +134,6 @@ config ESP_PANIC_GDBSTUB The UART's baudrate should be 115200 or others which can be recognized by xtensa GDB. endchoice -config MAIN_TASK_STACK_SIZE - int "Main task stack size" - default 3584 - help - Configure the "main task" stack size. This is the stack of the task - which calls app_main(). If app_main() returns then this task is deleted - and its stack memory is freed. - -config TASK_WDT - bool "Initialize Task Watchdog Timer on startup" - default y - help - The Task Watchdog Timer can be used to make sure individual tasks are still - running. Enabling this option will cause the Task Watchdog Timer to be - initialized automatically at startup. The Task Watchdog timer can be - initialized after startup as well. - -config TASK_WDT_PANIC - bool "Invoke panic handler on Task Watchdog timeout" - default y - help - If this option is enabled, the Task Watchdog Timer will be configured to - trigger the panic handler when it times out. And it may cost some time. - -choice TASK_WDT_TIMEOUT_S - prompt "Task Watchdog timeout period (seconds)" - default TASK_WDT_TIMEOUT_15N - help - Timeout period configuration for the Task Watchdog Timer in seconds. - This is also configurable at run time. - -config TASK_WDT_TIMEOUT_13N - bool "6.5536s" -config TASK_WDT_TIMEOUT_14N - bool "13.1072s" -config TASK_WDT_TIMEOUT_15N - bool "26.2144s" -endchoice - -config TASK_WDT_TIMEOUT_S - int - default 13 if TASK_WDT_TIMEOUT_13N - default 14 if TASK_WDT_TIMEOUT_14N - default 15 if TASK_WDT_TIMEOUT_15N - config RESET_REASON bool "Enable reset reason" default y @@ -249,12 +149,6 @@ config WIFI_PPT_TASKSTACK_SIZE which calls promiscuous callback function. So if user's function is complex, the stack must be set larger. -config EVENT_LOOP_STACK_SIZE - int "Event loop stack size" - default 2048 - help - Configure the Event loop task stack size per application. - config ESP8266_CORE_GLOBAL_DATA_LINK_IRAM bool "Link libcore.a internal global data to IRAM" default y @@ -307,16 +201,6 @@ config ESP8266_BOOT_COPY_APP Enable this option, when it is that "OTA1" application is to run after update by OTA, bootloader will copy "OTA1" application to "OTA0" partition and run "OTA0". -config ESP_ERR_TO_NAME_LOOKUP - bool "Enable lookup of error code strings" - default "y" - help - Functions esp_err_to_name() and esp_err_to_name_r() return string - representations of error codes from a pre-generated lookup table. - This option can be used to turn off the use of the look-up table in - order to save memory but this comes at the price of sacrificing - distinguishable (meaningful) output string representations. - choice ESP8266_TIME_SYSCALL prompt "Timers used for gettimeofday function" default ESP8266_TIME_SYSCALL_USE_FRC1 diff --git a/components/esp8266/Makefile.projbuild b/components/esp8266/Makefile.projbuild index 8a134f8f..e5ae1631 100644 --- a/components/esp8266/Makefile.projbuild +++ b/components/esp8266/Makefile.projbuild @@ -42,7 +42,7 @@ ESP8266_COMPONENT_PATH := $(COMPONENT_PATH) $(PHY_INIT_DATA_OBJ): $(ESP8266_COMPONENT_PATH)/include/internal/phy_init_data.h $(BUILD_DIR_BASE)/include/sdkconfig.h $(summary) CC $(notdir $@) - printf "#include \"internal/phy_init_data.h\"\n" | $(CC) -I $(BUILD_DIR_BASE)/include -I $(ESP8266_COMPONENT_PATH) -I $(ESP8266_COMPONENT_PATH)/include -c -o $@ -xc - + printf "#include \"internal/phy_init_data.h\"\n" | $(CC) -I $(BUILD_DIR_BASE)/include -I $(ESP8266_COMPONENT_PATH) -I $(ESP8266_COMPONENT_PATH)/include -I $(ESP8266_COMPONENT_PATH)/../esp_common/include -c -o $@ -xc - $(PHY_INIT_DATA_BIN): $(PHY_INIT_DATA_OBJ) $(summary) BIN $(notdir $@) diff --git a/components/esp8266/include/esp_event_loop.h b/components/esp8266/include/esp_event_loop.h index 0e582b90..8823b0d3 100644 --- a/components/esp8266/include/esp_event_loop.h +++ b/components/esp8266/include/esp_event_loop.h @@ -23,7 +23,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/queue.h" -#define EVENT_LOOP_STACKSIZE CONFIG_EVENT_LOOP_STACK_SIZE +#define EVENT_LOOP_STACKSIZE CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE #ifdef __cplusplus extern "C" { diff --git a/components/esp8266/sdkconfig.rename b/components/esp8266/sdkconfig.rename new file mode 100644 index 00000000..1f1159b1 --- /dev/null +++ b/components/esp8266/sdkconfig.rename @@ -0,0 +1,17 @@ +# sdkconfig replacement configurations for deprecated options formatted as +# CONFIG_DEPRECATED_OPTION CONFIG_NEW_OPTION + +CONFIG_MAIN_TASK_STACK_SIZE CONFIG_ESP_MAIN_TASK_STACK_SIZE +CONFIG_CONSOLE_UART CONFIG_ESP_CONSOLE_UART +CONFIG_CONSOLE_UART_DEFAULT CONFIG_ESP_CONSOLE_UART_DEFAULT +CONFIG_CONSOLE_UART_CUSTOM CONFIG_ESP_CONSOLE_UART_CUSTOM +CONFIG_CONSOLE_UART_NONE CONFIG_ESP_CONSOLE_UART_NONE +CONFIG_CONSOLE_UART_NUM CONFIG_ESP_CONSOLE_UART_NUM +CONFIG_CONSOLE_UART_CUSTOM_NUM_0 CONFIG_ESP_CONSOLE_UART_CUSTOM_NUM_0 +CONFIG_CONSOLE_UART_CUSTOM_NUM_1 CONFIG_ESP_CONSOLE_UART_CUSTOM_NUM_1 +CONFIG_CONSOLE_UART_BAUDRATE CONFIG_ESP_CONSOLE_UART_BAUDRATE +CONFIG_UART0_SWAP_IO CONFIG_ESP_UART0_SWAP_IO + +CONFIG_TASK_WDT CONFIG_ESP_TASK_WDT +CONFIG_TASK_WDT_PANIC CONFIG_ESP_TASK_WDT_PANIC +CONFIG_TASK_WDT_TIMEOUT_S CONFIG_ESP_TASK_WDT_TIMEOUT_S \ No newline at end of file diff --git a/components/esp8266/source/ets_printf.c b/components/esp8266/source/ets_printf.c index 2c6a0749..3e066dcc 100644 --- a/components/esp8266/source/ets_printf.c +++ b/components/esp8266/source/ets_printf.c @@ -24,17 +24,17 @@ #include "esp8266/uart_register.h" #include "esp8266/rom_functions.h" -#ifndef CONFIG_CONSOLE_UART_NONE +#ifndef CONFIG_ESP_CONSOLE_UART_NONE static void uart_putc(int c) { while (1) { - uint32_t fifo_cnt = READ_PERI_REG(UART_STATUS(CONFIG_CONSOLE_UART_NUM)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S); + uint32_t fifo_cnt = READ_PERI_REG(UART_STATUS(CONFIG_ESP_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_CONSOLE_UART_NUM) , c); + WRITE_PERI_REG(UART_FIFO(CONFIG_ESP_CONSOLE_UART_NUM) , c); } #else #define uart_putc(_c) { } diff --git a/components/esp8266/source/phy_init.c b/components/esp8266/source/phy_init.c index d3351d02..b67ff7bb 100644 --- a/components/esp8266/source/phy_init.c +++ b/components/esp8266/source/phy_init.c @@ -72,8 +72,8 @@ esp_err_t esp_phy_rf_init(const esp_phy_init_data_t* init_data, esp_phy_calibrat esp_err_t status = ESP_OK; uint8_t sta_mac[6]; uint8_t *local_init_data = calloc(1, 256); -#ifdef CONFIG_CONSOLE_UART_BAUDRATE - const uint32_t uart_baudrate = CONFIG_CONSOLE_UART_BAUDRATE; +#ifdef CONFIG_ESP_CONSOLE_UART_BAUDRATE + const uint32_t uart_baudrate = CONFIG_ESP_CONSOLE_UART_BAUDRATE; #else const uint32_t uart_baudrate = 74880; // ROM default baudrate #endif diff --git a/components/esp8266/source/startup.c b/components/esp8266/source/startup.c index 89ef3d81..8a444e73 100644 --- a/components/esp8266/source/startup.c +++ b/components/esp8266/source/startup.c @@ -33,6 +33,7 @@ #include "FreeRTOS.h" #include "task.h" +#include "esp_task.h" #ifndef CONFIG_NEWLIB_LIBRARY_CUSTOMER #include "esp_newlib.h" @@ -93,7 +94,7 @@ static void user_init_entry(void *param) esp_reset_reason_init(); #endif -#ifdef CONFIG_TASK_WDT +#ifdef CONFIG_ESP_TASK_WDT esp_task_wdt_init(); #endif @@ -175,7 +176,7 @@ void call_start_cpu(size_t start_addr) esp_newlib_init(); #endif - assert(xTaskCreate(user_init_entry, "uiT", CONFIG_MAIN_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES, NULL) == pdPASS); + assert(xTaskCreate(user_init_entry, "uiT", ESP_TASK_MAIN_STACK, NULL, configMAX_PRIORITIES, NULL) == pdPASS); vTaskStartScheduler(); } diff --git a/components/esp8266/source/task_wdt.c b/components/esp8266/source/task_wdt.c index 872d9415..744ed87a 100644 --- a/components/esp8266/source/task_wdt.c +++ b/components/esp8266/source/task_wdt.c @@ -23,7 +23,7 @@ static const char *TAG = "wdt"; -#ifdef CONFIG_TASK_WDT_PANIC +#ifdef CONFIG_ESP_TASK_WDT_PANIC /** * @brief Task watch dog interrupt function and it should do panic */ @@ -43,7 +43,7 @@ esp_err_t esp_task_wdt_init(void) { CLEAR_WDT_REG_MASK(WDT_CTL_ADDRESS, BIT0); -#ifdef CONFIG_TASK_WDT_PANIC +#ifdef CONFIG_ESP_TASK_WDT_PANIC const uint32_t panic_time_param = 11; // Just for soft restart @@ -59,9 +59,9 @@ esp_err_t esp_task_wdt_init(void) const uint32_t panic_time_param = 1; #endif - ESP_LOGD(TAG, "task watch dog trigger time parameter is %u", CONFIG_TASK_WDT_TIMEOUT_S); + ESP_LOGD(TAG, "task watch dog trigger time parameter is %u", CONFIG_ESP_TASK_WDT_TIMEOUT_S); - WDT_REG_WRITE(WDT_OP_ADDRESS, CONFIG_TASK_WDT_TIMEOUT_S); // 2^n * 0.8ms, mask 0xf, n = 13 -> (2^13 = 8192) * 0.8 * 0.001 = 6.5536 + WDT_REG_WRITE(WDT_OP_ADDRESS, CONFIG_ESP_TASK_WDT_TIMEOUT_S); // 2^n * 0.8ms, mask 0xf, n = 13 -> (2^13 = 8192) * 0.8 * 0.001 = 6.5536 WDT_REG_WRITE(WDT_OP_ND_ADDRESS, panic_time_param); // 2^n * 0.8ms, mask 0xf, n = 11 -> (2^11 = 2048) * 0.8 * 0.001 = 1.6384 SET_PERI_REG_BITS(PERIPHS_WDT_BASEADDR + WDT_CTL_ADDRESS, WDT_CTL_RSTLEN_MASK, 7 << WDT_CTL_RSTLEN_LSB, 0); diff --git a/components/esp_common/CMakeLists.txt b/components/esp_common/CMakeLists.txt index 6efd9986..b4d319cf 100644 --- a/components/esp_common/CMakeLists.txt +++ b/components/esp_common/CMakeLists.txt @@ -4,8 +4,9 @@ if(BOOTLOADER_BUILD) set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-Wl,--gc-sections") else() # Regular app build - idf_component_register(SRCS "src/stack_check.c" - INCLUDE_DIRS include) + idf_component_register(SRCS "src/stack_check.c" "src/esp_err_to_name.c" + INCLUDE_DIRS include + PRIV_REQUIRES "tcpip_adapter") set_source_files_properties( "src/stack_check.c" diff --git a/components/esp_common/Kconfig b/components/esp_common/Kconfig new file mode 100644 index 00000000..73bd3fd0 --- /dev/null +++ b/components/esp_common/Kconfig @@ -0,0 +1,138 @@ +menu "Common ESP-related" + + config ESP_ERR_TO_NAME_LOOKUP + bool "Enable lookup of error code strings" + default "y" + help + Functions esp_err_to_name() and esp_err_to_name_r() return string representations of error codes from a + pre-generated lookup table. This option can be used to turn off the use of the look-up table in order to + save memory but this comes at the price of sacrificing distinguishable (meaningful) output string + representations. + + config ESP_SYSTEM_EVENT_QUEUE_SIZE + int "System event queue size" + default 32 + help + Config system event queue size in different application. + + config ESP_SYSTEM_EVENT_TASK_STACK_SIZE + int "Event loop task stack size" + default 2048 + help + Config system event task stack size in different application. + + config ESP_MAIN_TASK_STACK_SIZE + int "Main task stack size" + default 3584 + help + Configure the "main task" stack size. This is the stack of the task + which calls app_main(). If app_main() returns then this task is deleted + and its stack memory is freed. + + config ESP_TIMER_TASK_STACK_SIZE + int "High-resolution timer task stack size" + default 3584 + range 2048 65536 + help + Configure the stack size of esp_timer/ets_timer task. This task is used + to dispatch callbacks of timers created using ets_timer and esp_timer + APIs. If you are seing stack overflow errors in timer task, increase + this value. + + Note that this is not the same as FreeRTOS timer task. To configure + FreeRTOS timer task size, see "FreeRTOS timer task stack size" option + in "FreeRTOS" menu. + + choice ESP_CONSOLE_UART + prompt "UART for console output" + default ESP_CONSOLE_UART_DEFAULT + help + Select whether to use UART for console output (through stdout and stderr). + + - Default is to use UART0 on pins GPIO1(TX) and GPIO3(RX). + - If "Custom" is selected, UART0 or UART1 can be chosen, + and any pins can be selected. + - If "None" is selected, there will be no console output on any UART, except + for initial output from ROM bootloader. This output can be further suppressed by + bootstrapping GPIO13 pin to low logic level. + + config ESP_CONSOLE_UART_DEFAULT + bool "Default: UART0, TX=GPIO1, RX=GPIO3" + config ESP_CONSOLE_UART_CUSTOM + bool "Custom" + config ESP_CONSOLE_UART_NONE + bool "None" + endchoice + + choice ESP_CONSOLE_UART_NUM + prompt "UART peripheral to use for console output (0-1)" + depends on ESP_CONSOLE_UART_CUSTOM + default ESP_CONSOLE_UART_CUSTOM_NUM_0 + help + Due of a ROM bug, UART2 is not supported for console output + via ets_printf. + + config ESP_CONSOLE_UART_CUSTOM_NUM_0 + bool "UART0" + config ESP_CONSOLE_UART_CUSTOM_NUM_1 + bool "UART1" + endchoice + + config ESP_CONSOLE_UART_NUM + int + default 0 if ESP_CONSOLE_UART_DEFAULT || ESP_CONSOLE_UART_NONE + default 0 if ESP_CONSOLE_UART_CUSTOM_NUM_0 + default 1 if ESP_CONSOLE_UART_CUSTOM_NUM_1 + + config ESP_CONSOLE_UART_BAUDRATE + int "UART console baud rate" + depends on !ESP_CONSOLE_UART_NONE + default 74880 + range 1200 4000000 + + config ESP_UART0_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. + + config ESP_TASK_WDT + bool "Initialize Task Watchdog Timer on startup" + default y + help + The Task Watchdog Timer can be used to make sure individual tasks are still + running. Enabling this option will cause the Task Watchdog Timer to be + initialized automatically at startup. The Task Watchdog timer can be + initialized after startup as well (see Task Watchdog Timer API Reference) + + config ESP_TASK_WDT_PANIC + bool "Invoke panic handler on Task Watchdog timeout" + depends on ESP_TASK_WDT + default n + help + If this option is enabled, the Task Watchdog Timer will be configured to + trigger the panic handler when it times out. This can also be configured + at run time (see Task Watchdog Timer API Reference) + + choice ESP_TASK_WDT_TIMEOUT_S + prompt "Task Watchdog timeout period (seconds)" + default TASK_WDT_TIMEOUT_15N + help + Timeout period configuration for the Task Watchdog Timer in seconds. + This is also configurable at run time. + + config ESP_TASK_WDT_TIMEOUT_13N + bool "6.5536s" + config ESP_TASK_WDT_TIMEOUT_14N + bool "13.1072s" + config ESP_TASK_WDT_TIMEOUT_15N + bool "26.2144s" + endchoice + + config ESP_TASK_WDT_TIMEOUT_S + int + default 13 if ESP_TASK_WDT_TIMEOUT_13N + default 14 if ESP_TASK_WDT_TIMEOUT_14N + default 15 if ESP_TASK_WDT_TIMEOUT_15N + +endmenu # Common ESP-related diff --git a/components/esp8266/include/esp_err.h b/components/esp_common/include/esp_err.h similarity index 100% rename from components/esp8266/include/esp_err.h rename to components/esp_common/include/esp_err.h diff --git a/components/esp_common/include/esp_task.h b/components/esp_common/include/esp_task.h new file mode 100644 index 00000000..2178ffa7 --- /dev/null +++ b/components/esp_common/include/esp_task.h @@ -0,0 +1,47 @@ +// Copyright 2020-2021 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. + +/* Notes: + * 1. Put all task priority and stack size definition in this file + * 2. If the task priority is less than 10, use ESP_TASK_PRIO_MIN + X style, + * otherwise use ESP_TASK_PRIO_MAX - X style + * 3. If this is a daemon task, the macro prefix is ESP_TASKD_, otherwise + * it's ESP_TASK_ + * 4. If the configMAX_PRIORITIES is modified, please make all priority are + * greater than 0 + * 5. Make sure esp_task.h is consistent between wifi lib and idf + */ + +#ifndef _ESP_TASK_H_ +#define _ESP_TASK_H_ + +#include "sdkconfig.h" +#include "freertos/FreeRTOSConfig.h" + +#define ESP_TASK_PRIO_MAX (configMAX_PRIORITIES) +#define ESP_TASK_PRIO_MIN (0) + +#define TASK_EXTRA_STACK_SIZE (0) + +/* idf task */ +#define ESP_TASK_TIMER_PRIO (ESP_TASK_PRIO_MAX - 3) +#define ESP_TASK_TIMER_STACK (CONFIG_ESP_TIMER_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE) +#define ESP_TASKD_EVENT_PRIO (ESP_TASK_PRIO_MAX - 5) +#define ESP_TASKD_EVENT_STACK (CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE) +#define ESP_TASK_TCPIP_PRIO (ESP_TASK_PRIO_MAX - 7) +#define ESP_TASK_TCPIP_STACK (CONFIG_LWIP_TCPIP_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE) +#define ESP_TASK_MAIN_PRIO (ESP_TASK_PRIO_MIN + 1) +#define ESP_TASK_MAIN_STACK (CONFIG_ESP_MAIN_TASK_STACK_SIZE + TASK_EXTRA_STACK_SIZE) + +#endif diff --git a/components/esp8266/source/esp_err_to_name.c b/components/esp_common/src/esp_err_to_name.c similarity index 100% rename from components/esp8266/source/esp_err_to_name.c rename to components/esp_common/src/esp_err_to_name.c diff --git a/components/esp_gdbstub/esp8266/gdbstub_esp8266.c b/components/esp_gdbstub/esp8266/gdbstub_esp8266.c index 6878fe1c..e5e77c26 100644 --- a/components/esp_gdbstub/esp8266/gdbstub_esp8266.c +++ b/components/esp_gdbstub/esp8266/gdbstub_esp8266.c @@ -17,7 +17,7 @@ #include "sdkconfig.h" #include "esp_task_wdt.h" -#define UART_NUM CONFIG_CONSOLE_UART_NUM +#define UART_NUM CONFIG_ESP_CONSOLE_UART_NUM void esp_gdbstub_target_init(void) { diff --git a/components/newlib/newlib/port/esp_newlib.c b/components/newlib/newlib/port/esp_newlib.c index a84ee029..de5a479b 100644 --- a/components/newlib/newlib/port/esp_newlib.c +++ b/components/newlib/newlib/port/esp_newlib.c @@ -52,7 +52,7 @@ void esp_reent_init(struct _reent* r) */ int esp_newlib_init(void) { - const char *default_uart_dev = "/dev/uart/" STR(CONFIG_CONSOLE_UART_NUM); + const char *default_uart_dev = "/dev/uart/" STR(CONFIG_ESP_CONSOLE_UART_NUM); esp_reent_init(_global_impure_ptr); diff --git a/examples/system/console/main/console_example_main.c b/examples/system/console/main/console_example_main.c index 89682545..73d164ae 100644 --- a/examples/system/console/main/console_example_main.c +++ b/examples/system/console/main/console_example_main.c @@ -52,14 +52,14 @@ static void initialize_console() .parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1, }; - ESP_ERROR_CHECK( uart_param_config(CONFIG_CONSOLE_UART_NUM, &uart_config) ); + ESP_ERROR_CHECK( uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config) ); /* Install UART driver for interrupt-driven reads and writes */ - ESP_ERROR_CHECK( uart_driver_install(CONFIG_CONSOLE_UART_NUM, + ESP_ERROR_CHECK( uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0) ); /* Tell VFS to use UART driver */ - esp_vfs_dev_uart_use_driver(CONFIG_CONSOLE_UART_NUM); + esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM); /* Initialize the console */ esp_console_config_t console_config = { diff --git a/examples/system/factory-test/main/main.c b/examples/system/factory-test/main/main.c index 2adcdfc5..2ac582a5 100644 --- a/examples/system/factory-test/main/main.c +++ b/examples/system/factory-test/main/main.c @@ -25,7 +25,7 @@ #ifndef ESP_FACTORY_TEST_EXTRA_COMPONENTS -#define CONFIG_CONSOLE_UART_NUM 0 +#define CONFIG_ESP_CONSOLE_UART_NUM 0 #define TAG "factory-test" @@ -48,14 +48,14 @@ static void initialize_console() .parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1, }; - ESP_ERROR_CHECK(uart_param_config(CONFIG_CONSOLE_UART_NUM, &uart_config)); + ESP_ERROR_CHECK(uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config)); /* Install UART driver for interrupt-driven reads and writes */ - ESP_ERROR_CHECK(uart_driver_install(CONFIG_CONSOLE_UART_NUM, + ESP_ERROR_CHECK(uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0)); /* Tell VFS to use UART driver */ - esp_vfs_dev_uart_use_driver(CONFIG_CONSOLE_UART_NUM); + esp_vfs_dev_uart_use_driver(CONFIG_ESP_CONSOLE_UART_NUM); esp_console_register_rftest_command(); diff --git a/tools/unit-test-app/components/unity/unity_platform.c b/tools/unit-test-app/components/unity/unity_platform.c index 0eda486e..c453dd3e 100644 --- a/tools/unit-test-app/components/unity/unity_platform.c +++ b/tools/unit-test-app/components/unity/unity_platform.c @@ -194,7 +194,7 @@ static void unity_run_single_test(const struct test_desc_t* test) printf("Running %s...\n", test->name); // Unit test runner expects to see test name before the test starts fflush(stdout); - uart_tx_wait_idle(CONFIG_CONSOLE_UART_NUM); + uart_tx_wait_idle(CONFIG_ESP_CONSOLE_UART_NUM); Unity.TestFile = test->file; Unity.CurrentDetail1 = test->desc;