From ae15c81dbe18026ddd9884381d5580728af6d8a8 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Thu, 18 Feb 2021 21:09:27 +0800 Subject: [PATCH 01/17] esp_common: move to esp_hw_support --- components/esp32/Kconfig | 2 +- components/esp32s2/Kconfig | 2 +- components/esp32s3/Kconfig | 2 +- components/esp_common/CMakeLists.txt | 4 - components/esp_common/Kconfig | 18 ----- components/esp_common/src/fpga_overrides.c | 73 ------------------- components/esp_hw_support/CMakeLists.txt | 4 +- components/esp_hw_support/Kconfig | 26 +++++++ .../Kconfig.spiram.common | 0 components/esp_hw_support/component.mk | 3 +- .../include/esp_crc.h | 0 .../include/esp_fault.h | 0 .../include/esp_interface.h | 0 .../src => esp_hw_support}/mac_addr.c | 0 14 files changed, 34 insertions(+), 100 deletions(-) delete mode 100644 components/esp_common/src/fpga_overrides.c create mode 100644 components/esp_hw_support/Kconfig rename components/{esp_common => esp_hw_support}/Kconfig.spiram.common (100%) rename components/{esp_common => esp_hw_support}/include/esp_crc.h (100%) rename components/{esp_common => esp_hw_support}/include/esp_fault.h (100%) rename components/{esp_common => esp_hw_support}/include/esp_interface.h (100%) rename components/{esp_common/src => esp_hw_support}/mac_addr.c (100%) diff --git a/components/esp32/Kconfig b/components/esp32/Kconfig index 3788e97bc1..ef84997304 100644 --- a/components/esp32/Kconfig +++ b/components/esp32/Kconfig @@ -122,7 +122,7 @@ menu "ESP32-specific" endchoice # insert non-chip-specific items here - source "$IDF_PATH/components/esp_common/Kconfig.spiram.common" + source "$IDF_PATH/components/esp_hw_support/Kconfig.spiram.common" config SPIRAM_CACHE_WORKAROUND bool "Enable workaround for bug in SPI RAM cache for Rev1 ESP32s" diff --git a/components/esp32s2/Kconfig b/components/esp32s2/Kconfig index 9ff302f698..b4aa25dfd2 100644 --- a/components/esp32s2/Kconfig +++ b/components/esp32s2/Kconfig @@ -192,7 +192,7 @@ menu "ESP32S2-specific" endchoice # insert non-chip-specific items here - source "$IDF_PATH/components/esp_common/Kconfig.spiram.common" + source "$IDF_PATH/components/esp_hw_support/Kconfig.spiram.common" endmenu diff --git a/components/esp32s3/Kconfig b/components/esp32s3/Kconfig index a083bd6a57..6e17dddd0c 100644 --- a/components/esp32s3/Kconfig +++ b/components/esp32s3/Kconfig @@ -242,7 +242,7 @@ menu "ESP32S3-Specific" endchoice # insert non-chip-specific items here - source "$IDF_PATH/components/esp_common/Kconfig.spiram.common" + source "$IDF_PATH/components/esp_hw_support/Kconfig.spiram.common" endmenu diff --git a/components/esp_common/CMakeLists.txt b/components/esp_common/CMakeLists.txt index 27b1e9b01a..7818a4b6a8 100644 --- a/components/esp_common/CMakeLists.txt +++ b/components/esp_common/CMakeLists.txt @@ -1,8 +1,5 @@ idf_build_get_property(target IDF_TARGET) -if(CONFIG_IDF_ENV_FPGA) - list(APPEND srcs "src/fpga_overrides.c") -endif() if(BOOTLOADER_BUILD) # For bootloader, all we need from esp_common is headers @@ -16,7 +13,6 @@ else() "src/esp_err.c" "src/esp_err_to_name.c" "src/freertos_hooks.c" - "src/mac_addr.c" "src/stack_check.c" "src/task_wdt.c" "src/int_wdt.c") diff --git a/components/esp_common/Kconfig b/components/esp_common/Kconfig index ab0c2277bd..d7aabd92d8 100644 --- a/components/esp_common/Kconfig +++ b/components/esp_common/Kconfig @@ -286,24 +286,6 @@ menu "Common ESP-related" Debug stubs are used by OpenOCD to execute pre-compiled onboard code which does some useful debugging stuff, e.g. GCOV data dump. - config ESP_MAC_ADDR_UNIVERSE_WIFI_STA - bool - - config ESP_MAC_ADDR_UNIVERSE_WIFI_AP - bool - - config ESP_MAC_ADDR_UNIVERSE_BT - bool - - config ESP_MAC_ADDR_UNIVERSE_BT_OFFSET - int - default 2 if ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR - default 1 if ESP32_UNIVERSAL_MAC_ADDRESSES_TWO - default 1 - - config ESP_MAC_ADDR_UNIVERSE_ETH - bool - config ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY # Invisible option that is set by SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY, but # exists even if SPIRAM is not supported diff --git a/components/esp_common/src/fpga_overrides.c b/components/esp_common/src/fpga_overrides.c deleted file mode 100644 index b309bef623..0000000000 --- a/components/esp_common/src/fpga_overrides.c +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2010-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#include "sdkconfig.h" -#include "soc/soc.h" -#include "soc/rtc.h" -#include "soc/rtc_cntl_reg.h" -#include "esp_log.h" -#include "esp_rom_sys.h" -#include "esp_rom_uart.h" -#include "esp_attr.h" - -static const char *TAG = "fpga"; - -extern void ets_update_cpu_frequency(uint32_t ticks_per_us); - -static void s_warn(void) -{ - ESP_EARLY_LOGW(TAG, "Project configuration is for internal FPGA use, not all functions will work"); -} - -void bootloader_clock_configure(void) -{ - s_warn(); - esp_rom_uart_tx_wait_idle(0); - - uint32_t xtal_freq_mhz = 40; -#ifdef CONFIG_IDF_TARGET_ESP32S2 - uint32_t apb_freq_hz = 20000000; -#else - uint32_t apb_freq_hz = 40000000; -#endif // CONFIG_IDF_TARGET_ESP32S2 - ets_update_cpu_frequency(apb_freq_hz / 1000000); - REG_WRITE(RTC_CNTL_STORE5_REG, (apb_freq_hz >> 12) | ((apb_freq_hz >> 12) << 16)); - REG_WRITE(RTC_CNTL_STORE4_REG, (xtal_freq_mhz) | ((xtal_freq_mhz) << 16)); -} - -/* Placed in IRAM since test_apps expects it to be */ -void IRAM_ATTR bootloader_fill_random(void *buffer, size_t length) -{ - uint8_t *buffer_bytes = (uint8_t *)buffer; - for (int i = 0; i < length; i++) { - buffer_bytes[i] = 0x5A; - } -} - -void esp_clk_init(void) -{ - s_warn(); -} - -void esp_perip_clk_init(void) -{ - -} - -/** - * @brief No-op function, used to force linking this file - * - */ -void esp_common_include_fpga_overrides(void) -{ -} diff --git a/components/esp_hw_support/CMakeLists.txt b/components/esp_hw_support/CMakeLists.txt index 7b8994d950..879b1999ca 100644 --- a/components/esp_hw_support/CMakeLists.txt +++ b/components/esp_hw_support/CMakeLists.txt @@ -7,7 +7,9 @@ endif() set(srcs "compare_set.c" "cpu_util.c") if(NOT BOOTLOADER_BUILD) - list(APPEND srcs "clk_ctrl_os.c") + list(APPEND srcs "clk_ctrl_os.c" "mac_addr.c") +endif() + endif() idf_component_register(SRCS ${srcs} diff --git a/components/esp_hw_support/Kconfig b/components/esp_hw_support/Kconfig new file mode 100644 index 0000000000..1098919b7e --- /dev/null +++ b/components/esp_hw_support/Kconfig @@ -0,0 +1,26 @@ +menu "Hardware Settings" + menu "MAC Config" + config ESP_UNIVERSAL_MAC_ADDRESSES + int + default 2 if ESP32_UNIVERSAL_MAC_ADDRESSES_TWO + default 4 if ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR + + config ESP_MAC_ADDR_UNIVERSE_WIFI_STA + bool + + config ESP_MAC_ADDR_UNIVERSE_WIFI_AP + bool + + config ESP_MAC_ADDR_UNIVERSE_BT + bool + + config ESP_MAC_ADDR_UNIVERSE_BT_OFFSET + int + default 2 if ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR + default 1 if ESP32_UNIVERSAL_MAC_ADDRESSES_TWO + default 1 + + config ESP_MAC_ADDR_UNIVERSE_ETH + bool + endmenu +endmenu diff --git a/components/esp_common/Kconfig.spiram.common b/components/esp_hw_support/Kconfig.spiram.common similarity index 100% rename from components/esp_common/Kconfig.spiram.common rename to components/esp_hw_support/Kconfig.spiram.common diff --git a/components/esp_hw_support/component.mk b/components/esp_hw_support/component.mk index 867056fdc0..f3c83d7505 100644 --- a/components/esp_hw_support/component.mk +++ b/components/esp_hw_support/component.mk @@ -5,5 +5,6 @@ COMPONENT_ADD_LDFRAGMENTS := linker.lf port/$(IDF_TARGET)/rtc_clk.o: CFLAGS += -fno-jump-tables -fno-tree-switch-conversion ifdef IS_BOOTLOADER_BUILD -COMPONENT_OBJEXCLUDE += clk_ctrl_os.o +COMPONENT_OBJEXCLUDE += clk_ctrl_os.o mac_addr.o + endif diff --git a/components/esp_common/include/esp_crc.h b/components/esp_hw_support/include/esp_crc.h similarity index 100% rename from components/esp_common/include/esp_crc.h rename to components/esp_hw_support/include/esp_crc.h diff --git a/components/esp_common/include/esp_fault.h b/components/esp_hw_support/include/esp_fault.h similarity index 100% rename from components/esp_common/include/esp_fault.h rename to components/esp_hw_support/include/esp_fault.h diff --git a/components/esp_common/include/esp_interface.h b/components/esp_hw_support/include/esp_interface.h similarity index 100% rename from components/esp_common/include/esp_interface.h rename to components/esp_hw_support/include/esp_interface.h diff --git a/components/esp_common/src/mac_addr.c b/components/esp_hw_support/mac_addr.c similarity index 100% rename from components/esp_common/src/mac_addr.c rename to components/esp_hw_support/mac_addr.c From 5fce7f4a41d167be95b3f0dd6a6d3dd9412c8ac8 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Tue, 26 Jan 2021 10:48:12 +0800 Subject: [PATCH 02/17] esp_common: move dbg_stubs --- components/esp_common/CMakeLists.txt | 4 - components/esp_common/Kconfig | 8 -- components/esp_common/src/dbg_stubs.c | 95 ------------------- components/esp_system/CMakeLists.txt | 24 +++-- components/esp_system/Kconfig | 9 ++ .../include/esp_private/dbg_stubs.h | 8 ++ components/esp_system/sdkconfig.rename | 1 + 7 files changed, 34 insertions(+), 115 deletions(-) delete mode 100644 components/esp_common/src/dbg_stubs.c rename components/{esp_common => esp_system}/include/esp_private/dbg_stubs.h (95%) diff --git a/components/esp_common/CMakeLists.txt b/components/esp_common/CMakeLists.txt index 7818a4b6a8..c93f3e5310 100644 --- a/components/esp_common/CMakeLists.txt +++ b/components/esp_common/CMakeLists.txt @@ -17,10 +17,6 @@ else() "src/task_wdt.c" "src/int_wdt.c") - if(NOT CONFIG_IDF_TARGET_ESP32C3) - list(APPEND srcs "src/dbg_stubs.c") - endif() - # Note: esp_ipc, esp_pm added as a public requirement to keep compatibility as to be located here. idf_component_register(SRCS "${srcs}" INCLUDE_DIRS include diff --git a/components/esp_common/Kconfig b/components/esp_common/Kconfig index d7aabd92d8..88d983ecfc 100644 --- a/components/esp_common/Kconfig +++ b/components/esp_common/Kconfig @@ -278,14 +278,6 @@ menu "Common ESP-related" complex issues with crashes while flash cache is disabled (for example, when writing to SPI flash.) - config ESP_DEBUG_STUBS_ENABLE - bool - default COMPILER_OPTIMIZATION_LEVEL_DEBUG - depends on !ESP32_TRAX && !ESP32S2_TRAX - help - Debug stubs are used by OpenOCD to execute pre-compiled onboard code - which does some useful debugging stuff, e.g. GCOV data dump. - config ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY # Invisible option that is set by SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY, but # exists even if SPIRAM is not supported diff --git a/components/esp_common/src/dbg_stubs.c b/components/esp_common/src/dbg_stubs.c deleted file mode 100644 index 1ee9124897..0000000000 --- a/components/esp_common/src/dbg_stubs.c +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2017 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. - -// This module implements debug/trace stubs. The stub is a piece of special code which can invoked by OpenOCD -// Currently one stub is used for GCOV functionality -// - -#include "eri.h" -#include "xtensa-debug-module.h" -#include "esp_private/dbg_stubs.h" -#include "esp_attr.h" - -#if CONFIG_ESP_DEBUG_STUBS_ENABLE -/* - Debug stubs is actually a table of 4-byte entries. Every entry is equal to zero or must contain meaningfull data. - The first entry is a service one and has the followinf format: - - tramp_addr, 4 bytes; Address of buffer for trampoline/code. Max size is ESP_DBG_STUBS_CODE_BUF_SIZE. - - min_stack_addr, 4 bytes; Start of the buffer for minimal onboard stack or data. Max size is ESP_DBG_STUBS_STACK_MIN_SIZE. - - data_alloc, 4 bytes; Address of function to allocate memory on target. - - data_free, 4 bytes; Address of function to free target memory. - This entry is used by OpenOCD code to invoke other stub entries and allocate memory for them. - */ - -#define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL -#include "esp_log.h" -const static char *TAG = "esp_dbg_stubs"; - -#define ESP_DBG_STUBS_TRAX_REG ERI_TRAX_TRIGGERPC -#define ESP_DBG_STUBS_CODE_BUF_SIZE 32 -#define ESP_DBG_STUBS_STACK_MIN_SIZE 2048 - -#define DBG_STUB_TRAMP_ATTR IRAM_ATTR - -static struct { - uint32_t tramp_addr; - uint32_t min_stack_addr; // minimal stack addr - uint32_t data_alloc; - uint32_t data_free; -} s_dbg_stubs_ctl_data; - -static uint32_t s_stub_entry[ESP_DBG_STUB_ENTRY_MAX]; -static uint8_t s_stub_min_stack[ESP_DBG_STUBS_STACK_MIN_SIZE]; -static DBG_STUB_TRAMP_ATTR uint8_t s_stub_code_buf[ESP_DBG_STUBS_CODE_BUF_SIZE]; - -// TODO: all called funcs should be in IRAM to work with disabled flash cache -static void * esp_dbg_stubs_data_alloc(uint32_t size) -{ - ESP_LOGV(TAG, "%s %d", __func__, size); - void *p = malloc(size); - ESP_LOGV(TAG, "%s EXIT %p", __func__, p); - return p; -} - -static void esp_dbg_stubs_data_free(void *addr) -{ - ESP_LOGV(TAG, "%s %p", __func__, addr); - free(addr); - ESP_LOGV(TAG, "%s EXIT %p", __func__, addr); -} - -void esp_dbg_stubs_init(void) -{ - s_dbg_stubs_ctl_data.tramp_addr = (uint32_t)s_stub_code_buf; - s_dbg_stubs_ctl_data.min_stack_addr = (uint32_t)s_stub_min_stack; - s_dbg_stubs_ctl_data.data_alloc = (uint32_t)esp_dbg_stubs_data_alloc; - s_dbg_stubs_ctl_data.data_free = (uint32_t)esp_dbg_stubs_data_free; - - s_stub_entry[ESP_DBG_STUB_CONTROL_DATA] = (uint32_t)&s_dbg_stubs_ctl_data; - eri_write(ESP_DBG_STUBS_TRAX_REG, (uint32_t)s_stub_entry); - ESP_LOGV(TAG, "%s stubs %x", __func__, eri_read(ESP_DBG_STUBS_TRAX_REG)); -} - -esp_err_t esp_dbg_stub_entry_set(esp_dbg_stub_id_t id, uint32_t entry) -{ - if (id < ESP_DBG_STUB_ENTRY_FIRST || id >= ESP_DBG_STUB_ENTRY_MAX) { - ESP_LOGE(TAG, "Invalid stub id %d!", id); - return ESP_ERR_INVALID_ARG; - } - s_stub_entry[id] = entry; - - return ESP_OK; -} - -#endif diff --git a/components/esp_system/CMakeLists.txt b/components/esp_system/CMakeLists.txt index f6e9d7b8a2..ba06c0df28 100644 --- a/components/esp_system/CMakeLists.txt +++ b/components/esp_system/CMakeLists.txt @@ -4,13 +4,21 @@ if(BOOTLOADER_BUILD) return() endif() -idf_component_register(SRCS "intr_alloc.c" - "esp_async_memcpy.c" - "panic.c" - "system_api.c" - "startup.c" - "system_time.c" - "sleep_modes.c" +idf_build_get_property(target IDF_TARGET) + +set(srcs "intr_alloc.c" + "esp_async_memcpy.c" + "panic.c" + "system_api.c" + "startup.c" + "system_time.c" + "sleep_modes.c") + +if(NOT (${target} STREQUAL "esp32c3") ) + list(APPEND srcs "dbg_stubs.c") +endif() + +idf_component_register(SRCS "${srcs}" INCLUDE_DIRS include PRIV_REQUIRES spi_flash # [refactor-todo] requirements due to init code, @@ -18,9 +26,9 @@ idf_component_register(SRCS "intr_alloc.c" # link-time registration is used. esp_pm app_update nvs_flash pthread app_trace esp_gdbstub LDFRAGMENTS "linker.lf") - add_subdirectory(port) + # After system initialization, `start_app` (and its other cores variant) is called. # This is provided by the user or from another component. Since we can't establish # dependency on what we don't know, force linker to not drop the symbol regardless diff --git a/components/esp_system/Kconfig b/components/esp_system/Kconfig index 16171815e8..00f7c84ec7 100644 --- a/components/esp_system/Kconfig +++ b/components/esp_system/Kconfig @@ -121,5 +121,14 @@ menu "ESP System Settings" The lock is reset only on the chip startup. endmenu # Memory protection + + config ESP_DEBUG_STUBS_ENABLE + bool + default COMPILER_OPTIMIZATION_LEVEL_DEBUG + depends on !ESP32_TRAX && !ESP32S2_TRAX + help + Debug stubs are used by OpenOCD to execute pre-compiled onboard code + which does some useful debugging stuff, e.g. GCOV data dump. + endmenu # ESP System Settings diff --git a/components/esp_common/include/esp_private/dbg_stubs.h b/components/esp_system/include/esp_private/dbg_stubs.h similarity index 95% rename from components/esp_common/include/esp_private/dbg_stubs.h rename to components/esp_system/include/esp_private/dbg_stubs.h index c784de9845..f3f5fba3b7 100644 --- a/components/esp_common/include/esp_private/dbg_stubs.h +++ b/components/esp_system/include/esp_private/dbg_stubs.h @@ -14,6 +14,10 @@ #ifndef ESP_DBG_STUBS_H_ #define ESP_DBG_STUBS_H_ +#ifdef __cplusplus +extern "C" { +#endif + #include "esp_err.h" /** @@ -47,4 +51,8 @@ void esp_dbg_stubs_init(void); */ esp_err_t esp_dbg_stub_entry_set(esp_dbg_stub_id_t id, uint32_t entry); +#ifdef __cplusplus +} +#endif + #endif //ESP_DBG_STUBS_H_ diff --git a/components/esp_system/sdkconfig.rename b/components/esp_system/sdkconfig.rename index 33bdd49f17..cd834310c2 100644 --- a/components/esp_system/sdkconfig.rename +++ b/components/esp_system/sdkconfig.rename @@ -16,3 +16,4 @@ CONFIG_ESP32C3_MEMPROT_FEATURE CONFIG_ESP_SYSTEM_MEMPRO CONFIG_ESP32C3_MEMPROT_FEATURE_LOCK CONFIG_ESP_SYSTEM_MEMPROT_FEATURE_LOCK CONFIG_ESP32_RTC_XTAL_BOOTSTRAP_CYCLES CONFIG_ESP_SYSTEM_RTC_EXT_XTAL_BOOTSTRAP_CYCLES +CONFIG_ESP32_DEBUG_STUBS_ENABLE CONFIG_ESP_DEBUG_STUBS_ENABLE From deaad431f4c11c818cb3d0b5ae86210da2963e19 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Tue, 26 Jan 2021 11:20:09 +0800 Subject: [PATCH 03/17] esp_common: move task, int wdt --- components/esp_common/CMakeLists.txt | 4 +- components/esp_common/Kconfig | 71 ------------------- components/esp_common/sdkconfig.rename | 9 --- components/esp_pm/linker.lf | 9 ++- components/esp_system/CMakeLists.txt | 4 +- .../include/esp_int_wdt.h | 0 .../include/esp_task_wdt.h | 0 .../{esp_common/src => esp_system}/int_wdt.c | 0 components/esp_system/sdkconfig.rename | 8 +++ .../{esp_common/src => esp_system}/task_wdt.c | 4 +- 10 files changed, 19 insertions(+), 90 deletions(-) rename components/{esp_common => esp_system}/include/esp_int_wdt.h (100%) rename components/{esp_common => esp_system}/include/esp_task_wdt.h (100%) rename components/{esp_common/src => esp_system}/int_wdt.c (100%) rename components/{esp_common/src => esp_system}/task_wdt.c (99%) diff --git a/components/esp_common/CMakeLists.txt b/components/esp_common/CMakeLists.txt index c93f3e5310..d78ffdda90 100644 --- a/components/esp_common/CMakeLists.txt +++ b/components/esp_common/CMakeLists.txt @@ -13,9 +13,7 @@ else() "src/esp_err.c" "src/esp_err_to_name.c" "src/freertos_hooks.c" - "src/stack_check.c" - "src/task_wdt.c" - "src/int_wdt.c") + "src/stack_check.c") # Note: esp_ipc, esp_pm added as a public requirement to keep compatibility as to be located here. idf_component_register(SRCS "${srcs}" diff --git a/components/esp_common/Kconfig b/components/esp_common/Kconfig index 88d983ecfc..0e4fdd4a46 100644 --- a/components/esp_common/Kconfig +++ b/components/esp_common/Kconfig @@ -193,77 +193,6 @@ menu "Common ESP-related" If enabled, esp_rom_printf and ESP_EARLY_LOG output will also be sent over USB CDC. Disabling this option saves about 1kB or RAM. - config ESP_INT_WDT - bool "Interrupt watchdog" - default y - help - This watchdog timer can detect if the FreeRTOS tick interrupt has not been called for a certain time, - either because a task turned off interrupts and did not turn them on for a long time, or because an - interrupt handler did not return. It will try to invoke the panic handler first and failing that - reset the SoC. - - config ESP_INT_WDT_TIMEOUT_MS - int "Interrupt watchdog timeout (ms)" - depends on ESP_INT_WDT - default 300 if !ESP32_SPIRAM_SUPPORT - default 800 if ESP32_SPIRAM_SUPPORT - range 10 10000 - help - The timeout of the watchdog, in miliseconds. Make this higher than the FreeRTOS tick rate. - - config ESP_INT_WDT_CHECK_CPU1 - bool "Also watch CPU1 tick interrupt" - depends on ESP_INT_WDT && !FREERTOS_UNICORE - default y - help - Also detect if interrupts on CPU 1 are disabled for too long. - - 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) - - config ESP_TASK_WDT_TIMEOUT_S - int "Task Watchdog timeout period (seconds)" - depends on ESP_TASK_WDT - range 1 60 - default 5 - help - Timeout period configuration for the Task Watchdog Timer in seconds. - This is also configurable at run time (see Task Watchdog Timer API Reference) - - config ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 - bool "Watch CPU0 Idle Task" - depends on ESP_TASK_WDT - default y - help - If this option is enabled, the Task Watchdog Timer will watch the CPU0 - Idle Task. Having the Task Watchdog watch the Idle Task allows for detection - of CPU starvation as the Idle Task not being called is usually a symptom of - CPU starvation. Starvation of the Idle Task is detrimental as FreeRTOS household - tasks depend on the Idle Task getting some runtime every now and then. - - config ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 - bool "Watch CPU1 Idle Task" - depends on ESP_TASK_WDT && !FREERTOS_UNICORE - default y - help - If this option is enabled, the Task Wtachdog Timer will wach the CPU1 - Idle Task. - config ESP_PANIC_HANDLER_IRAM bool "Place panic handler code in IRAM" default n diff --git a/components/esp_common/sdkconfig.rename b/components/esp_common/sdkconfig.rename index 5096f42755..419f6206a5 100644 --- a/components/esp_common/sdkconfig.rename +++ b/components/esp_common/sdkconfig.rename @@ -16,14 +16,5 @@ CONFIG_CONSOLE_UART_CUSTOM_NUM_1 CONFIG_ESP_CONSOLE_UART_ CONFIG_CONSOLE_UART_TX_GPIO CONFIG_ESP_CONSOLE_UART_TX_GPIO CONFIG_CONSOLE_UART_RX_GPIO CONFIG_ESP_CONSOLE_UART_RX_GPIO CONFIG_CONSOLE_UART_BAUDRATE CONFIG_ESP_CONSOLE_UART_BAUDRATE -CONFIG_INT_WDT CONFIG_ESP_INT_WDT -CONFIG_INT_WDT_TIMEOUT_MS CONFIG_ESP_INT_WDT_TIMEOUT_MS -CONFIG_INT_WDT_CHECK_CPU1 CONFIG_ESP_INT_WDT_CHECK_CPU1 -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 -CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 -CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 -CONFIG_ESP32_DEBUG_STUBS_ENABLE CONFIG_ESP_DEBUG_STUBS_ENABLE CONFIG_ESP32_ALLOW_RTC_FAST_MEM_AS_HEAP CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP CONFIG_ESP32S2_ALLOW_RTC_FAST_MEM_AS_HEAP CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP diff --git a/components/esp_pm/linker.lf b/components/esp_pm/linker.lf index e4c4b2f9a5..7bb7d05089 100644 --- a/components/esp_pm/linker.lf +++ b/components/esp_pm/linker.lf @@ -12,11 +12,6 @@ archive: libesp_common.a entries: if PM_RTOS_IDLE_OPT = y: freertos_hooks:esp_vApplicationIdleHook (noflash) - task_wdt:idle_hook_cb (noflash) - task_wdt:esp_task_wdt_reset (noflash) - task_wdt:find_task_in_twdt_list (noflash) - task_wdt:reset_hw_timer (noflash) - [mapping:esp_hw_support_pm] archive: libesp_hw_support.a entries: @@ -31,6 +26,10 @@ entries: sleep_modes:esp_sleep_enable_timer_wakeup (noflash) sleep_modes:timer_wakeup_prepare (noflash) sleep_modes:get_power_down_flags (noflash) + task_wdt:idle_hook_cb (noflash) + task_wdt:esp_task_wdt_reset (noflash) + task_wdt:find_task_in_twdt_list (noflash) + task_wdt:reset_hw_timer (noflash) [mapping:esp_timer_pm] archive: libesp_timer.a diff --git a/components/esp_system/CMakeLists.txt b/components/esp_system/CMakeLists.txt index ba06c0df28..621eeaee2d 100644 --- a/components/esp_system/CMakeLists.txt +++ b/components/esp_system/CMakeLists.txt @@ -12,7 +12,9 @@ set(srcs "intr_alloc.c" "system_api.c" "startup.c" "system_time.c" - "sleep_modes.c") + "sleep_modes.c" + "task_wdt.c" + "int_wdt.c") if(NOT (${target} STREQUAL "esp32c3") ) list(APPEND srcs "dbg_stubs.c") diff --git a/components/esp_common/include/esp_int_wdt.h b/components/esp_system/include/esp_int_wdt.h similarity index 100% rename from components/esp_common/include/esp_int_wdt.h rename to components/esp_system/include/esp_int_wdt.h diff --git a/components/esp_common/include/esp_task_wdt.h b/components/esp_system/include/esp_task_wdt.h similarity index 100% rename from components/esp_common/include/esp_task_wdt.h rename to components/esp_system/include/esp_task_wdt.h diff --git a/components/esp_common/src/int_wdt.c b/components/esp_system/int_wdt.c similarity index 100% rename from components/esp_common/src/int_wdt.c rename to components/esp_system/int_wdt.c diff --git a/components/esp_system/sdkconfig.rename b/components/esp_system/sdkconfig.rename index cd834310c2..5ff5eecc74 100644 --- a/components/esp_system/sdkconfig.rename +++ b/components/esp_system/sdkconfig.rename @@ -16,4 +16,12 @@ CONFIG_ESP32C3_MEMPROT_FEATURE CONFIG_ESP_SYSTEM_MEMPRO CONFIG_ESP32C3_MEMPROT_FEATURE_LOCK CONFIG_ESP_SYSTEM_MEMPROT_FEATURE_LOCK CONFIG_ESP32_RTC_XTAL_BOOTSTRAP_CYCLES CONFIG_ESP_SYSTEM_RTC_EXT_XTAL_BOOTSTRAP_CYCLES +CONFIG_INT_WDT CONFIG_ESP_INT_WDT +CONFIG_INT_WDT_TIMEOUT_MS CONFIG_ESP_INT_WDT_TIMEOUT_MS +CONFIG_INT_WDT_CHECK_CPU1 CONFIG_ESP_INT_WDT_CHECK_CPU1 +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 +CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 +CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 CONFIG_ESP32_DEBUG_STUBS_ENABLE CONFIG_ESP_DEBUG_STUBS_ENABLE diff --git a/components/esp_common/src/task_wdt.c b/components/esp_system/task_wdt.c similarity index 99% rename from components/esp_common/src/task_wdt.c rename to components/esp_system/task_wdt.c index 5c73e20774..27a68a5b15 100644 --- a/components/esp_common/src/task_wdt.c +++ b/components/esp_system/task_wdt.c @@ -164,7 +164,9 @@ static void task_wdt_isr(void *arg) for (twdttask=twdt_config->list; twdttask!=NULL; twdttask=twdttask->next) { if (!twdttask->has_reset) { cpu=xTaskGetAffinity(twdttask->task_handle)==0?DRAM_STR("CPU 0"):DRAM_STR("CPU 1"); - if (xTaskGetAffinity(twdttask->task_handle)==tskNO_AFFINITY) cpu=DRAM_STR("CPU 0/1"); + if (xTaskGetAffinity(twdttask->task_handle)==tskNO_AFFINITY) { + cpu=DRAM_STR("CPU 0/1"); + } ESP_EARLY_LOGE(TAG, " - %s (%s)", pcTaskGetTaskName(twdttask->task_handle), cpu); } } From 1d55e6d6b81364fc8e2270090a3c9cb2a95b516f Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Sat, 20 Feb 2021 17:52:30 +0800 Subject: [PATCH 04/17] esp_common: move brownout init --- components/esp_common/CMakeLists.txt | 3 +- components/esp_system/Kconfig | 72 ++++++++++++++++++- components/esp_system/port/CMakeLists.txt | 4 +- .../src => esp_system/port}/brownout.c | 0 4 files changed, 74 insertions(+), 5 deletions(-) rename components/{esp_common/src => esp_system/port}/brownout.c (100%) diff --git a/components/esp_common/CMakeLists.txt b/components/esp_common/CMakeLists.txt index d78ffdda90..474ddfba8d 100644 --- a/components/esp_common/CMakeLists.txt +++ b/components/esp_common/CMakeLists.txt @@ -9,8 +9,7 @@ if(BOOTLOADER_BUILD) set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-Wl,--gc-sections") else() # Regular app build - list(APPEND srcs "src/brownout.c" - "src/esp_err.c" + list(APPEND srcs "src/esp_err.c" "src/esp_err_to_name.c" "src/freertos_hooks.c" "src/stack_check.c") diff --git a/components/esp_system/Kconfig b/components/esp_system/Kconfig index 00f7c84ec7..c223e85e9e 100644 --- a/components/esp_system/Kconfig +++ b/components/esp_system/Kconfig @@ -121,7 +121,77 @@ menu "ESP System Settings" The lock is reset only on the chip startup. endmenu # Memory protection - + + config ESP_INT_WDT + bool "Interrupt watchdog" + default y + help + This watchdog timer can detect if the FreeRTOS tick interrupt has not been called for a certain time, + either because a task turned off interrupts and did not turn them on for a long time, or because an + interrupt handler did not return. It will try to invoke the panic handler first and failing that + reset the SoC. + + config ESP_INT_WDT_TIMEOUT_MS + int "Interrupt watchdog timeout (ms)" + depends on ESP_INT_WDT + default 300 if !ESP32_SPIRAM_SUPPORT + default 800 if ESP32_SPIRAM_SUPPORT + range 10 10000 + help + The timeout of the watchdog, in miliseconds. Make this higher than the FreeRTOS tick rate. + + config ESP_INT_WDT_CHECK_CPU1 + bool "Also watch CPU1 tick interrupt" + depends on ESP_INT_WDT && !FREERTOS_UNICORE + default y + help + Also detect if interrupts on CPU 1 are disabled for too long. + + 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) + + config ESP_TASK_WDT_TIMEOUT_S + int "Task Watchdog timeout period (seconds)" + depends on ESP_TASK_WDT + range 1 60 + default 5 + help + Timeout period configuration for the Task Watchdog Timer in seconds. + This is also configurable at run time (see Task Watchdog Timer API Reference) + + config ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 + bool "Watch CPU0 Idle Task" + depends on ESP_TASK_WDT + default y + help + If this option is enabled, the Task Watchdog Timer will watch the CPU0 + Idle Task. Having the Task Watchdog watch the Idle Task allows for detection + of CPU starvation as the Idle Task not being called is usually a symptom of + CPU starvation. Starvation of the Idle Task is detrimental as FreeRTOS household + tasks depend on the Idle Task getting some runtime every now and then. + + config ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 + bool "Watch CPU1 Idle Task" + depends on ESP_TASK_WDT && !FREERTOS_UNICORE + default y + help + If this option is enabled, the Task Wtachdog Timer will wach the CPU1 + Idle Task. config ESP_DEBUG_STUBS_ENABLE bool default COMPILER_OPTIMIZATION_LEVEL_DEBUG diff --git a/components/esp_system/port/CMakeLists.txt b/components/esp_system/port/CMakeLists.txt index 628c79f007..cc098d8092 100644 --- a/components/esp_system/port/CMakeLists.txt +++ b/components/esp_system/port/CMakeLists.txt @@ -1,6 +1,6 @@ -target_include_directories(${COMPONENT_LIB} PRIVATE include) +target_include_directories(${COMPONENT_LIB} PRIVATE include .) -set(srcs "cpu_start.c" "panic_handler.c") +set(srcs "cpu_start.c" "panic_handler.c" "brownout.c") add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" ${srcs}) target_sources(${COMPONENT_LIB} PRIVATE ${srcs}) diff --git a/components/esp_common/src/brownout.c b/components/esp_system/port/brownout.c similarity index 100% rename from components/esp_common/src/brownout.c rename to components/esp_system/port/brownout.c From 5a56f794ec65380a757f337bad59979b6ac1d463 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Tue, 26 Jan 2021 11:28:34 +0800 Subject: [PATCH 05/17] esp_common: move dbg stubs --- components/esp_system/dbg_stubs.c | 95 +++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 components/esp_system/dbg_stubs.c diff --git a/components/esp_system/dbg_stubs.c b/components/esp_system/dbg_stubs.c new file mode 100644 index 0000000000..1ee9124897 --- /dev/null +++ b/components/esp_system/dbg_stubs.c @@ -0,0 +1,95 @@ +// Copyright 2017 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. + +// This module implements debug/trace stubs. The stub is a piece of special code which can invoked by OpenOCD +// Currently one stub is used for GCOV functionality +// + +#include "eri.h" +#include "xtensa-debug-module.h" +#include "esp_private/dbg_stubs.h" +#include "esp_attr.h" + +#if CONFIG_ESP_DEBUG_STUBS_ENABLE +/* + Debug stubs is actually a table of 4-byte entries. Every entry is equal to zero or must contain meaningfull data. + The first entry is a service one and has the followinf format: + - tramp_addr, 4 bytes; Address of buffer for trampoline/code. Max size is ESP_DBG_STUBS_CODE_BUF_SIZE. + - min_stack_addr, 4 bytes; Start of the buffer for minimal onboard stack or data. Max size is ESP_DBG_STUBS_STACK_MIN_SIZE. + - data_alloc, 4 bytes; Address of function to allocate memory on target. + - data_free, 4 bytes; Address of function to free target memory. + This entry is used by OpenOCD code to invoke other stub entries and allocate memory for them. + */ + +#define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL +#include "esp_log.h" +const static char *TAG = "esp_dbg_stubs"; + +#define ESP_DBG_STUBS_TRAX_REG ERI_TRAX_TRIGGERPC +#define ESP_DBG_STUBS_CODE_BUF_SIZE 32 +#define ESP_DBG_STUBS_STACK_MIN_SIZE 2048 + +#define DBG_STUB_TRAMP_ATTR IRAM_ATTR + +static struct { + uint32_t tramp_addr; + uint32_t min_stack_addr; // minimal stack addr + uint32_t data_alloc; + uint32_t data_free; +} s_dbg_stubs_ctl_data; + +static uint32_t s_stub_entry[ESP_DBG_STUB_ENTRY_MAX]; +static uint8_t s_stub_min_stack[ESP_DBG_STUBS_STACK_MIN_SIZE]; +static DBG_STUB_TRAMP_ATTR uint8_t s_stub_code_buf[ESP_DBG_STUBS_CODE_BUF_SIZE]; + +// TODO: all called funcs should be in IRAM to work with disabled flash cache +static void * esp_dbg_stubs_data_alloc(uint32_t size) +{ + ESP_LOGV(TAG, "%s %d", __func__, size); + void *p = malloc(size); + ESP_LOGV(TAG, "%s EXIT %p", __func__, p); + return p; +} + +static void esp_dbg_stubs_data_free(void *addr) +{ + ESP_LOGV(TAG, "%s %p", __func__, addr); + free(addr); + ESP_LOGV(TAG, "%s EXIT %p", __func__, addr); +} + +void esp_dbg_stubs_init(void) +{ + s_dbg_stubs_ctl_data.tramp_addr = (uint32_t)s_stub_code_buf; + s_dbg_stubs_ctl_data.min_stack_addr = (uint32_t)s_stub_min_stack; + s_dbg_stubs_ctl_data.data_alloc = (uint32_t)esp_dbg_stubs_data_alloc; + s_dbg_stubs_ctl_data.data_free = (uint32_t)esp_dbg_stubs_data_free; + + s_stub_entry[ESP_DBG_STUB_CONTROL_DATA] = (uint32_t)&s_dbg_stubs_ctl_data; + eri_write(ESP_DBG_STUBS_TRAX_REG, (uint32_t)s_stub_entry); + ESP_LOGV(TAG, "%s stubs %x", __func__, eri_read(ESP_DBG_STUBS_TRAX_REG)); +} + +esp_err_t esp_dbg_stub_entry_set(esp_dbg_stub_id_t id, uint32_t entry) +{ + if (id < ESP_DBG_STUB_ENTRY_FIRST || id >= ESP_DBG_STUB_ENTRY_MAX) { + ESP_LOGE(TAG, "Invalid stub id %d!", id); + return ESP_ERR_INVALID_ARG; + } + s_stub_entry[id] = entry; + + return ESP_OK; +} + +#endif From 883aba20be4efdbcef3ed0abe77f2872d2cf9a46 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Tue, 26 Jan 2021 11:31:41 +0800 Subject: [PATCH 06/17] esp_common: move stack check --- components/esp_common/CMakeLists.txt | 8 +----- components/esp_common/component.mk | 6 +---- components/esp_system/CMakeLists.txt | 5 ++-- components/esp_system/stack_check.c | 40 ++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 components/esp_system/stack_check.c diff --git a/components/esp_common/CMakeLists.txt b/components/esp_common/CMakeLists.txt index 474ddfba8d..4bb2fcbb97 100644 --- a/components/esp_common/CMakeLists.txt +++ b/components/esp_common/CMakeLists.txt @@ -11,8 +11,7 @@ else() # Regular app build list(APPEND srcs "src/esp_err.c" "src/esp_err_to_name.c" - "src/freertos_hooks.c" - "src/stack_check.c") + "src/freertos_hooks.c") # Note: esp_ipc, esp_pm added as a public requirement to keep compatibility as to be located here. idf_component_register(SRCS "${srcs}" @@ -21,11 +20,6 @@ else() PRIV_REQUIRES soc LDFRAGMENTS "linker.lf") - set_source_files_properties( - "src/stack_check.c" - PROPERTIES COMPILE_FLAGS - -fno-stack-protector) - set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY LINK_LIBRARIES "-Wl,--gc-sections") set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-Wl,--gc-sections") set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY LINK_INTERFACE_MULTIPLICITY 4) diff --git a/components/esp_common/component.mk b/components/esp_common/component.mk index da494c4b94..01fc42388a 100644 --- a/components/esp_common/component.mk +++ b/components/esp_common/component.mk @@ -4,10 +4,6 @@ COMPONENT_ADD_INCLUDEDIRS := include COMPONENT_SRCDIRS := src - ifndef CONFIG_IDF_ENV_FPGA COMPONENT_OBJEXCLUDE += src/fpga_overrides.o -endif - -# disable stack protection in files which are involved in initialization of that feature -src/stack_check.o: CFLAGS := $(filter-out -fstack-protector%, $(CFLAGS)) +endif \ No newline at end of file diff --git a/components/esp_system/CMakeLists.txt b/components/esp_system/CMakeLists.txt index 621eeaee2d..74a3fdb655 100644 --- a/components/esp_system/CMakeLists.txt +++ b/components/esp_system/CMakeLists.txt @@ -14,7 +14,8 @@ set(srcs "intr_alloc.c" "system_time.c" "sleep_modes.c" "task_wdt.c" - "int_wdt.c") + "int_wdt.c" + "stack_check.c") if(NOT (${target} STREQUAL "esp32c3") ) list(APPEND srcs "dbg_stubs.c") @@ -43,7 +44,7 @@ endif() # Disable stack protection in files which are involved in initialization of that feature set_source_files_properties( - startup.c + "startup.c" "stack_check.c" PROPERTIES COMPILE_FLAGS -fno-stack-protector) diff --git a/components/esp_system/stack_check.c b/components/esp_system/stack_check.c new file mode 100644 index 0000000000..cffff6555a --- /dev/null +++ b/components/esp_system/stack_check.c @@ -0,0 +1,40 @@ +// Copyright 2017 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. + +#include "sdkconfig.h" +#include "esp_system.h" +#include "esp_rom_sys.h" + +#if CONFIG_COMPILER_STACK_CHECK + +#define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL +#include "esp_log.h" +const static char *TAG = "stack_chk"; + +void *__stack_chk_guard = NULL; + +static void __attribute__ ((constructor)) +__esp_stack_guard_setup (void) +{ + ESP_LOGD(TAG, "Intialize random stack guard"); + __stack_chk_guard = (void *)esp_random(); +} + +void __stack_chk_fail (void) +{ + esp_rom_printf("\r\nStack smashing protect failure!\r\n\r\n"); + abort(); +} + +#endif From 840e2c0e50e0e8e44adadd4fdda7354a9727dc55 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Tue, 26 Jan 2021 11:37:25 +0800 Subject: [PATCH 07/17] esp_common: move stack check --- components/esp_common/src/stack_check.c | 40 ------------------------- components/esp_system/component.mk | 2 +- 2 files changed, 1 insertion(+), 41 deletions(-) delete mode 100644 components/esp_common/src/stack_check.c diff --git a/components/esp_common/src/stack_check.c b/components/esp_common/src/stack_check.c deleted file mode 100644 index cffff6555a..0000000000 --- a/components/esp_common/src/stack_check.c +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2017 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. - -#include "sdkconfig.h" -#include "esp_system.h" -#include "esp_rom_sys.h" - -#if CONFIG_COMPILER_STACK_CHECK - -#define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL -#include "esp_log.h" -const static char *TAG = "stack_chk"; - -void *__stack_chk_guard = NULL; - -static void __attribute__ ((constructor)) -__esp_stack_guard_setup (void) -{ - ESP_LOGD(TAG, "Intialize random stack guard"); - __stack_chk_guard = (void *)esp_random(); -} - -void __stack_chk_fail (void) -{ - esp_rom_printf("\r\nStack smashing protect failure!\r\n\r\n"); - abort(); -} - -#endif diff --git a/components/esp_system/component.mk b/components/esp_system/component.mk index d78bcef737..e3ca1f7318 100644 --- a/components/esp_system/component.mk +++ b/components/esp_system/component.mk @@ -8,4 +8,4 @@ COMPONENT_ADD_LDFRAGMENTS += linker.lf include $(COMPONENT_PATH)/port/soc/$(SOC_NAME)/component.mk # disable stack protection in files which are involved in initialization of that feature -startup.o: CFLAGS := $(filter-out -fstack-protector%, $(CFLAGS)) +startup.o stack_check.o: CFLAGS := $(filter-out -fstack-protector%, $(CFLAGS)) From 0e0914476c420e8f298359cc34e4ec661ac0a532 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Tue, 26 Jan 2021 11:41:19 +0800 Subject: [PATCH 08/17] esp_common: move freertos hooks --- components/esp_common/CMakeLists.txt | 3 +-- components/esp_pm/linker.lf | 7 ++----- components/esp_system/CMakeLists.txt | 3 ++- components/{esp_common/src => esp_system}/freertos_hooks.c | 0 .../include/esp_freertos_hooks.h | 3 +++ 5 files changed, 8 insertions(+), 8 deletions(-) rename components/{esp_common/src => esp_system}/freertos_hooks.c (100%) rename components/{esp_common => esp_system}/include/esp_freertos_hooks.h (99%) diff --git a/components/esp_common/CMakeLists.txt b/components/esp_common/CMakeLists.txt index 4bb2fcbb97..1edabc4ea6 100644 --- a/components/esp_common/CMakeLists.txt +++ b/components/esp_common/CMakeLists.txt @@ -10,8 +10,7 @@ if(BOOTLOADER_BUILD) else() # Regular app build list(APPEND srcs "src/esp_err.c" - "src/esp_err_to_name.c" - "src/freertos_hooks.c") + "src/esp_err_to_name.c") # Note: esp_ipc, esp_pm added as a public requirement to keep compatibility as to be located here. idf_component_register(SRCS "${srcs}" diff --git a/components/esp_pm/linker.lf b/components/esp_pm/linker.lf index 7bb7d05089..f1fe2f4baa 100644 --- a/components/esp_pm/linker.lf +++ b/components/esp_pm/linker.lf @@ -7,11 +7,6 @@ entries: if PM_SLP_IRAM_OPT = y && IDF_TARGET_ESP32 = n: pm_impl:periph_inform_out_light_sleep_overhead (noflash) -[mapping:esp_common_pm] -archive: libesp_common.a -entries: - if PM_RTOS_IDLE_OPT = y: - freertos_hooks:esp_vApplicationIdleHook (noflash) [mapping:esp_hw_support_pm] archive: libesp_hw_support.a entries: @@ -21,6 +16,8 @@ entries: [mapping:esp_system_pm] archive: libesp_system.a entries: + if PM_RTOS_IDLE_OPT = y: + freertos_hooks:esp_vApplicationIdleHook (noflash) if PM_SLP_IRAM_OPT = y: sleep_modes:esp_light_sleep_start (noflash) sleep_modes:esp_sleep_enable_timer_wakeup (noflash) diff --git a/components/esp_system/CMakeLists.txt b/components/esp_system/CMakeLists.txt index 74a3fdb655..2b5ea50442 100644 --- a/components/esp_system/CMakeLists.txt +++ b/components/esp_system/CMakeLists.txt @@ -15,7 +15,8 @@ set(srcs "intr_alloc.c" "sleep_modes.c" "task_wdt.c" "int_wdt.c" - "stack_check.c") + "stack_check.c" + "freertos_hooks.c") if(NOT (${target} STREQUAL "esp32c3") ) list(APPEND srcs "dbg_stubs.c") diff --git a/components/esp_common/src/freertos_hooks.c b/components/esp_system/freertos_hooks.c similarity index 100% rename from components/esp_common/src/freertos_hooks.c rename to components/esp_system/freertos_hooks.c diff --git a/components/esp_common/include/esp_freertos_hooks.h b/components/esp_system/include/esp_freertos_hooks.h similarity index 99% rename from components/esp_common/include/esp_freertos_hooks.h rename to components/esp_system/include/esp_freertos_hooks.h index 47db07ce9d..290d580b1d 100644 --- a/components/esp_common/include/esp_freertos_hooks.h +++ b/components/esp_system/include/esp_freertos_hooks.h @@ -16,6 +16,9 @@ #define __ESP_FREERTOS_HOOKS_H__ #include + +#include "freertos/portmacro.h" + #include "esp_err.h" #ifdef __cplusplus From 91287f424b114934a1fe3af59a4bbf25abb9e3b8 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Tue, 26 Jan 2021 11:45:53 +0800 Subject: [PATCH 09/17] esp_common: move shared stack --- .../include/esp_expression_with_stack.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename components/{esp_common => esp_system}/include/esp_expression_with_stack.h (100%) diff --git a/components/esp_common/include/esp_expression_with_stack.h b/components/esp_system/include/esp_expression_with_stack.h similarity index 100% rename from components/esp_common/include/esp_expression_with_stack.h rename to components/esp_system/include/esp_expression_with_stack.h From c16ceafa5ce17aacb8febbbbe89d94d773916543 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Tue, 26 Jan 2021 12:04:33 +0800 Subject: [PATCH 10/17] esp_common: move esp_err --- components/esp_common/CMakeLists.txt | 6 ++---- components/esp_common/linker.lf | 4 ---- components/esp_system/CMakeLists.txt | 3 ++- components/{esp_common/src => esp_system}/esp_err.c | 1 + components/esp_system/linker.lf | 1 + 5 files changed, 6 insertions(+), 9 deletions(-) delete mode 100644 components/esp_common/linker.lf rename components/{esp_common/src => esp_system}/esp_err.c (98%) diff --git a/components/esp_common/CMakeLists.txt b/components/esp_common/CMakeLists.txt index 1edabc4ea6..0baf70ec1f 100644 --- a/components/esp_common/CMakeLists.txt +++ b/components/esp_common/CMakeLists.txt @@ -9,15 +9,13 @@ if(BOOTLOADER_BUILD) set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-Wl,--gc-sections") else() # Regular app build - list(APPEND srcs "src/esp_err.c" - "src/esp_err_to_name.c") + list(APPEND srcs "src/esp_err_to_name.c") # Note: esp_ipc, esp_pm added as a public requirement to keep compatibility as to be located here. idf_component_register(SRCS "${srcs}" INCLUDE_DIRS include REQUIRES ${target} espcoredump esp_timer esp_ipc esp_pm esp_hw_support - PRIV_REQUIRES soc - LDFRAGMENTS "linker.lf") + PRIV_REQUIRES soc) set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY LINK_LIBRARIES "-Wl,--gc-sections") set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-Wl,--gc-sections") diff --git a/components/esp_common/linker.lf b/components/esp_common/linker.lf deleted file mode 100644 index b6913ecff1..0000000000 --- a/components/esp_common/linker.lf +++ /dev/null @@ -1,4 +0,0 @@ -[mapping:esp_common] -archive: libesp_common.a -entries: - esp_err (noflash) diff --git a/components/esp_system/CMakeLists.txt b/components/esp_system/CMakeLists.txt index 2b5ea50442..4dc3224bdb 100644 --- a/components/esp_system/CMakeLists.txt +++ b/components/esp_system/CMakeLists.txt @@ -16,7 +16,8 @@ set(srcs "intr_alloc.c" "task_wdt.c" "int_wdt.c" "stack_check.c" - "freertos_hooks.c") + "freertos_hooks.c" + "esp_err.c") if(NOT (${target} STREQUAL "esp32c3") ) list(APPEND srcs "dbg_stubs.c") diff --git a/components/esp_common/src/esp_err.c b/components/esp_system/esp_err.c similarity index 98% rename from components/esp_common/src/esp_err.c rename to components/esp_system/esp_err.c index 4aa6a230d0..9df59f9290 100644 --- a/components/esp_common/src/esp_err.c +++ b/components/esp_system/esp_err.c @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. #include +#include #include #include "esp_err.h" diff --git a/components/esp_system/linker.lf b/components/esp_system/linker.lf index 00544ff0df..b8c568f0e3 100644 --- a/components/esp_system/linker.lf +++ b/components/esp_system/linker.lf @@ -5,6 +5,7 @@ entries: panic_handler (noflash) panic_arch (noflash) reset_reason (noflash) + esp_err (noflash) system_api:esp_system_abort (noflash) if ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF: From 5e8799bbfec085683bd3bccdfcd35e9564189586 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Tue, 26 Jan 2021 12:54:26 +0800 Subject: [PATCH 11/17] esp_common: move some headers --- components/bootloader/subproject/CMakeLists.txt | 1 + components/driver/CMakeLists.txt | 4 ++-- components/esp32/CMakeLists.txt | 2 +- .../include/esp_private/crosscore_int.h | 7 +++++++ .../include/esp_private/system_internal.h | 0 components/{esp_common => esp_system}/include/esp_task.h | 0 6 files changed, 11 insertions(+), 3 deletions(-) rename components/{esp_common => esp_hw_support}/include/esp_private/crosscore_int.h (96%) rename components/{esp_common => esp_system}/include/esp_private/system_internal.h (100%) rename components/{esp_common => esp_system}/include/esp_task.h (100%) diff --git a/components/bootloader/subproject/CMakeLists.txt b/components/bootloader/subproject/CMakeLists.txt index 2c507035c7..222aad9f2d 100644 --- a/components/bootloader/subproject/CMakeLists.txt +++ b/components/bootloader/subproject/CMakeLists.txt @@ -19,6 +19,7 @@ set(COMPONENTS bootloader esptool_py esp_hw_support + esp_system hal partition_table soc diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index 8e68bb570e..df392d00b2 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -75,8 +75,8 @@ endif() idf_component_register(SRCS "${srcs}" INCLUDE_DIRS ${includes} PRIV_INCLUDE_DIRS "include/driver" - PRIV_REQUIRES efuse esp_pm esp_timer esp_ipc - REQUIRES esp_ringbuf freertos soc hal esp_hw_support) + PRIV_REQUIRES efuse esp_timer esp_ipc + REQUIRES esp_pm esp_ringbuf freertos soc hal esp_hw_support) # (REQUIRES cannot hide soc headers, since many arguments in the driver headers are chip-dependent) # uses C11 atomic feature diff --git a/components/esp32/CMakeLists.txt b/components/esp32/CMakeLists.txt index b805a5c539..de64b5f8fa 100644 --- a/components/esp32/CMakeLists.txt +++ b/components/esp32/CMakeLists.txt @@ -30,7 +30,7 @@ else() # app_update is added here because cpu_start.c uses esp_ota_get_app_description() function. # esp_timer is added here because cpu_start.c uses esp_timer set(priv_requires app_trace app_update bootloader_support esp_system log mbedtls nvs_flash pthread - spi_flash vfs espcoredump esp_common perfmon esp_timer esp_ipc) + spi_flash vfs espcoredump esp_common perfmon esp_timer esp_ipc esp_pm) set(fragments linker.lf ld/esp32_fragments.lf) idf_component_register(SRCS "${srcs}" diff --git a/components/esp_common/include/esp_private/crosscore_int.h b/components/esp_hw_support/include/esp_private/crosscore_int.h similarity index 96% rename from components/esp_common/include/esp_private/crosscore_int.h rename to components/esp_hw_support/include/esp_private/crosscore_int.h index e6f7801767..bac4afba29 100644 --- a/components/esp_common/include/esp_private/crosscore_int.h +++ b/components/esp_hw_support/include/esp_private/crosscore_int.h @@ -14,6 +14,9 @@ #ifndef __ESP_CROSSCORE_INT_H #define __ESP_CROSSCORE_INT_H +#ifdef __cplusplus +extern "C" { +#endif /** * Initialize the crosscore interrupt system for this CPU. @@ -61,4 +64,8 @@ void esp_crosscore_int_send_freq_switch(int core_id); */ void esp_crosscore_int_send_print_backtrace(int core_id); +#ifdef __cplusplus +} +#endif + #endif diff --git a/components/esp_common/include/esp_private/system_internal.h b/components/esp_system/include/esp_private/system_internal.h similarity index 100% rename from components/esp_common/include/esp_private/system_internal.h rename to components/esp_system/include/esp_private/system_internal.h diff --git a/components/esp_common/include/esp_task.h b/components/esp_system/include/esp_task.h similarity index 100% rename from components/esp_common/include/esp_task.h rename to components/esp_system/include/esp_task.h From 03dce3668c52d6cc2f36157df52c3c456b749b69 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Tue, 26 Jan 2021 12:57:41 +0800 Subject: [PATCH 12/17] esp_common: move tests --- components/{esp_common => esp_system}/test/test_delay.c | 0 components/{esp_common => newlib}/test/test_atomic.c | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename components/{esp_common => esp_system}/test/test_delay.c (100%) rename components/{esp_common => newlib}/test/test_atomic.c (100%) diff --git a/components/esp_common/test/test_delay.c b/components/esp_system/test/test_delay.c similarity index 100% rename from components/esp_common/test/test_delay.c rename to components/esp_system/test/test_delay.c diff --git a/components/esp_common/test/test_atomic.c b/components/newlib/test/test_atomic.c similarity index 100% rename from components/esp_common/test/test_atomic.c rename to components/newlib/test/test_atomic.c From 51e66d0f8247fd8314458f8e209a93cb12823cf4 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Tue, 26 Jan 2021 13:03:14 +0800 Subject: [PATCH 13/17] esp_common: move configs --- components/esp_common/Kconfig | 198 ------------------------ components/esp_common/sdkconfig.rename | 20 --- components/esp_system/Kconfig | 200 +++++++++++++++++++++++++ components/esp_system/panic.c | 4 +- components/esp_system/sdkconfig.rename | 18 +++ components/esp_system/startup.c | 4 + 6 files changed, 223 insertions(+), 221 deletions(-) delete mode 100644 components/esp_common/sdkconfig.rename diff --git a/components/esp_common/Kconfig b/components/esp_common/Kconfig index 0e4fdd4a46..43a74a4544 100644 --- a/components/esp_common/Kconfig +++ b/components/esp_common/Kconfig @@ -9,204 +9,6 @@ menu "Common ESP-related" 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 2304 - 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_IPC_TASK_STACK_SIZE - int "Inter-Processor Call (IPC) task stack size" - range 512 65536 if !APPTRACE_ENABLE - range 2048 65536 if APPTRACE_ENABLE - default 2048 if APPTRACE_ENABLE - default 1024 - help - Configure the IPC tasks stack size. One IPC task runs on each core - (in dual core mode), and allows for cross-core function calls. - - See IPC documentation for more details. - - The default stack size should be enough for most common use cases. - It can be shrunk if you are sure that you do not use any custom - IPC functionality. - - config ESP_IPC_USES_CALLERS_PRIORITY - bool "IPC runs at caller's priority" - default y - depends on !FREERTOS_UNICORE - help - If this option is not enabled then the IPC task will keep behavior - same as prior to that of ESP-IDF v4.0, and hence IPC task will run - at (configMAX_PRIORITIES - 1) priority. - - config ESP_MINIMAL_SHARED_STACK_SIZE - int "Minimal allowed size for shared stack" - default 2048 - help - Minimal value of size, in bytes, accepted to execute a expression - with shared stack. - - choice ESP_CONSOLE_UART - prompt "Channel for console output" - default ESP_CONSOLE_UART_DEFAULT - help - Select where to send console output (through stdout and stderr). - - - Default is to use UART0 on pre-defined GPIOs. - - 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 ROM output can be suppressed by - GPIO strapping or EFUSE, refer to chip datasheet for details. - - On chips with USB peripheral, "USB CDC" option redirects output to the - CDC port. This option uses the CDC driver in the chip ROM. - This option is incompatible with TinyUSB stack. - config ESP_CONSOLE_UART_DEFAULT - bool "Default: UART0" - config ESP_CONSOLE_USB_CDC - bool "USB CDC" - # The naming is confusing: USB_ENABLED means that TinyUSB driver is enabled, not USB in general. - # && !USB_ENABLED is because the ROM CDC driver is currently incompatible with TinyUSB. - depends on IDF_TARGET_ESP32S2 && !USB_ENABLED - config ESP_CONSOLE_UART_CUSTOM - bool "Custom UART" - config ESP_CONSOLE_NONE - bool "None" - endchoice - - # Internal option, indicates that console UART is used (and not USB, for example) - config ESP_CONSOLE_UART - bool - default y if ESP_CONSOLE_UART_DEFAULT || ESP_CONSOLE_UART_CUSTOM - - config ESP_CONSOLE_MULTIPLE_UART - bool - default y if !IDF_TARGET_ESP32C3 - - choice ESP_CONSOLE_UART_NUM - prompt "UART peripheral to use for console output (0-1)" - depends on ESP_CONSOLE_UART_CUSTOM && ESP_CONSOLE_MULTIPLE_UART - default ESP_CONSOLE_UART_CUSTOM_NUM_0 - help - This UART peripheral is used for console output from the ESP-IDF Bootloader and the app. - - If the configuration is different in the Bootloader binary compared to the app binary, UART - is reconfigured after the bootloader exits and the app starts. - - Due to an ESP32 ROM bug, UART2 is not supported for console output - via esp_rom_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 - default 0 if !ESP_CONSOLE_MULTIPLE_UART - default 0 if ESP_CONSOLE_UART_CUSTOM_NUM_0 - default 1 if ESP_CONSOLE_UART_CUSTOM_NUM_1 - default -1 if !ESP_CONSOLE_UART - - config ESP_CONSOLE_UART_TX_GPIO - int "UART TX on GPIO#" - depends on ESP_CONSOLE_UART_CUSTOM - range 0 46 - default 1 if IDF_TARGET_ESP32 - default 21 if IDF_TARGET_ESP32C3 - default 43 - help - This GPIO is used for console UART TX output in the ESP-IDF Bootloader and the app (including - boot log output and default standard output and standard error of the app). - - If the configuration is different in the Bootloader binary compared to the app binary, UART - is reconfigured after the bootloader exits and the app starts. - - config ESP_CONSOLE_UART_RX_GPIO - int "UART RX on GPIO#" - depends on ESP_CONSOLE_UART_CUSTOM - range 0 46 - default 3 if IDF_TARGET_ESP32 - default 20 if IDF_TARGET_ESP32C3 - default 44 - help - This GPIO is used for UART RX input in the ESP-IDF Bootloader and the app (including - default default standard input of the app). - - Note: The default ESP-IDF Bootloader configures this pin but doesn't read anything from the UART. - - If the configuration is different in the Bootloader binary compared to the app binary, UART - is reconfigured after the bootloader exits and the app starts. - - - config ESP_CONSOLE_UART_BAUDRATE - int - prompt "UART console baud rate" if ESP_CONSOLE_UART_CUSTOM - depends on ESP_CONSOLE_UART - default 115200 - range 1200 4000000 if !PM_ENABLE - range 1200 1000000 if PM_ENABLE - help - This baud rate is used by both the ESP-IDF Bootloader and the app (including - boot log output and default standard input/output/error of the app). - - The app's maximum baud rate depends on the UART clock source. If Power Management is disabled, - the UART clock source is the APB clock and all baud rates in the available range will be sufficiently - accurate. If Power Management is enabled, REF_TICK clock source is used so the baud rate is divided - from 1MHz. Baud rates above 1Mbps are not possible and values between 500Kbps and 1Mbps may not be - accurate. - - If the configuration is different in the Bootloader binary compared to the app binary, UART - is reconfigured after the bootloader exits and the app starts. - - config ESP_CONSOLE_USB_CDC_RX_BUF_SIZE - int "Size of USB CDC RX buffer" - depends on ESP_CONSOLE_USB_CDC - default 64 - range 4 16384 - help - Set the size of USB CDC RX buffer. Increase the buffer size if your application - is often receiving data over USB CDC. - - config ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF - bool "Enable esp_rom_printf / ESP_EARLY_LOG via USB CDC" - depends on ESP_CONSOLE_USB_CDC - default n - help - If enabled, esp_rom_printf and ESP_EARLY_LOG output will also be sent over USB CDC. - Disabling this option saves about 1kB or RAM. - - config ESP_PANIC_HANDLER_IRAM - bool "Place panic handler code in IRAM" - default n - help - If this option is disabled (default), the panic handler code is placed in flash not IRAM. - This means that if ESP-IDF crashes while flash cache is disabled, the panic handler will - automatically re-enable flash cache before running GDB Stub or Core Dump. This adds some minor - risk, if the flash cache status is also corrupted during the crash. - - If this option is enabled, the panic handler code is placed in IRAM. This allows the panic - handler to run without needing to re-enable cache first. This may be necessary to debug some - complex issues with crashes while flash cache is disabled (for example, when writing to - SPI flash.) - config ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY # Invisible option that is set by SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY, but # exists even if SPIRAM is not supported diff --git a/components/esp_common/sdkconfig.rename b/components/esp_common/sdkconfig.rename deleted file mode 100644 index 419f6206a5..0000000000 --- a/components/esp_common/sdkconfig.rename +++ /dev/null @@ -1,20 +0,0 @@ -# sdkconfig replacement configurations for deprecated options formatted as -# CONFIG_DEPRECATED_OPTION CONFIG_NEW_OPTION - -CONFIG_SYSTEM_EVENT_QUEUE_SIZE CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE -CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE -CONFIG_MAIN_TASK_STACK_SIZE CONFIG_ESP_MAIN_TASK_STACK_SIZE -CONFIG_IPC_TASK_STACK_SIZE CONFIG_ESP_IPC_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_NONE -CONFIG_ESP_CONSOLE_UART_NONE CONFIG_ESP_CONSOLE_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_TX_GPIO CONFIG_ESP_CONSOLE_UART_TX_GPIO -CONFIG_CONSOLE_UART_RX_GPIO CONFIG_ESP_CONSOLE_UART_RX_GPIO -CONFIG_CONSOLE_UART_BAUDRATE CONFIG_ESP_CONSOLE_UART_BAUDRATE -CONFIG_ESP32_ALLOW_RTC_FAST_MEM_AS_HEAP CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP -CONFIG_ESP32S2_ALLOW_RTC_FAST_MEM_AS_HEAP CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP diff --git a/components/esp_system/Kconfig b/components/esp_system/Kconfig index c223e85e9e..486c8cde45 100644 --- a/components/esp_system/Kconfig +++ b/components/esp_system/Kconfig @@ -1,3 +1,4 @@ + menu "ESP System Settings" choice ESP_SYSTEM_PANIC @@ -122,6 +123,165 @@ menu "ESP System Settings" endmenu # Memory protection + 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 2304 + 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_MINIMAL_SHARED_STACK_SIZE + int "Minimal allowed size for shared stack" + default 2048 + help + Minimal value of size, in bytes, accepted to execute a expression + with shared stack. + + choice ESP_CONSOLE_UART + prompt "Channel for console output" + default ESP_CONSOLE_UART_DEFAULT + help + Select where to send console output (through stdout and stderr). + + - Default is to use UART0 on pre-defined GPIOs. + - 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 ROM output can be suppressed by + GPIO strapping or EFUSE, refer to chip datasheet for details. + - On chips with USB peripheral, "USB CDC" option redirects output to the + CDC port. This option uses the CDC driver in the chip ROM. + This option is incompatible with TinyUSB stack. + config ESP_CONSOLE_UART_DEFAULT + bool "Default: UART0" + config ESP_CONSOLE_USB_CDC + bool "USB CDC" + # The naming is confusing: USB_ENABLED means that TinyUSB driver is enabled, not USB in general. + # && !USB_ENABLED is because the ROM CDC driver is currently incompatible with TinyUSB. + depends on IDF_TARGET_ESP32S2 && !USB_ENABLED + config ESP_CONSOLE_UART_CUSTOM + bool "Custom UART" + config ESP_CONSOLE_NONE + bool "None" + endchoice + + # Internal option, indicates that console UART is used (and not USB, for example) + config ESP_CONSOLE_UART + bool + default y if ESP_CONSOLE_UART_DEFAULT || ESP_CONSOLE_UART_CUSTOM + + config ESP_CONSOLE_MULTIPLE_UART + bool + default y if !IDF_TARGET_ESP32C3 + + choice ESP_CONSOLE_UART_NUM + prompt "UART peripheral to use for console output (0-1)" + depends on ESP_CONSOLE_UART_CUSTOM && ESP_CONSOLE_MULTIPLE_UART + default ESP_CONSOLE_UART_CUSTOM_NUM_0 + help + This UART peripheral is used for console output from the ESP-IDF Bootloader and the app. + + If the configuration is different in the Bootloader binary compared to the app binary, UART + is reconfigured after the bootloader exits and the app starts. + + Due to an ESP32 ROM bug, UART2 is not supported for console output + via esp_rom_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 + default 0 if !ESP_CONSOLE_MULTIPLE_UART + default 0 if ESP_CONSOLE_UART_CUSTOM_NUM_0 + default 1 if ESP_CONSOLE_UART_CUSTOM_NUM_1 + default -1 if !ESP_CONSOLE_UART + + config ESP_CONSOLE_UART_TX_GPIO + int "UART TX on GPIO#" + depends on ESP_CONSOLE_UART_CUSTOM + range 0 46 + default 1 if IDF_TARGET_ESP32 + default 21 if IDF_TARGET_ESP32C3 + default 43 + help + This GPIO is used for console UART TX output in the ESP-IDF Bootloader and the app (including + boot log output and default standard output and standard error of the app). + + If the configuration is different in the Bootloader binary compared to the app binary, UART + is reconfigured after the bootloader exits and the app starts. + + config ESP_CONSOLE_UART_RX_GPIO + int "UART RX on GPIO#" + depends on ESP_CONSOLE_UART_CUSTOM + range 0 46 + default 3 if IDF_TARGET_ESP32 + default 20 if IDF_TARGET_ESP32C3 + default 44 + help + This GPIO is used for UART RX input in the ESP-IDF Bootloader and the app (including + default default standard input of the app). + + Note: The default ESP-IDF Bootloader configures this pin but doesn't read anything from the UART. + + If the configuration is different in the Bootloader binary compared to the app binary, UART + is reconfigured after the bootloader exits and the app starts. + + + config ESP_CONSOLE_UART_BAUDRATE + int + prompt "UART console baud rate" if ESP_CONSOLE_UART_CUSTOM + depends on ESP_CONSOLE_UART + default 115200 + range 1200 4000000 if !PM_ENABLE + range 1200 1000000 if PM_ENABLE + help + This baud rate is used by both the ESP-IDF Bootloader and the app (including + boot log output and default standard input/output/error of the app). + + The app's maximum baud rate depends on the UART clock source. If Power Management is disabled, + the UART clock source is the APB clock and all baud rates in the available range will be sufficiently + accurate. If Power Management is enabled, REF_TICK clock source is used so the baud rate is divided + from 1MHz. Baud rates above 1Mbps are not possible and values between 500Kbps and 1Mbps may not be + accurate. + + If the configuration is different in the Bootloader binary compared to the app binary, UART + is reconfigured after the bootloader exits and the app starts. + + config ESP_CONSOLE_USB_CDC_RX_BUF_SIZE + int "Size of USB CDC RX buffer" + depends on ESP_CONSOLE_USB_CDC + default 64 + range 4 16384 + help + Set the size of USB CDC RX buffer. Increase the buffer size if your application + is often receiving data over USB CDC. + + config ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF + bool "Enable esp_rom_printf / ESP_EARLY_LOG via USB CDC" + depends on ESP_CONSOLE_USB_CDC + default n + help + If enabled, esp_rom_printf and ESP_EARLY_LOG output will also be sent over USB CDC. + Disabling this option saves about 1kB or RAM. + config ESP_INT_WDT bool "Interrupt watchdog" default y @@ -192,6 +352,46 @@ menu "ESP System Settings" help If this option is enabled, the Task Wtachdog Timer will wach the CPU1 Idle Task. + + config ESP_IPC_TASK_STACK_SIZE + int "Inter-Processor Call (IPC) task stack size" + range 512 65536 if !APPTRACE_ENABLE + range 2048 65536 if APPTRACE_ENABLE + default 2048 if APPTRACE_ENABLE + default 1024 + help + Configure the IPC tasks stack size. One IPC task runs on each core + (in dual core mode), and allows for cross-core function calls. + + See IPC documentation for more details. + + The default stack size should be enough for most common use cases. + It can be shrunk if you are sure that you do not use any custom + IPC functionality. + + config ESP_IPC_USES_CALLERS_PRIORITY + bool "IPC runs at caller's priority" + default y + depends on !FREERTOS_UNICORE + help + If this option is not enabled then the IPC task will keep behavior + same as prior to that of ESP-IDF v4.0, and hence IPC task will run + at (configMAX_PRIORITIES - 1) priority. + + config ESP_PANIC_HANDLER_IRAM + bool "Place panic handler code in IRAM" + default n + help + If this option is disabled (default), the panic handler code is placed in flash not IRAM. + This means that if ESP-IDF crashes while flash cache is disabled, the panic handler will + automatically re-enable flash cache before running GDB Stub or Core Dump. This adds some minor + risk, if the flash cache status is also corrupted during the crash. + + If this option is enabled, the panic handler code is placed in IRAM. This allows the panic + handler to run without needing to re-enable cache first. This may be necessary to debug some + complex issues with crashes while flash cache is disabled (for example, when writing to + SPI flash.) + config ESP_DEBUG_STUBS_ENABLE bool default COMPILER_OPTIMIZATION_LEVEL_DEBUG diff --git a/components/esp_system/panic.c b/components/esp_system/panic.c index 196e46ec6d..d35057ccb1 100644 --- a/components/esp_system/panic.c +++ b/components/esp_system/panic.c @@ -21,8 +21,6 @@ #include "esp_private/usb_console.h" #include "esp_ota_ops.h" -#include "esp_core_dump.h" - #include "soc/cpu.h" #include "soc/rtc.h" #include "hal/timer_hal.h" @@ -35,7 +33,7 @@ #include "sdkconfig.h" -#if CONFIG_ESP32_ENABLE_COREDUMP +#if CONFIG_ESP_COREDUMP_ENABLE #include "esp_core_dump.h" #endif diff --git a/components/esp_system/sdkconfig.rename b/components/esp_system/sdkconfig.rename index 5ff5eecc74..5d113edd17 100644 --- a/components/esp_system/sdkconfig.rename +++ b/components/esp_system/sdkconfig.rename @@ -16,6 +16,22 @@ CONFIG_ESP32C3_MEMPROT_FEATURE CONFIG_ESP_SYSTEM_MEMPRO CONFIG_ESP32C3_MEMPROT_FEATURE_LOCK CONFIG_ESP_SYSTEM_MEMPROT_FEATURE_LOCK CONFIG_ESP32_RTC_XTAL_BOOTSTRAP_CYCLES CONFIG_ESP_SYSTEM_RTC_EXT_XTAL_BOOTSTRAP_CYCLES + +CONFIG_SYSTEM_EVENT_QUEUE_SIZE CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE +CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE +CONFIG_MAIN_TASK_STACK_SIZE CONFIG_ESP_MAIN_TASK_STACK_SIZE +CONFIG_IPC_TASK_STACK_SIZE CONFIG_ESP_IPC_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_NONE +CONFIG_ESP_CONSOLE_UART_NONE CONFIG_ESP_CONSOLE_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_TX_GPIO CONFIG_ESP_CONSOLE_UART_TX_GPIO +CONFIG_CONSOLE_UART_RX_GPIO CONFIG_ESP_CONSOLE_UART_RX_GPIO +CONFIG_CONSOLE_UART_BAUDRATE CONFIG_ESP_CONSOLE_UART_BAUDRATE CONFIG_INT_WDT CONFIG_ESP_INT_WDT CONFIG_INT_WDT_TIMEOUT_MS CONFIG_ESP_INT_WDT_TIMEOUT_MS CONFIG_INT_WDT_CHECK_CPU1 CONFIG_ESP_INT_WDT_CHECK_CPU1 @@ -25,3 +41,5 @@ CONFIG_TASK_WDT_TIMEOUT_S CONFIG_ESP_TASK_WDT_TIME CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 CONFIG_ESP32_DEBUG_STUBS_ENABLE CONFIG_ESP_DEBUG_STUBS_ENABLE +CONFIG_ESP32_ALLOW_RTC_FAST_MEM_AS_HEAP CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP +CONFIG_ESP32S2_ALLOW_RTC_FAST_MEM_AS_HEAP CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP diff --git a/components/esp_system/startup.c b/components/esp_system/startup.c index 3ad549d267..4527ffa48a 100644 --- a/components/esp_system/startup.c +++ b/components/esp_system/startup.c @@ -45,7 +45,11 @@ #include "nvs_flash.h" #include "esp_phy_init.h" #include "esp_coexist_internal.h" + +#if CONFIG_ESP_COREDUMP_ENABLE #include "esp_core_dump.h" +#endif + #include "esp_app_trace.h" #include "esp_private/dbg_stubs.h" #include "esp_flash_encrypt.h" From 349f0cad3e629db1a0c4c012142d36ee4231ee26 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Tue, 26 Jan 2021 13:12:54 +0800 Subject: [PATCH 14/17] esp_common: other movements --- components/esp_common/component.mk | 3 - components/esp_hw_support/CMakeLists.txt | 2 - components/esp_hw_support/Kconfig | 5 -- components/esp_hw_support/component.mk | 1 - components/esp_ipc/test/CMakeLists.txt | 2 +- components/esp_system/CMakeLists.txt | 37 ++++++---- components/esp_system/component.mk | 6 +- components/esp_system/fpga_overrides.c | 73 +++++++++++++++++++ .../include/esp_private/crosscore_int.h | 0 9 files changed, 103 insertions(+), 26 deletions(-) create mode 100644 components/esp_system/fpga_overrides.c rename components/{esp_hw_support => esp_system}/include/esp_private/crosscore_int.h (100%) diff --git a/components/esp_common/component.mk b/components/esp_common/component.mk index 01fc42388a..ea720ca509 100644 --- a/components/esp_common/component.mk +++ b/components/esp_common/component.mk @@ -4,6 +4,3 @@ COMPONENT_ADD_INCLUDEDIRS := include COMPONENT_SRCDIRS := src -ifndef CONFIG_IDF_ENV_FPGA -COMPONENT_OBJEXCLUDE += src/fpga_overrides.o -endif \ No newline at end of file diff --git a/components/esp_hw_support/CMakeLists.txt b/components/esp_hw_support/CMakeLists.txt index 879b1999ca..d18183d1ec 100644 --- a/components/esp_hw_support/CMakeLists.txt +++ b/components/esp_hw_support/CMakeLists.txt @@ -10,8 +10,6 @@ if(NOT BOOTLOADER_BUILD) list(APPEND srcs "clk_ctrl_os.c" "mac_addr.c") endif() -endif() - idf_component_register(SRCS ${srcs} INCLUDE_DIRS include REQUIRES ${requires} diff --git a/components/esp_hw_support/Kconfig b/components/esp_hw_support/Kconfig index 1098919b7e..e37fb77ec2 100644 --- a/components/esp_hw_support/Kconfig +++ b/components/esp_hw_support/Kconfig @@ -1,10 +1,5 @@ menu "Hardware Settings" menu "MAC Config" - config ESP_UNIVERSAL_MAC_ADDRESSES - int - default 2 if ESP32_UNIVERSAL_MAC_ADDRESSES_TWO - default 4 if ESP32_UNIVERSAL_MAC_ADDRESSES_FOUR - config ESP_MAC_ADDR_UNIVERSE_WIFI_STA bool diff --git a/components/esp_hw_support/component.mk b/components/esp_hw_support/component.mk index f3c83d7505..07566e52b8 100644 --- a/components/esp_hw_support/component.mk +++ b/components/esp_hw_support/component.mk @@ -6,5 +6,4 @@ port/$(IDF_TARGET)/rtc_clk.o: CFLAGS += -fno-jump-tables -fno-tree-switch-conver ifdef IS_BOOTLOADER_BUILD COMPONENT_OBJEXCLUDE += clk_ctrl_os.o mac_addr.o - endif diff --git a/components/esp_ipc/test/CMakeLists.txt b/components/esp_ipc/test/CMakeLists.txt index 37594e61be..24591e199b 100644 --- a/components/esp_ipc/test/CMakeLists.txt +++ b/components/esp_ipc/test/CMakeLists.txt @@ -1,5 +1,5 @@ if(IDF_TARGET STREQUAL "esp32") idf_component_register(SRC_DIRS "." PRIV_INCLUDE_DIRS "." - PRIV_REQUIRES cmock test_utils) + PRIV_REQUIRES cmock test_utils esp_ipc) endif() diff --git a/components/esp_system/CMakeLists.txt b/components/esp_system/CMakeLists.txt index 4dc3224bdb..960abe8a18 100644 --- a/components/esp_system/CMakeLists.txt +++ b/components/esp_system/CMakeLists.txt @@ -6,30 +6,36 @@ endif() idf_build_get_property(target IDF_TARGET) -set(srcs "intr_alloc.c" - "esp_async_memcpy.c" - "panic.c" - "system_api.c" - "startup.c" - "system_time.c" - "sleep_modes.c" - "task_wdt.c" - "int_wdt.c" - "stack_check.c" - "freertos_hooks.c" - "esp_err.c") +# Remove when sleep is brought up on master for C3 TODO ESP32-C3 IDF-2571 +set(srcs "esp_err.c" + "freertos_hooks.c" + "intr_alloc.c" + "int_wdt.c" + "esp_async_memcpy.c" + "panic.c" + "system_api.c" + "startup.c" + "system_time.c" + "stack_check.c" + "sleep_modes.c" + "task_wdt.c") if(NOT (${target} STREQUAL "esp32c3") ) list(APPEND srcs "dbg_stubs.c") endif() +if(CONFIG_IDF_ENV_FPGA) + list(APPEND srcs "fpga_overrides.c") +endif() + idf_component_register(SRCS "${srcs}" INCLUDE_DIRS include PRIV_REQUIRES spi_flash # [refactor-todo] requirements due to init code, # should be removable once using component init functions # link-time registration is used. - esp_pm app_update nvs_flash pthread app_trace esp_gdbstub + esp_pm app_update nvs_flash pthread app_trace esp_gdbstub esp_ipc + espcoredump LDFRAGMENTS "linker.lf") add_subdirectory(port) @@ -54,3 +60,8 @@ if(NOT CMAKE_BUILD_EARLY_EXPANSION) set_source_files_properties("${CMAKE_CURRENT_LIST_DIR}/sleep_modes.c" PROPERTIES COMPILE_FLAGS "-fno-jump-tables -fno-tree-switch-conversion") endif() + +if(CONFIG_IDF_ENV_FPGA) + # Forces the linker to include fpga stubs from this component + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_common_include_fpga_overrides") +endif() diff --git a/components/esp_system/component.mk b/components/esp_system/component.mk index e3ca1f7318..b22cfba328 100644 --- a/components/esp_system/component.mk +++ b/components/esp_system/component.mk @@ -1,11 +1,15 @@ +ifdef IS_BOOTLOADER_BUILD +COMPONENT_CONFIG_ONLY := 1 +else SOC_NAME := $(IDF_TARGET) COMPONENT_SRCDIRS := . COMPONENT_ADD_INCLUDEDIRS := include -COMPONENT_PRIV_INCLUDEDIRS := private_include port/include +COMPONENT_PRIV_INCLUDEDIRS := port/include port COMPONENT_ADD_LDFRAGMENTS += linker.lf include $(COMPONENT_PATH)/port/soc/$(SOC_NAME)/component.mk # disable stack protection in files which are involved in initialization of that feature startup.o stack_check.o: CFLAGS := $(filter-out -fstack-protector%, $(CFLAGS)) +endif diff --git a/components/esp_system/fpga_overrides.c b/components/esp_system/fpga_overrides.c new file mode 100644 index 0000000000..b309bef623 --- /dev/null +++ b/components/esp_system/fpga_overrides.c @@ -0,0 +1,73 @@ +// Copyright 2010-2020 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#include "sdkconfig.h" +#include "soc/soc.h" +#include "soc/rtc.h" +#include "soc/rtc_cntl_reg.h" +#include "esp_log.h" +#include "esp_rom_sys.h" +#include "esp_rom_uart.h" +#include "esp_attr.h" + +static const char *TAG = "fpga"; + +extern void ets_update_cpu_frequency(uint32_t ticks_per_us); + +static void s_warn(void) +{ + ESP_EARLY_LOGW(TAG, "Project configuration is for internal FPGA use, not all functions will work"); +} + +void bootloader_clock_configure(void) +{ + s_warn(); + esp_rom_uart_tx_wait_idle(0); + + uint32_t xtal_freq_mhz = 40; +#ifdef CONFIG_IDF_TARGET_ESP32S2 + uint32_t apb_freq_hz = 20000000; +#else + uint32_t apb_freq_hz = 40000000; +#endif // CONFIG_IDF_TARGET_ESP32S2 + ets_update_cpu_frequency(apb_freq_hz / 1000000); + REG_WRITE(RTC_CNTL_STORE5_REG, (apb_freq_hz >> 12) | ((apb_freq_hz >> 12) << 16)); + REG_WRITE(RTC_CNTL_STORE4_REG, (xtal_freq_mhz) | ((xtal_freq_mhz) << 16)); +} + +/* Placed in IRAM since test_apps expects it to be */ +void IRAM_ATTR bootloader_fill_random(void *buffer, size_t length) +{ + uint8_t *buffer_bytes = (uint8_t *)buffer; + for (int i = 0; i < length; i++) { + buffer_bytes[i] = 0x5A; + } +} + +void esp_clk_init(void) +{ + s_warn(); +} + +void esp_perip_clk_init(void) +{ + +} + +/** + * @brief No-op function, used to force linking this file + * + */ +void esp_common_include_fpga_overrides(void) +{ +} diff --git a/components/esp_hw_support/include/esp_private/crosscore_int.h b/components/esp_system/include/esp_private/crosscore_int.h similarity index 100% rename from components/esp_hw_support/include/esp_private/crosscore_int.h rename to components/esp_system/include/esp_private/crosscore_int.h From 813044c6dba1d8ba26c327d1e22c7b0a2936fa4e Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Wed, 20 Jan 2021 15:17:38 +0800 Subject: [PATCH 15/17] docs, ci: update docs and ci with movements from esp_common --- docs/doxygen/Doxyfile_common | 10 +++++----- docs/en/api-reference/system/wdts.rst | 2 +- tools/ci/check_public_headers_exceptions.txt | 1 - 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/doxygen/Doxyfile_common b/docs/doxygen/Doxyfile_common index 71866087e4..d77df83d48 100644 --- a/docs/doxygen/Doxyfile_common +++ b/docs/doxygen/Doxyfile_common @@ -226,15 +226,15 @@ INPUT = \ $(IDF_PATH)/components/esp_system/include/esp_intr_alloc.h \ ## Watchdogs ## NOTE: for two lines below header_file.inc is not used - $(IDF_PATH)/components/esp_common/include/esp_int_wdt.h \ - $(IDF_PATH)/components/esp_common/include/esp_task_wdt.h \ - $(IDF_PATH)/components/esp_common/include/esp_crc.h \ + $(IDF_PATH)/components/esp_system/include/esp_int_wdt.h \ + $(IDF_PATH)/components/esp_system/include/esp_task_wdt.h \ + $(IDF_PATH)/components/esp_hw_support/include/esp_crc.h \ ## Hooks - $(IDF_PATH)/components/esp_common/include/esp_freertos_hooks.h \ + $(IDF_PATH)/components/esp_system/include/esp_freertos_hooks.h \ ## Inter-Processor Call $(IDF_PATH)/components/esp_ipc/include/esp_ipc.h \ ## Call Function with External stack - $(IDF_PATH)/components/esp_common/include/esp_expression_with_stack.h \ + $(IDF_PATH)/components/esp_system/include/esp_expression_with_stack.h \ ## Over The Air Updates (OTA) $(IDF_PATH)/components/app_update/include/esp_ota_ops.h \ ## ESP HTTPS OTA diff --git a/docs/en/api-reference/system/wdts.rst b/docs/en/api-reference/system/wdts.rst index 6843ab3a4d..5b7d3fbabb 100644 --- a/docs/en/api-reference/system/wdts.rst +++ b/docs/en/api-reference/system/wdts.rst @@ -128,7 +128,7 @@ Interrupt Watchdog API Reference Header File ^^^^^^^^^^^ - * :component_file:`esp_common/include/esp_int_wdt.h` + * :component_file:`esp_system/include/esp_int_wdt.h` Functions diff --git a/tools/ci/check_public_headers_exceptions.txt b/tools/ci/check_public_headers_exceptions.txt index fe42aecfcd..a76dd29913 100644 --- a/tools/ci/check_public_headers_exceptions.txt +++ b/tools/ci/check_public_headers_exceptions.txt @@ -117,7 +117,6 @@ components/esp_rom/include/esp32s2/rom/cache.h components/esp_rom/include/esp32s2/rom/secure_boot.h components/esp_rom/include/esp32s2/rom/opi_flash.h components/esp_rom/include/esp32s2/rom/efuse.h -components/esp_common/include/esp_freertos_hooks.h components/esp32/include/esp32/dport_access.h components/esp32/include/rom/sha.h components/esp32/include/rom/secure_boot.h From 43f6c7a533c5c47c5758a5ab84348fa5d2bcb616 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Wed, 20 Jan 2021 15:18:55 +0800 Subject: [PATCH 16/17] esp_common: simplify component build script --- components/esp_common/CMakeLists.txt | 81 +++++++++-------------- components/esp_system/CMakeLists.txt | 97 ++++++++++++++-------------- components/esp_system/component.mk | 11 ++++ tools/cmake/build.cmake | 3 + 4 files changed, 93 insertions(+), 99 deletions(-) diff --git a/components/esp_common/CMakeLists.txt b/components/esp_common/CMakeLists.txt index 0baf70ec1f..bcb16a907e 100644 --- a/components/esp_common/CMakeLists.txt +++ b/components/esp_common/CMakeLists.txt @@ -1,56 +1,37 @@ idf_build_get_property(target IDF_TARGET) +list(APPEND srcs "src/esp_err_to_name.c") -if(BOOTLOADER_BUILD) - # For bootloader, all we need from esp_common is headers - idf_component_register(SRCS ${srcs} - INCLUDE_DIRS include - PRIV_REQUIRES soc) - set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-Wl,--gc-sections") -else() - # Regular app build - list(APPEND srcs "src/esp_err_to_name.c") +# Note: esp_ipc, esp_pm added as a public requirement to keep compatibility as to be located here. +idf_component_register(SRCS "${srcs}" + INCLUDE_DIRS include + REQUIRES ${target}) - # Note: esp_ipc, esp_pm added as a public requirement to keep compatibility as to be located here. - idf_component_register(SRCS "${srcs}" - INCLUDE_DIRS include - REQUIRES ${target} espcoredump esp_timer esp_ipc esp_pm esp_hw_support - PRIV_REQUIRES soc) +set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY LINK_INTERFACE_MULTIPLICITY 4) - set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY LINK_LIBRARIES "-Wl,--gc-sections") - set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "-Wl,--gc-sections") - set_property(TARGET ${COMPONENT_LIB} APPEND PROPERTY LINK_INTERFACE_MULTIPLICITY 4) +# List of components needed for the error codes list +set(optional_reqs ulp + efuse + esp_http_client + esp_http_server + bootloader_support + nvs_flash + esp_wifi + app_update + lwip + spi_flash + wpa_supplicant + tcpip_adapter + esp_serial_slave_link + esp_netif + soc + esp-tls + esp_https_ota) - # List of components needed for the error codes list - set(optional_reqs ulp - efuse - esp_http_client - esp_http_server - bootloader_support - nvs_flash - esp_wifi - app_update - lwip - spi_flash - wpa_supplicant - tcpip_adapter - esp_serial_slave_link - esp_netif - soc - esp-tls - esp_https_ota) - - idf_build_get_property(build_components BUILD_COMPONENTS) - foreach(req ${optional_reqs}) - if(req IN_LIST build_components) - idf_component_get_property(req_lib ${req} COMPONENT_LIB) - target_link_libraries(${COMPONENT_LIB} PRIVATE ${req_lib}) - endif() - endforeach() - -endif() - -if(CONFIG_IDF_ENV_FPGA) - # Forces the linker to include fpga stubs from this component - target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_common_include_fpga_overrides") -endif() +idf_build_get_property(build_components BUILD_COMPONENTS) +foreach(req ${optional_reqs}) + if(req IN_LIST build_components) + idf_component_get_property(req_lib ${req} COMPONENT_LIB) + target_link_libraries(${COMPONENT_LIB} PRIVATE ${req_lib}) + endif() +endforeach() diff --git a/components/esp_system/CMakeLists.txt b/components/esp_system/CMakeLists.txt index 960abe8a18..2f7ab5c2db 100644 --- a/components/esp_system/CMakeLists.txt +++ b/components/esp_system/CMakeLists.txt @@ -1,64 +1,63 @@ -if(BOOTLOADER_BUILD) - # Bootloader relies on some Kconfig options defined in esp_system. - idf_component_register() - return() -endif() - idf_build_get_property(target IDF_TARGET) -# Remove when sleep is brought up on master for C3 TODO ESP32-C3 IDF-2571 -set(srcs "esp_err.c" - "freertos_hooks.c" - "intr_alloc.c" - "int_wdt.c" - "esp_async_memcpy.c" - "panic.c" - "system_api.c" - "startup.c" - "system_time.c" - "stack_check.c" - "sleep_modes.c" - "task_wdt.c") - -if(NOT (${target} STREQUAL "esp32c3") ) - list(APPEND srcs "dbg_stubs.c") -endif() +set(srcs) if(CONFIG_IDF_ENV_FPGA) list(APPEND srcs "fpga_overrides.c") endif() -idf_component_register(SRCS "${srcs}" - INCLUDE_DIRS include - PRIV_REQUIRES spi_flash - # [refactor-todo] requirements due to init code, - # should be removable once using component init functions - # link-time registration is used. - esp_pm app_update nvs_flash pthread app_trace esp_gdbstub esp_ipc - espcoredump - LDFRAGMENTS "linker.lf") -add_subdirectory(port) +if(BOOTLOADER_BUILD) + # Bootloader relies on some Kconfig options defined in esp_system. + idf_component_register(SRCS "${srcs}") +else() + list(APPEND srcs "esp_err.c" + "freertos_hooks.c" + "intr_alloc.c" + "int_wdt.c" + "esp_async_memcpy.c" + "panic.c" + "system_api.c" + "startup.c" + "system_time.c" + "stack_check.c" + "sleep_modes.c" + "task_wdt.c") + if(NOT (${target} STREQUAL "esp32c3") ) + list(APPEND srcs "dbg_stubs.c") + endif() -# After system initialization, `start_app` (and its other cores variant) is called. -# This is provided by the user or from another component. Since we can't establish -# dependency on what we don't know, force linker to not drop the symbol regardless -# of link line order. -target_link_libraries(${COMPONENT_LIB} INTERFACE "-u start_app") + idf_component_register(SRCS "${srcs}" + INCLUDE_DIRS include + PRIV_REQUIRES spi_flash + # [refactor-todo] requirements due to init code, + # should be removable once using component init functions + # link-time registration is used. + esp_pm app_update nvs_flash pthread app_trace esp_gdbstub esp_ipc + espcoredump + LDFRAGMENTS "linker.lf") + add_subdirectory(port) -if(NOT CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE) - target_link_libraries(${COMPONENT_LIB} INTERFACE "-u start_app_other_cores") -endif() + # After system initialization, `start_app` (and its other cores variant) is called. + # This is provided by the user or from another component. Since we can't establish + # dependency on what we don't know, force linker to not drop the symbol regardless + # of link line order. + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u start_app") -# Disable stack protection in files which are involved in initialization of that feature -set_source_files_properties( - "startup.c" "stack_check.c" - PROPERTIES COMPILE_FLAGS - -fno-stack-protector) + if(NOT CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE) + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u start_app_other_cores") + endif() -if(NOT CMAKE_BUILD_EARLY_EXPANSION) - set_source_files_properties("${CMAKE_CURRENT_LIST_DIR}/sleep_modes.c" PROPERTIES - COMPILE_FLAGS "-fno-jump-tables -fno-tree-switch-conversion") + # Disable stack protection in files which are involved in initialization of that feature + set_source_files_properties( + "startup.c" "stack_check.c" + PROPERTIES COMPILE_FLAGS + -fno-stack-protector) + + if(NOT CMAKE_BUILD_EARLY_EXPANSION) + set_source_files_properties("${CMAKE_CURRENT_LIST_DIR}/sleep_modes.c" PROPERTIES + COMPILE_FLAGS "-fno-jump-tables -fno-tree-switch-conversion") + endif() endif() if(CONFIG_IDF_ENV_FPGA) diff --git a/components/esp_system/component.mk b/components/esp_system/component.mk index b22cfba328..e6a0693ae7 100644 --- a/components/esp_system/component.mk +++ b/components/esp_system/component.mk @@ -1,5 +1,12 @@ ifdef IS_BOOTLOADER_BUILD + +ifndef CONFIG_IDF_ENV_FPGA COMPONENT_CONFIG_ONLY := 1 +else +COMPONENT_SRCDIRS := . +COMPONENT_OBJS += fpga_overrides.o +endif + else SOC_NAME := $(IDF_TARGET) @@ -8,6 +15,10 @@ COMPONENT_ADD_INCLUDEDIRS := include COMPONENT_PRIV_INCLUDEDIRS := port/include port COMPONENT_ADD_LDFRAGMENTS += linker.lf +ifndef CONFIG_IDF_ENV_FPGA +COMPONENT_OBJEXCLUDE += fpga_overrides.o +endif + include $(COMPONENT_PATH)/port/soc/$(SOC_NAME)/component.mk # disable stack protection in files which are involved in initialization of that feature diff --git a/tools/cmake/build.cmake b/tools/cmake/build.cmake index 54fd6520fb..3ba3186d89 100644 --- a/tools/cmake/build.cmake +++ b/tools/cmake/build.cmake @@ -112,10 +112,13 @@ function(__build_set_default_build_specifications) list(APPEND cxx_compile_options "-std=gnu++11") + list(APPEND link_options "-Wl,--gc-sections") + idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND) idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND) idf_build_set_property(C_COMPILE_OPTIONS "${c_compile_options}" APPEND) idf_build_set_property(CXX_COMPILE_OPTIONS "${cxx_compile_options}" APPEND) + idf_build_set_property(LINK_OPTIONS "${link_options}" APPEND) endfunction() # From f2561f63601c50a411fb7af52fef9315c40c4c37 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Fri, 19 Feb 2021 11:49:58 +0800 Subject: [PATCH 17/17] docs: update list of common component requirements --- docs/en/api-guides/build-system.rst | 2 +- docs/zh_CN/api-guides/build-system.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/api-guides/build-system.rst b/docs/en/api-guides/build-system.rst index d2964f25cb..9643e70a7b 100644 --- a/docs/en/api-guides/build-system.rst +++ b/docs/en/api-guides/build-system.rst @@ -618,7 +618,7 @@ Common component requirements To avoid duplication, every component automatically requires some "common" IDF components even if they are not mentioned explicitly. Headers from these components can always be included. -The list of common components is: freertos, newlib, heap, log, soc, esp_rom, esp_common, xtensa/riscv, cxx. +The list of common components is: cxx, newlib, freertos, esp_hw_support, heap, log, lwip, soc, hal, esp_rom, esp_common, esp_system. Including components in the build ---------------------------------- diff --git a/docs/zh_CN/api-guides/build-system.rst b/docs/zh_CN/api-guides/build-system.rst index 201c68f62f..7934b935c3 100644 --- a/docs/zh_CN/api-guides/build-system.rst +++ b/docs/zh_CN/api-guides/build-system.rst @@ -618,7 +618,7 @@ Spark Plug 组件 为避免重复性工作,各组件都用自动依赖一些“通用” IDF 组件,即使它们没有被明确提及。这些组件的头文件会一直包含在构建系统中。 -通用组件包括:freertos、newlibheap、log、soc、esp_rom、esp_common、xtensa、cxx。 +通用组件包括:cxx, newlib, freertos, esp_hw_support, heap, log, lwip, soc, hal, esp_rom, esp_common, esp_system。 在构建中导入组件 -----------------