From a334cd50ceff4a26c2e6614b8270983c21175f24 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Wed, 18 May 2022 01:16:12 +0200 Subject: [PATCH] app_trace: perform initialization using ESP_SYSTEM_INIT_FN --- components/app_trace/app_trace.c | 6 ++++++ components/app_trace/sys_view/esp/SEGGER_RTT_esp.c | 14 ++++++++++++++ components/esp_system/startup.c | 13 ------------- components/esp_system/system_init_fn.txt | 4 ++++ 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/components/app_trace/app_trace.c b/components/app_trace/app_trace.c index 141a62b670..9f5ec743fb 100644 --- a/components/app_trace/app_trace.c +++ b/components/app_trace/app_trace.c @@ -8,6 +8,7 @@ #include "esp_log.h" #include "esp_app_trace.h" #include "esp_app_trace_port.h" +#include "esp_private/startup_internal.h" #ifdef CONFIG_APPTRACE_DEST_UART0 #define ESP_APPTRACE_DEST_UART_NUM 0 @@ -75,6 +76,11 @@ esp_err_t esp_apptrace_init(void) return ESP_OK; } +ESP_SYSTEM_INIT_FN(esp_apptrace_init, ESP_SYSTEM_INIT_ALL_CORES, 115) +{ + return esp_apptrace_init(); +} + void esp_apptrace_down_buffer_config(uint8_t *buf, uint32_t size) { esp_apptrace_channel_t *ch; diff --git a/components/app_trace/sys_view/esp/SEGGER_RTT_esp.c b/components/app_trace/sys_view/esp/SEGGER_RTT_esp.c index b4d186f2a9..beb6128970 100644 --- a/components/app_trace/sys_view/esp/SEGGER_RTT_esp.c +++ b/components/app_trace/sys_view/esp/SEGGER_RTT_esp.c @@ -12,6 +12,7 @@ #include "esp_app_trace.h" #include "esp_log.h" +#include "esp_private/startup_internal.h" const static char *TAG = "segger_rtt"; @@ -288,4 +289,17 @@ int SEGGER_RTT_ConfigDownBuffer(unsigned BufferIndex, const char* sName, void* p return 0; } +/*************************** Init hook **************************** + * + * This init function is placed here because this port file will be + * linked whenever SystemView is used. + */ + +ESP_SYSTEM_INIT_FN(sysview_init, BIT(0), 120) +{ + SEGGER_SYSVIEW_Conf(); + return ESP_OK; +} + + /*************************** End of file ****************************/ diff --git a/components/esp_system/startup.c b/components/esp_system/startup.c index 02f02da571..98156a3d52 100644 --- a/components/esp_system/startup.c +++ b/components/esp_system/startup.c @@ -47,10 +47,6 @@ #include "esp_core_dump.h" #endif -#if CONFIG_APPTRACE_ENABLE -#include "esp_app_trace.h" -#endif - #include "esp_private/dbg_stubs.h" #if CONFIG_PM_ENABLE @@ -446,15 +442,6 @@ static void start_cpu0_default(void) ESP_SYSTEM_INIT_FN(init_components0, BIT(0), 200) { - -#if CONFIG_APPTRACE_ENABLE - esp_err_t err = esp_apptrace_init(); - assert(err == ESP_OK && "Failed to init apptrace module on PRO CPU!"); -#endif -#if CONFIG_APPTRACE_SV_ENABLE - SEGGER_SYSVIEW_Conf(); -#endif - #if CONFIG_ESP_DEBUG_STUBS_ENABLE esp_dbg_stubs_init(); #endif diff --git a/components/esp_system/system_init_fn.txt b/components/esp_system/system_init_fn.txt index d8abc241a4..7f67937c60 100644 --- a/components/esp_system/system_init_fn.txt +++ b/components/esp_system/system_init_fn.txt @@ -19,6 +19,10 @@ # esp_sleep doesn't have init dependencies 105: esp_sleep_startup_init in components/esp_hw_support/sleep_modes.c on BIT(0) +# app_trace has to be initialized before systemview +115: esp_apptrace_init in components/app_trace/app_trace.c on ESP_SYSTEM_INIT_ALL_CORES +120: sysview_init in components/app_trace/sys_view/esp/SEGGER_RTT_esp.c on BIT(0) + # the rest of the components which are initialized from startup.c # [refactor-todo]: move init calls into respective components 200: init_components0 in components/esp_system/startup.c on BIT(0)