diff --git a/components/app_trace/CMakeLists.txt b/components/app_trace/CMakeLists.txt index 7153ffcc9e..c770a964c2 100644 --- a/components/app_trace/CMakeLists.txt +++ b/components/app_trace/CMakeLists.txt @@ -30,7 +30,7 @@ endif() idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "${include_dirs}" - PRIV_REQUIRES soc esp_ipc + PRIV_REQUIRES soc esp_common LDFRAGMENTS linker.lf) diff --git a/components/app_trace/gcov/gcov_rtio.c b/components/app_trace/gcov/gcov_rtio.c index 660a70ab2a..8953611b12 100644 --- a/components/app_trace/gcov/gcov_rtio.c +++ b/components/app_trace/gcov/gcov_rtio.c @@ -25,7 +25,6 @@ #include "esp_freertos_hooks.h" #include "esp_private/dbg_stubs.h" #include "esp_ipc.h" -#include "hal/wdt_hal.h" #if CONFIG_IDF_TARGET_ESP32 #include "esp32/rom/libc_stubs.h" #elif CONFIG_IDF_TARGET_ESP32S2BETA @@ -61,18 +60,11 @@ void gcov_dump_task(void *pvParameter) } ESP_EARLY_LOGV(TAG, "Config apptrace down buf"); esp_apptrace_down_buffer_config(down_buf, ESP_GCOV_DOWN_BUF_SIZE); - /* we are directing the std outputs to the fake ones in order to reduce stack usage */ - FILE *old_stderr = stderr; - FILE *old_stdout = stdout; - stderr = (FILE *) &__sf_fake_stderr; - stdout = (FILE *) &__sf_fake_stdout; ESP_EARLY_LOGV(TAG, "Dump data..."); __gcov_dump(); // reset dump status to allow incremental data accumulation __gcov_reset(); free(down_buf); - stderr = old_stderr; - stdout = old_stdout; ESP_EARLY_LOGV(TAG, "Finish file transfer session"); dump_result = esp_apptrace_fstop(ESP_APPTRACE_DEST_TRAX); if (dump_result != ESP_OK) { diff --git a/components/esp_common/src/ipc.c b/components/esp_common/src/ipc.c index 4f6a4092ee..3255e307ea 100644 --- a/components/esp_common/src/ipc.c +++ b/components/esp_common/src/ipc.c @@ -62,6 +62,8 @@ static void IRAM_ATTR ipc_task(void* arg) if (s_gcov_func) { (*s_gcov_func)(s_gcov_func_arg); s_gcov_func = NULL; + /* we can not interfer with IPC calls so no need for further processing */ + continue; } #endif if (s_func[cpuid]) { @@ -164,13 +166,34 @@ esp_err_t esp_ipc_call_blocking(uint32_t cpu_id, esp_ipc_func_t func, void* arg) #if CONFIG_APPTRACE_GCOV_ENABLE esp_err_t esp_ipc_start_gcov_from_isr(uint32_t cpu_id, esp_ipc_func_t func, void* arg) { + portBASE_TYPE ret = pdFALSE; + if (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING) { return ESP_ERR_INVALID_STATE; } + + /* Lock IPC to avoid interferring with normal IPC calls, e.g. + avoid situation when esp_ipc_start_gcov_from_isr() is called from IRQ + in the middle of IPC call between `s_func` and `s_func_arg` modification. See esp_ipc_call_and_wait() */ +#ifdef CONFIG_ESP_IPC_USES_CALLERS_PRIORITY + ret = xSemaphoreTakeFromISR(s_ipc_mutex[cpu_id], NULL); +#else + ret = xSemaphoreTakeFromISR(s_ipc_mutex[0], NULL); +#endif + if (ret != pdTRUE) { + return ESP_ERR_TIMEOUT; + } + s_gcov_func = func; s_gcov_func_arg = arg; - xSemaphoreGiveFromISR(s_ipc_sem[cpu_id], NULL); + ret = xSemaphoreGiveFromISR(s_ipc_sem[cpu_id], NULL); - return ESP_OK; +#ifdef CONFIG_ESP_IPC_USES_CALLERS_PRIORITY + xSemaphoreGiveFromISR(s_ipc_mutex[cpu_id], NULL); +#else + xSemaphoreGiveFromISR(s_ipc_mutex[0], NULL); +#endif + + return ret == pdTRUE ? ESP_OK : ESP_FAIL; } #endif