diff --git a/components/app_trace/CMakeLists.txt b/components/app_trace/CMakeLists.txt index b9bcdddcc..ef396803e 100644 --- a/components/app_trace/CMakeLists.txt +++ b/components/app_trace/CMakeLists.txt @@ -23,6 +23,9 @@ endif() if(CONFIG_HEAP_TRACING_TOHOST) list(APPEND srcs "heap_trace_tohost.c") + set_source_files_properties(heap_trace_tohost.c + PROPERTIES COMPILE_FLAGS + -Wno-frame-address) endif() idf_component_register(SRCS "${srcs}" diff --git a/components/app_trace/Kconfig b/components/app_trace/Kconfig index f1fb35edc..88010b882 100644 --- a/components/app_trace/Kconfig +++ b/components/app_trace/Kconfig @@ -15,9 +15,11 @@ menu "Application Level Tracing" config ESP32_APPTRACE_ENABLE bool - depends on !ESP32_TRAX + depends on !ESP32_TRAX && !ESP32S2_TRAX select ESP32_MEMMAP_TRACEMEM + select ESP32S2_MEMMAP_TRACEMEM select ESP32_MEMMAP_TRACEMEM_TWOBANKS + select ESP32S2_MEMMAP_TRACEMEM_TWOBANKS default n help Enables/disable application tracing module. diff --git a/components/app_trace/app_trace.c b/components/app_trace/app_trace.c index bc0d0c20b..041a3c029 100644 --- a/components/app_trace/app_trace.c +++ b/components/app_trace/app_trace.c @@ -158,6 +158,9 @@ #include #include "soc/soc.h" #include "soc/dport_reg.h" +#if CONFIG_IDF_TARGET_ESP32S2BETA +#include "soc/sensitive_reg.h" +#endif #include "eri.h" #include "trax.h" #include "soc/timer_periph.h" @@ -202,10 +205,16 @@ const static char *TAG = "esp_apptrace"; #define ESP_APPTRACE_LOGO( format, ... ) ESP_APPTRACE_LOG_LEV(E, ESP_LOG_NONE, format, ##__VA_ARGS__) // TODO: move these (and same definitions in trax.c to dport_reg.h) +#if CONFIG_IDF_TARGET_ESP32 #define TRACEMEM_MUX_PROBLK0_APPBLK1 0 #define TRACEMEM_MUX_BLK0_ONLY 1 #define TRACEMEM_MUX_BLK1_ONLY 2 #define TRACEMEM_MUX_PROBLK1_APPBLK0 3 +#elif CONFIG_IDF_TARGET_ESP32S2BETA +#define TRACEMEM_MUX_BLK0_NUM 19 +#define TRACEMEM_MUX_BLK1_NUM 20 +#define TRACEMEM_BLK_NUM2ADDR(_n_) (0x3FFB8000UL + 0x4000UL*((_n_)-4)) +#endif // TRAX is disabled, so we use its registers for our own purposes // | 31..XXXXXX..24 | 23 .(host_connect). 23 | 22 .(host_data). 22| 21..(block_id)..15 | 14..(block_len)..0 | @@ -230,10 +239,17 @@ const static char *TAG = "esp_apptrace"; #endif #define ESP_APPTRACE_USR_BLOCK_RAW_SZ(_s_) ((_s_) + sizeof(esp_tracedata_hdr_t)) +#if CONFIG_IDF_TARGET_ESP32 static volatile uint8_t *s_trax_blocks[] = { (volatile uint8_t *) 0x3FFFC000, (volatile uint8_t *) 0x3FFF8000 }; +#elif CONFIG_IDF_TARGET_ESP32S2BETA +static volatile uint8_t *s_trax_blocks[] = { + (volatile uint8_t *)TRACEMEM_BLK_NUM2ADDR(TRACEMEM_MUX_BLK0_NUM), + (volatile uint8_t *)TRACEMEM_BLK_NUM2ADDR(TRACEMEM_MUX_BLK1_NUM) +}; +#endif #define ESP_APPTRACE_TRAX_BLOCKS_NUM (sizeof(s_trax_blocks)/sizeof(s_trax_blocks[0])) @@ -413,6 +429,17 @@ esp_err_t esp_apptrace_unlock(void) } #if CONFIG_ESP32_APPTRACE_DEST_TRAX + +static inline void esp_apptrace_trax_select_memory_block(int block_num) +{ + // select memory block to be exposed to the TRAX module (accessed by host) +#if CONFIG_IDF_TARGET_ESP32 + DPORT_WRITE_PERI_REG(DPORT_TRACEMEM_MUX_MODE_REG, block_num ? TRACEMEM_MUX_BLK0_ONLY : TRACEMEM_MUX_BLK1_ONLY); +#elif CONFIG_IDF_TARGET_ESP32S2BETA + DPORT_WRITE_PERI_REG(DPORT_PMS_OCCUPY_3_REG, block_num ? BIT(TRACEMEM_MUX_BLK0_NUM-4) : BIT(TRACEMEM_MUX_BLK1_NUM-4)); +#endif +} + static void esp_apptrace_trax_init(void) { // Stop trace, if any (on the current CPU) @@ -499,7 +526,7 @@ static esp_err_t esp_apptrace_trax_block_switch(void) // switch to new block s_trace_buf.trax.state.in_block++; - DPORT_WRITE_PERI_REG(DPORT_TRACEMEM_MUX_MODE_REG, new_block_num ? TRACEMEM_MUX_BLK0_ONLY : TRACEMEM_MUX_BLK1_ONLY); + esp_apptrace_trax_select_memory_block(new_block_num); // handle data from host esp_hostdata_hdr_t *hdr = (esp_hostdata_hdr_t *)s_trace_buf.trax.blocks[new_block_num].start; if (ctrl_reg & ESP_APPTRACE_TRAX_HOST_DATA && hdr->block_sz > 0) { @@ -863,12 +890,13 @@ static esp_err_t esp_apptrace_trax_dest_init(void) #endif #endif +#if CONFIG_IDF_TARGET_ESP32 DPORT_WRITE_PERI_REG(DPORT_PRO_TRACEMEM_ENA_REG, DPORT_PRO_TRACEMEM_ENA_M); #if CONFIG_FREERTOS_UNICORE == 0 DPORT_WRITE_PERI_REG(DPORT_APP_TRACEMEM_ENA_REG, DPORT_APP_TRACEMEM_ENA_M); #endif - // Expose block 1 to host, block 0 is current trace input buffer - DPORT_WRITE_PERI_REG(DPORT_TRACEMEM_MUX_MODE_REG, TRACEMEM_MUX_BLK1_ONLY); +#endif + esp_apptrace_trax_select_memory_block(0); return ESP_OK; } diff --git a/components/app_trace/sys_view/Sample/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c b/components/app_trace/sys_view/Sample/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c index 9fe8c018c..20614e332 100644 --- a/components/app_trace/sys_view/Sample/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c +++ b/components/app_trace/sys_view/Sample/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c @@ -63,6 +63,13 @@ Revision: $Rev: 3734 $ */ #include "freertos/FreeRTOS.h" #include "SEGGER_SYSVIEW.h" +#if CONFIG_IDF_TARGET_ESP32 +#include "esp32/rom/ets_sys.h" +#include "esp32/clk.h" +#elif CONFIG_IDF_TARGET_ESP32S2BETA +#include "esp32s2beta/rom/ets_sys.h" +#include "esp32s2beta/clk.h" +#endif #include "esp_app_trace.h" #include "esp_app_trace_util.h" #include "esp_intr_alloc.h" @@ -136,7 +143,6 @@ extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; #elif CONFIG_IDF_TARGET_ESP32S2BETA #define SYSVIEW_TIMESTAMP_FREQ (CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ * 1000000) #endif - #endif // TS_USE_CCOUNT // System Frequency. diff --git a/components/app_trace/sys_view/esp32/SEGGER_RTT_esp32.c b/components/app_trace/sys_view/esp32/SEGGER_RTT_esp32.c index 2ee0a4950..604ac67c9 100644 --- a/components/app_trace/sys_view/esp32/SEGGER_RTT_esp32.c +++ b/components/app_trace/sys_view/esp32/SEGGER_RTT_esp32.c @@ -18,7 +18,11 @@ #include "SEGGER_SYSVIEW.h" #include "SEGGER_SYSVIEW_Conf.h" +#if CONFIG_IDF_TARGET_ESP32 #include "esp32/rom/ets_sys.h" +#elif CONFIG_IDF_TARGET_ESP32S2BETA +#include "esp32s2beta/rom/ets_sys.h" +#endif #include "esp_app_trace.h" #include "esp_log.h" diff --git a/components/esp32s2beta/Kconfig b/components/esp32s2beta/Kconfig index 9aa2f2a86..a89f67f55 100644 --- a/components/esp32s2beta/Kconfig +++ b/components/esp32s2beta/Kconfig @@ -257,7 +257,8 @@ menu "ESP32S2-specific" config ESP32S2_TRACEMEM_RESERVE_DRAM hex - default 0x4000 if ESP32S2_MEMMAP_TRACEMEM + default 0x8000 if ESP32S2_MEMMAP_TRACEMEM && ESP32S2_MEMMAP_TRACEMEM_TWOBANKS + default 0x4000 if ESP32S2_MEMMAP_TRACEMEM && !ESP32S2_MEMMAP_TRACEMEM_TWOBANKS default 0x0 diff --git a/components/esp32s2beta/ld/esp32s2beta.ld b/components/esp32s2beta/ld/esp32s2beta.ld index 54eb54a7b..c3f877f60 100644 --- a/components/esp32s2beta/ld/esp32s2beta.ld +++ b/components/esp32s2beta/ld/esp32s2beta.ld @@ -95,8 +95,11 @@ MEMORY _static_data_end = _bss_end; -/* Heap ends at top of dram0_0_seg */ -_heap_end = 0x40000000 - CONFIG_ESP32S2_TRACEMEM_RESERVE_DRAM; +/* Heap ends at top of dram0_0_seg + ROM data mappings start from 0x3FFFC000, + 0x3FFF4000...0x3FFFC000 can be reserved for trace memory mapping +*/ +_heap_end = 0x3FFFC000 - CONFIG_ESP32S2_TRACEMEM_RESERVE_DRAM; _data_seg_org = ORIGIN(rtc_data_seg); diff --git a/components/heap/CMakeLists.txt b/components/heap/CMakeLists.txt index 0bacaf74f..2e194b5ae 100644 --- a/components/heap/CMakeLists.txt +++ b/components/heap/CMakeLists.txt @@ -13,6 +13,9 @@ endif() if(CONFIG_HEAP_TRACING_STANDALONE) list(APPEND srcs "heap_trace_standalone.c") + set_source_files_properties(heap_trace_standalone.c + PROPERTIES COMPILE_FLAGS + -Wno-frame-address) endif() idf_component_register(SRCS "${srcs}"