}
}
+static int stlink_usb_trace_read_callback(void *handle)
+{
+ stlink_usb_trace_read(handle);
+ return ERROR_OK;
+}
+
static enum target_state stlink_usb_v2_get_status(void *handle)
{
int result;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV2_STOP_TRACE_RX;
res = stlink_usb_xfer(handle, h->databuf, 2);
- if (res == ERROR_OK)
+ if (res == ERROR_OK) {
h->trace.enabled = false;
+ target_unregister_timer_callback(stlink_usb_trace_read_callback, handle);
+ }
}
if (res == ERROR_OK) {
h->trace.enabled = true;
LOG_DEBUG("Tracing: recording at %" PRIu32 "Hz\n", trace_hz);
+ /* We need the trace read function to be called at a
+ * high-enough frequency to ensure reasonable
+ * "timeliness" in processing ITM/DWT data.
+ * TODO: An alternative could be using the asynchronous
+ * features of the libusb-1.0 API to queue up one or more
+ * reads in advance and requeue them once they are
+ * completed. */
+ target_register_timer_callback(stlink_usb_trace_read_callback, 1, 1, handle);
}
} else {
LOG_ERROR("Tracing is not supported by this version.");
res = stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_DEBUGEN);
/* Try to start tracing, if requested */
- if (res == ERROR_OK && h->trace.source_hz) {
+ if (res == ERROR_OK && h->trace.source_hz && !h->trace.enabled) {
if (stlink_usb_trace_enable(handle) == ERROR_OK)
LOG_DEBUG("Tracing: enabled\n");
else
return ERROR_OK;
}
-static int target_unregister_timer_callback(int (*callback)(void *priv), void *priv)
+int target_unregister_timer_callback(int (*callback)(void *priv), void *priv)
{
struct target_timer_callback **p = &target_timer_callbacks;
struct target_timer_callback *c = target_timer_callbacks;
*/
int target_register_timer_callback(int (*callback)(void *priv),
int time_ms, int periodic, void *priv);
-
+int target_unregister_timer_callback(int (*callback)(void *priv), void *priv);
int target_call_timer_callbacks(void);
/**
* Invoke this to ensure that e.g. polling timer callbacks happen before