From f9509c92dba370be363f5641d3fefe2250bee10c Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 13 Nov 2020 19:41:41 +0100 Subject: [PATCH] itm: rework itm commands before 'init' If the command 'itm port[s]' is issued before 'init', the ITM can not be programmed because OpenOCD cannot access the target yet. The configuration is recorded and applied after target examine. The current test to trigger the ITM delayed-programming is based on the TPIU configuration. This is allowed because the only use of ITM it so send data through TPIU. In case of system TPIU, not belonging anymore to the target, there is no more association between target ITM and system TPIU. Add a flag to record the pending ITM configuration requested before 'init' and test the flag to trigger the delayed-programming of the ITM. Change-Id: I101eb97a116d7925cd2ff068f3e8813fc008b08e Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6029 Tested-by: jenkins --- src/target/armv7m_trace.c | 10 ++++++---- src/target/armv7m_trace.h | 2 ++ src/target/cortex_m.c | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/target/armv7m_trace.c b/src/target/armv7m_trace.c index adfef2e9b..02f3f1061 100644 --- a/src/target/armv7m_trace.c +++ b/src/target/armv7m_trace.c @@ -408,8 +408,9 @@ COMMAND_HANDLER(handle_itm_port_command) if (CMD_CTX->mode == COMMAND_EXEC) return armv7m_trace_itm_config(target); - else - return ERROR_OK; + + armv7m->trace_config.itm_deferred_config = true; + return ERROR_OK; } COMMAND_HANDLER(handle_itm_ports_command) @@ -427,8 +428,9 @@ COMMAND_HANDLER(handle_itm_ports_command) if (CMD_CTX->mode == COMMAND_EXEC) return armv7m_trace_itm_config(target); - else - return ERROR_OK; + + armv7m->trace_config.itm_deferred_config = true; + return ERROR_OK; } static const struct command_registration tpiu_command_handlers[] = { diff --git a/src/target/armv7m_trace.h b/src/target/armv7m_trace.h index cdf79e74c..61142b1e3 100644 --- a/src/target/armv7m_trace.h +++ b/src/target/armv7m_trace.h @@ -78,6 +78,8 @@ struct armv7m_trace_config { bool itm_async_timestamps; /** Enable synchronisation packet transmission (for sync port only) */ bool itm_synchro_packets; + /** Config ITM after target examine */ + bool itm_deferred_config; /** Current frequency of TRACECLKIN (usually matches HCLK) */ unsigned int traceclkin_freq; diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index ce2c426ce..4580c10ff 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -2082,10 +2082,11 @@ int cortex_m_examine(struct target *target) if (retval != ERROR_OK) return retval; - if (armv7m->trace_config.config_type != TRACE_CONFIG_TYPE_DISABLED) { + if (armv7m->trace_config.config_type != TRACE_CONFIG_TYPE_DISABLED) armv7m_trace_tpiu_config(target); + + if (armv7m->trace_config.itm_deferred_config) armv7m_trace_itm_config(target); - } /* NOTE: FPB and DWT are both optional. */