diff --git a/src/target/armv7m_trace.c b/src/target/armv7m_trace.c index 916d1a164..10f14221d 100644 --- a/src/target/armv7m_trace.c +++ b/src/target/armv7m_trace.c @@ -234,6 +234,21 @@ static int trace_connection_closed(struct connection *connection) return ERROR_OK; } +extern struct command_context *global_cmd_ctx; + +int armv7m_trace_tpiu_exit(struct target *target) +{ + struct armv7m_common *armv7m = target_to_armv7m(target); + + if (global_cmd_ctx->mode == COMMAND_CONFIG || + armv7m->trace_config.config_type == TRACE_CONFIG_TYPE_DISABLED) + return ERROR_OK; + + close_trace_channel(armv7m); + armv7m->trace_config.config_type = TRACE_CONFIG_TYPE_DISABLED; + return armv7m_trace_tpiu_config(target); +} + COMMAND_HANDLER(handle_tpiu_config_command) { struct target *target = get_current_target(CMD_CTX); diff --git a/src/target/armv7m_trace.h b/src/target/armv7m_trace.h index 076f9d582..cdf79e74c 100644 --- a/src/target/armv7m_trace.h +++ b/src/target/armv7m_trace.h @@ -95,6 +95,10 @@ extern const struct command_registration armv7m_trace_command_handlers[]; * Configure hardware accordingly to the current TPIU target settings */ int armv7m_trace_tpiu_config(struct target *target); +/** + * Disable TPIU data gathering at exit + */ +int armv7m_trace_tpiu_exit(struct target *target); /** * Configure hardware accordingly to the current ITM target settings */ diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index 316089c35..ac308b43b 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -1648,6 +1648,8 @@ void cortex_m_deinit_target(struct target *target) { struct cortex_m_common *cortex_m = target_to_cm(target); + armv7m_trace_tpiu_exit(target); + free(cortex_m->fp_comparator_list); cortex_m_dwt_free(target);