esp32s2: Adds apptrace support

Closes IDF-510.
Closes IDF-1032.
This commit is contained in:
Alexey Gerenkov 2019-07-24 20:20:11 +03:00
parent d57890cdff
commit 5909d3676c
8 changed files with 58 additions and 8 deletions

View file

@ -23,6 +23,9 @@ endif()
if(CONFIG_HEAP_TRACING_TOHOST) if(CONFIG_HEAP_TRACING_TOHOST)
list(APPEND srcs "heap_trace_tohost.c") list(APPEND srcs "heap_trace_tohost.c")
set_source_files_properties(heap_trace_tohost.c
PROPERTIES COMPILE_FLAGS
-Wno-frame-address)
endif() endif()
idf_component_register(SRCS "${srcs}" idf_component_register(SRCS "${srcs}"

View file

@ -15,9 +15,11 @@ menu "Application Level Tracing"
config ESP32_APPTRACE_ENABLE config ESP32_APPTRACE_ENABLE
bool bool
depends on !ESP32_TRAX depends on !ESP32_TRAX && !ESP32S2_TRAX
select ESP32_MEMMAP_TRACEMEM select ESP32_MEMMAP_TRACEMEM
select ESP32S2_MEMMAP_TRACEMEM
select ESP32_MEMMAP_TRACEMEM_TWOBANKS select ESP32_MEMMAP_TRACEMEM_TWOBANKS
select ESP32S2_MEMMAP_TRACEMEM_TWOBANKS
default n default n
help help
Enables/disable application tracing module. Enables/disable application tracing module.

View file

@ -158,6 +158,9 @@
#include <sys/param.h> #include <sys/param.h>
#include "soc/soc.h" #include "soc/soc.h"
#include "soc/dport_reg.h" #include "soc/dport_reg.h"
#if CONFIG_IDF_TARGET_ESP32S2BETA
#include "soc/sensitive_reg.h"
#endif
#include "eri.h" #include "eri.h"
#include "trax.h" #include "trax.h"
#include "soc/timer_periph.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__) #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) // 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_PROBLK0_APPBLK1 0
#define TRACEMEM_MUX_BLK0_ONLY 1 #define TRACEMEM_MUX_BLK0_ONLY 1
#define TRACEMEM_MUX_BLK1_ONLY 2 #define TRACEMEM_MUX_BLK1_ONLY 2
#define TRACEMEM_MUX_PROBLK1_APPBLK0 3 #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 // 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 | // | 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 #endif
#define ESP_APPTRACE_USR_BLOCK_RAW_SZ(_s_) ((_s_) + sizeof(esp_tracedata_hdr_t)) #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[] = { static volatile uint8_t *s_trax_blocks[] = {
(volatile uint8_t *) 0x3FFFC000, (volatile uint8_t *) 0x3FFFC000,
(volatile uint8_t *) 0x3FFF8000 (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])) #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 #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) static void esp_apptrace_trax_init(void)
{ {
// Stop trace, if any (on the current CPU) // 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 // switch to new block
s_trace_buf.trax.state.in_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 // handle data from host
esp_hostdata_hdr_t *hdr = (esp_hostdata_hdr_t *)s_trace_buf.trax.blocks[new_block_num].start; 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) { 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
#endif #endif
#if CONFIG_IDF_TARGET_ESP32
DPORT_WRITE_PERI_REG(DPORT_PRO_TRACEMEM_ENA_REG, DPORT_PRO_TRACEMEM_ENA_M); DPORT_WRITE_PERI_REG(DPORT_PRO_TRACEMEM_ENA_REG, DPORT_PRO_TRACEMEM_ENA_M);
#if CONFIG_FREERTOS_UNICORE == 0 #if CONFIG_FREERTOS_UNICORE == 0
DPORT_WRITE_PERI_REG(DPORT_APP_TRACEMEM_ENA_REG, DPORT_APP_TRACEMEM_ENA_M); DPORT_WRITE_PERI_REG(DPORT_APP_TRACEMEM_ENA_REG, DPORT_APP_TRACEMEM_ENA_M);
#endif #endif
// Expose block 1 to host, block 0 is current trace input buffer #endif
DPORT_WRITE_PERI_REG(DPORT_TRACEMEM_MUX_MODE_REG, TRACEMEM_MUX_BLK1_ONLY); esp_apptrace_trax_select_memory_block(0);
return ESP_OK; return ESP_OK;
} }

View file

@ -63,6 +63,13 @@ Revision: $Rev: 3734 $
*/ */
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "SEGGER_SYSVIEW.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.h"
#include "esp_app_trace_util.h" #include "esp_app_trace_util.h"
#include "esp_intr_alloc.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 #elif CONFIG_IDF_TARGET_ESP32S2BETA
#define SYSVIEW_TIMESTAMP_FREQ (CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ * 1000000) #define SYSVIEW_TIMESTAMP_FREQ (CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ * 1000000)
#endif #endif
#endif // TS_USE_CCOUNT #endif // TS_USE_CCOUNT
// System Frequency. // System Frequency.

View file

@ -18,7 +18,11 @@
#include "SEGGER_SYSVIEW.h" #include "SEGGER_SYSVIEW.h"
#include "SEGGER_SYSVIEW_Conf.h" #include "SEGGER_SYSVIEW_Conf.h"
#if CONFIG_IDF_TARGET_ESP32
#include "esp32/rom/ets_sys.h" #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_app_trace.h"
#include "esp_log.h" #include "esp_log.h"

View file

@ -257,7 +257,8 @@ menu "ESP32S2-specific"
config ESP32S2_TRACEMEM_RESERVE_DRAM config ESP32S2_TRACEMEM_RESERVE_DRAM
hex 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 default 0x0

View file

@ -95,8 +95,11 @@ MEMORY
_static_data_end = _bss_end; _static_data_end = _bss_end;
/* Heap ends at top of dram0_0_seg */ /* Heap ends at top of dram0_0_seg
_heap_end = 0x40000000 - CONFIG_ESP32S2_TRACEMEM_RESERVE_DRAM; 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); _data_seg_org = ORIGIN(rtc_data_seg);

View file

@ -13,6 +13,9 @@ endif()
if(CONFIG_HEAP_TRACING_STANDALONE) if(CONFIG_HEAP_TRACING_STANDALONE)
list(APPEND srcs "heap_trace_standalone.c") list(APPEND srcs "heap_trace_standalone.c")
set_source_files_properties(heap_trace_standalone.c
PROPERTIES COMPILE_FLAGS
-Wno-frame-address)
endif() endif()
idf_component_register(SRCS "${srcs}" idf_component_register(SRCS "${srcs}"