feat(tracing): add new component for tracing

This commit is contained in:
Erhan Kurubas
2025-09-25 08:58:59 +02:00
parent 3671a41e35
commit 1dac8685db
73 changed files with 2898 additions and 810 deletions
+11 -15
View File
@@ -16,22 +16,19 @@ extern "C" {
#endif
/**
* @brief Get custom trace initialization parameters (optional callback)
* @brief Initializes application tracing module for the selected destination and configuration.
*
* This is an optional callback function that user applications can implement to provide
* custom trace configuration. A weak default implementation exists in the app_trace component
* that returns menuconfig defaults (APPTRACE_CONFIG_DEFAULT()). User applications can override
* this by providing their own implementation.
*
* This function is called during early system initialization (before app_main) on all cores.
* @note Should be called before any esp_apptrace_xxx call.
*
* @return ESP_OK on success, otherwise see esp_err_t
*/
esp_apptrace_config_t esp_apptrace_get_user_params(void);
esp_err_t esp_apptrace_init(const esp_apptrace_config_t *config);
/**
* @brief Configures down buffer.
* @note Needs to be called before attempting to receive any data using esp_apptrace_down_buffer_get and esp_apptrace_read.
* This function does not protect internal data by lock.
*
* @note Needs to be called before attempting to receive any data using esp_apptrace_down_buffer_get and
* esp_apptrace_read. This function does not protect internal data by lock.
*
* @param buf Address of buffer to use for down channel (host to target) data.
* @param size Size of the buffer.
@@ -262,8 +259,8 @@ int esp_apptrace_feof(void *stream);
#define APPTRACE_JTAG_CONFIG_DEFAULT() { \
.dest = ESP_APPTRACE_DEST_JTAG, \
.dest_cfg.jtag = {0}, \
.panic_flush_tmo = CONFIG_APPTRACE_ONPANIC_HOST_FLUSH_TMO, \
.panic_flush_thresh = CONFIG_APPTRACE_POSTMORTEM_FLUSH_THRESH, \
.flush_tmo = CONFIG_APPTRACE_ONPANIC_HOST_FLUSH_TMO, \
.flush_thresh = CONFIG_APPTRACE_POSTMORTEM_FLUSH_THRESH, \
}
#endif
@@ -275,13 +272,12 @@ int esp_apptrace_feof(void *stream);
.tx_pin_num = CONFIG_APPTRACE_UART_TX_GPIO, \
.rx_pin_num = CONFIG_APPTRACE_UART_RX_GPIO, \
.baud_rate = CONFIG_APPTRACE_UART_BAUDRATE, \
.rx_buff_size = CONFIG_APPTRACE_UART_RX_BUFF_SIZE, \
.tx_buff_size = CONFIG_APPTRACE_UART_TX_BUFF_SIZE, \
.tx_msg_size = CONFIG_APPTRACE_UART_TX_MSG_SIZE, \
.task_prio = CONFIG_APPTRACE_UART_TASK_PRIO, \
}, \
.panic_flush_tmo = CONFIG_APPTRACE_ONPANIC_HOST_FLUSH_TMO, \
.panic_flush_thresh = CONFIG_APPTRACE_POSTMORTEM_FLUSH_THRESH, \
.flush_tmo = CONFIG_APPTRACE_ONPANIC_HOST_FLUSH_TMO, \
.flush_thresh = CONFIG_APPTRACE_POSTMORTEM_FLUSH_THRESH, \
}
#endif
@@ -8,10 +8,12 @@
#include "sdkconfig.h"
/* Default configurations for runtime selection (CONFIG_APPTRACE_DEST_NONE)
* These values are used when CONFIG_APPTRACE_DEST_NONE is selected in menuconfig.
* To customize at runtime, implement esp_apptrace_get_user_params()
* in your application. See esp_app_trace.h for details.
/* Default configurations for runtime selection (APPTRACE_DEST_ALL)
* These values are used when building with both JTAG and UART enabled
* to allow runtime selection. You can switch between destinations
* via esp_apptrace_get_user_params(). If this function is
* not provided by the application, JTAG is used by default with the
* configuration defined below. See esp_app_trace.h for details.
*/
#if !defined(CONFIG_APPTRACE_UART_TX_GPIO) || !defined(CONFIG_APPTRACE_UART_RX_GPIO)
@@ -22,10 +24,6 @@
#define CONFIG_APPTRACE_BUF_SIZE 16384
#endif
#ifndef CONFIG_APPTRACE_UART_RX_BUFF_SIZE
#define CONFIG_APPTRACE_UART_RX_BUFF_SIZE 128
#endif
#ifndef CONFIG_APPTRACE_UART_TX_BUFF_SIZE
#define CONFIG_APPTRACE_UART_TX_BUFF_SIZE 4096
#endif
@@ -54,8 +52,4 @@
#define CONFIG_APPTRACE_DEST_UART_NUM 1
#endif
#ifndef CONFIG_APPTRACE_SV_DEST_CPU_0
#define CONFIG_APPTRACE_SV_DEST_CPU_0 1
#endif
#endif /* ESP_APP_TRACE_CONFIG_H_ */
@@ -27,7 +27,7 @@ typedef struct {
/** Tracing module synchronization lock */
typedef struct {
spinlock_t mux;
unsigned int_state;
unsigned int int_state;
} esp_apptrace_lock_t;
/** Ring buffer control structure.
@@ -59,7 +59,6 @@ typedef struct {
int tx_pin_num; ///< TX pin number
int rx_pin_num; ///< RX pin number
int baud_rate; ///< Baud rate
uint32_t rx_buff_size; ///< RX ring buffer size
uint32_t tx_buff_size; ///< TX ring buffer size
uint32_t tx_msg_size; ///< Maximum size of the single message to transfer.
int task_prio; ///< Task priority
@@ -86,8 +85,8 @@ typedef struct {
} jtag;
} dest_cfg; ///< Destination-specific configuration
uint32_t panic_flush_tmo; ///< Panic flush timeout in milliseconds
uint32_t panic_flush_thresh; ///< Panic flush threshold in bytes
uint32_t flush_tmo; ///< Flush timeout in milliseconds
uint32_t flush_thresh; ///< Flush threshold in bytes
} esp_apptrace_config_t;
#ifdef __cplusplus
@@ -15,16 +15,37 @@ extern "C" {
#include "SEGGER_RTT.h" // SEGGER_RTT_ESP_Flush
#include "esp_app_trace_util.h" // ESP_APPTRACE_TMO_INFINITE
/* Forward declaration for esp_trace integration */
typedef struct esp_trace_encoder esp_trace_encoder_t;
/**
* @brief Inject encoder handle to SEGGER RTT layer.
*
* This maintains proper architectural layering. SEGGER RTT can accesses it's transport
*
* @param encoder Pointer to encoder instance from esp_trace
*
* @return 0 if successful, -1 if encoder is not initialized or missing required functions.
*/
int SEGGER_RTT_ESP_SetEncoder(esp_trace_encoder_t *encoder);
/**
* @brief Get the encoder handle for accessing transport functions.
*
* This is used by SEGGER_SYSVIEW_Config_FreeRTOS.c to access transport lock functions.
*
* @return Pointer to encoder instance, or NULL if not initialized.
*/
esp_trace_encoder_t* SEGGER_SYSVIEW_GetEncoder(void);
/**
* @brief Flushes remaining data in SystemView trace buffer to host.
*
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinitely.
*
* @return ESP_OK.
*/
static inline esp_err_t esp_sysview_flush(uint32_t tmo)
static inline esp_err_t esp_sysview_flush(void)
{
SEGGER_RTT_ESP_Flush(0, tmo);
SEGGER_RTT_ESP_Flush();
return ESP_OK;
}