Skip to content

Commit 8a2692e

Browse files
erhankurespressif-bot
authored andcommitted
change(app_trace): add dest parameter to down buffer config
1 parent 3d7d781 commit 8a2692e

File tree

7 files changed

+74
-34
lines changed

7 files changed

+74
-34
lines changed

components/app_trace/app_trace.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0 OR MIT
55
*/
@@ -80,31 +80,30 @@ ESP_SYSTEM_INIT_FN(esp_apptrace_init, SECONDARY, ESP_SYSTEM_INIT_ALL_CORES, 115)
8080
return esp_apptrace_init();
8181
}
8282

83-
void esp_apptrace_down_buffer_config(uint8_t *buf, uint32_t size)
83+
esp_err_t esp_apptrace_down_buffer_config(esp_apptrace_dest_t dest, uint8_t *buf, uint32_t size)
8484
{
8585
esp_apptrace_channel_t *ch;
8686

87+
if (dest >= ESP_APPTRACE_DEST_MAX) {
88+
return ESP_ERR_INVALID_ARG;
89+
}
90+
if (buf == NULL || size == 0) {
91+
return ESP_ERR_INVALID_ARG;
92+
}
8793
if (!s_inited) {
88-
return;
89-
}
90-
// currently down buffer is supported for JTAG interface only
91-
// TODO: one more argument should be added to this function to specify HW interface: JTAG, UART0 etc
92-
ch = &s_trace_channels[ESP_APPTRACE_DEST_JTAG];
93-
if (ch->hw != NULL) {
94-
if (ch->hw->down_buffer_config != NULL) {
95-
ch->hw->down_buffer_config(ch->hw_data, buf, size);
96-
}
97-
} else {
98-
ESP_APPTRACE_LOGD("Trace destination for JTAG not supported!");
94+
return ESP_ERR_INVALID_STATE;
9995
}
100-
ch = &s_trace_channels[ESP_APPTRACE_DEST_UART];
101-
if (ch->hw != NULL) {
102-
if (ch->hw->down_buffer_config != NULL) {
103-
ch->hw->down_buffer_config(ch->hw_data, buf, size);
104-
}
105-
} else {
106-
ESP_APPTRACE_LOGD("Trace destination for UART not supported!");
96+
97+
ch = &s_trace_channels[dest];
98+
if (ch->hw == NULL) {
99+
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
100+
return ESP_FAIL;
101+
}
102+
if (ch->hw->down_buffer_config != NULL) {
103+
ch->hw->down_buffer_config(ch->hw_data, buf, size);
107104
}
105+
106+
return ESP_OK;
108107
}
109108

110109
uint8_t *esp_apptrace_down_buffer_get(esp_apptrace_dest_t dest, uint32_t *size, uint32_t user_tmo)

components/app_trace/gcov/gcov_rtio.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -46,7 +46,12 @@ void gcov_dump_task(void *pvParameter)
4646
goto gcov_exit;
4747
}
4848
ESP_EARLY_LOGV(TAG, "Config apptrace down buf");
49-
esp_apptrace_down_buffer_config(down_buf, ESP_GCOV_DOWN_BUF_SIZE);
49+
esp_err_t res = esp_apptrace_down_buffer_config(ESP_APPTRACE_DEST_JTAG, down_buf, ESP_GCOV_DOWN_BUF_SIZE);
50+
if (res != ESP_OK) {
51+
ESP_EARLY_LOGE(TAG, "Failed to config apptrace down buf (%d)!", res);
52+
dump_result = res;
53+
goto gcov_exit;
54+
}
5055
ESP_EARLY_LOGV(TAG, "Dump data...");
5156
__gcov_dump();
5257
// reset dump status to allow incremental data accumulation

components/app_trace/include/esp_app_trace.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern "C" {
1717
/**
1818
* Application trace data destinations bits.
1919
*/
20-
typedef enum {
20+
typedef enum {
2121
ESP_APPTRACE_DEST_JTAG, ///< JTAG destination
2222
ESP_APPTRACE_DEST_UART, ///< UART destination
2323
ESP_APPTRACE_DEST_MAX,
@@ -37,10 +37,13 @@ esp_err_t esp_apptrace_init(void);
3737
* @note Needs to be called before attempting to receive any data using esp_apptrace_down_buffer_get and esp_apptrace_read.
3838
* This function does not protect internal data by lock.
3939
*
40+
* @param dest Indicates HW interface to configure.
4041
* @param buf Address of buffer to use for down channel (host to target) data.
4142
* @param size Size of the buffer.
43+
*
44+
* @return ESP_OK on success, otherwise see esp_err_t
4245
*/
43-
void esp_apptrace_down_buffer_config(uint8_t *buf, uint32_t size);
46+
esp_err_t esp_apptrace_down_buffer_config(esp_apptrace_dest_t dest, uint8_t *buf, uint32_t size);
4447

4548
/**
4649
* @brief Allocates buffer for trace data.

components/app_trace/sys_view/esp/SEGGER_RTT_esp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ int SEGGER_RTT_ConfigUpBuffer(unsigned BufferIndex, const char* sName, void* pBu
288288
*/
289289
int SEGGER_RTT_ConfigDownBuffer(unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags)
290290
{
291-
esp_apptrace_down_buffer_config(s_down_buf, sizeof(s_down_buf));
292-
return 0;
291+
return esp_apptrace_down_buffer_config(ESP_APPTRACE_DEST_SYSVIEW, s_down_buf, sizeof(s_down_buf));
293292
}
294293

295294
/*************************** Init hook ****************************

docs/en/api-guides/app_trace.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,13 @@ In general, users should decide what type of data should be transferred in every
115115
size_t sz = sizeof(buf);
116116
117117
/* config down buffer */
118-
esp_apptrace_down_buffer_config(down_buf, sizeof(down_buf));
118+
esp_err_t res = esp_apptrace_down_buffer_config(ESP_APPTRACE_DEST_JTAG, down_buf, sizeof(down_buf));
119+
if (res != ESP_OK) {
120+
ESP_LOGE(TAG, "Failed to config down buffer!");
121+
return res;
122+
}
119123
/* check for incoming data and read them if any */
120-
esp_err_t res = esp_apptrace_read(ESP_APPTRACE_DEST_JTAG, buf, &sz, 0/*do not wait*/);
124+
res = esp_apptrace_read(ESP_APPTRACE_DEST_JTAG, buf, &sz, 0/*do not wait*/);
121125
if (res != ESP_OK) {
122126
ESP_LOGE(TAG, "Failed to read data from host!");
123127
return res;
@@ -138,7 +142,11 @@ In general, users should decide what type of data should be transferred in every
138142
size_t sz = 32;
139143
140144
/* config down buffer */
141-
esp_apptrace_down_buffer_config(down_buf, sizeof(down_buf));
145+
esp_err_t res = esp_apptrace_down_buffer_config(ESP_APPTRACE_DEST_JTAG, down_buf, sizeof(down_buf));
146+
if (res != ESP_OK) {
147+
ESP_LOGE(TAG, "Failed to config down buffer!");
148+
return res;
149+
}
142150
char *ptr = (char *)esp_apptrace_down_buffer_get(ESP_APPTRACE_DEST_JTAG, &sz, 100/*tmo in us*/);
143151
if (ptr == NULL) {
144152
ESP_LOGE(TAG, "Failed to get buffer!");
@@ -150,7 +158,7 @@ In general, users should decide what type of data should be transferred in every
150158
} else {
151159
printf("No data");
152160
}
153-
esp_err_t res = esp_apptrace_down_buffer_put(ESP_APPTRACE_DEST_JTAG, ptr, 100/*tmo in us*/);
161+
res = esp_apptrace_down_buffer_put(ESP_APPTRACE_DEST_JTAG, ptr, 100/*tmo in us*/);
154162
if (res != ESP_OK) {
155163
/* in case of error host tracing tool (e.g., OpenOCD) will report incomplete user buffer */
156164
ESP_LOGE(TAG, "Failed to put buffer!");

docs/en/migration-guides/release-6.x/6.0/system.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ Removed extra data buffering option. `CONFIG_APPTRACE_PENDING_DATA_SIZE_MAX` is
6161

6262
Removed deprecated `ESP_APPTRACE_DEST_TRAX` enum value. Use `ESP_APPTRACE_DEST_JTAG` instead.
6363

64+
The :cpp:func:`esp_apptrace_down_buffer_config` function now requires a destination parameter and returns an error code for proper error handling.
65+
66+
Old Version:
67+
68+
.. code-block:: c
69+
70+
esp_apptrace_down_buffer_config(down_buf, sizeof(down_buf));
71+
72+
Update to:
73+
74+
.. code-block:: c
75+
76+
esp_err_t res = esp_apptrace_down_buffer_config(ESP_APPTRACE_DEST_JTAG, down_buf, sizeof(down_buf));
77+
if (res != ESP_OK) {
78+
ESP_LOGE(TAG, "Failed to config down buffer!");
79+
return res;
80+
}
81+
6482
FreeRTOS
6583
--------
6684

docs/zh_CN/api-guides/app_trace.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,13 @@ ESP-IDF 中提供了应用层跟踪功能,用于分析应用程序的行为。
115115
size_t sz = sizeof(buf);
116116
117117
/* config down buffer */
118-
esp_apptrace_down_buffer_config(down_buf, sizeof(down_buf));
118+
esp_err_t res = esp_apptrace_down_buffer_config(ESP_APPTRACE_DEST_JTAG, down_buf, sizeof(down_buf));
119+
if (res != ESP_OK) {
120+
ESP_LOGE(TAG, "Failed to config down buffer!");
121+
return res;
122+
}
119123
/* check for incoming data and read them if any */
120-
esp_err_t res = esp_apptrace_read(ESP_APPTRACE_DEST_JTAG, buf, &sz, 0/*do not wait*/);
124+
res = esp_apptrace_read(ESP_APPTRACE_DEST_JTAG, buf, &sz, 0/*do not wait*/);
121125
if (res != ESP_OK) {
122126
ESP_LOGE(TAG, "Failed to read data from host!");
123127
return res;
@@ -138,7 +142,11 @@ ESP-IDF 中提供了应用层跟踪功能,用于分析应用程序的行为。
138142
size_t sz = 32;
139143
140144
/* config down buffer */
141-
esp_apptrace_down_buffer_config(down_buf, sizeof(down_buf));
145+
esp_err_t res = esp_apptrace_down_buffer_config(ESP_APPTRACE_DEST_JTAG, down_buf, sizeof(down_buf));
146+
if (res != ESP_OK) {
147+
ESP_LOGE(TAG, "Failed to config down buffer!");
148+
return res;
149+
}
142150
char *ptr = (char *)esp_apptrace_down_buffer_get(ESP_APPTRACE_DEST_JTAG, &sz, 100/*tmo in us*/);
143151
if (ptr == NULL) {
144152
ESP_LOGE(TAG, "Failed to get buffer!");
@@ -150,7 +158,7 @@ ESP-IDF 中提供了应用层跟踪功能,用于分析应用程序的行为。
150158
} else {
151159
printf("No data");
152160
}
153-
esp_err_t res = esp_apptrace_down_buffer_put(ESP_APPTRACE_DEST_JTAG, ptr, 100/*tmo in us*/);
161+
res = esp_apptrace_down_buffer_put(ESP_APPTRACE_DEST_JTAG, ptr, 100/*tmo in us*/);
154162
if (res != ESP_OK) {
155163
/* in case of error host tracing tool (e.g. OpenOCD) will report incomplete user buffer */
156164
ESP_LOGE(TAG, "Failed to put buffer!");

0 commit comments

Comments
 (0)