This is an automated email from Gerrit. Tomas Vanek ([email protected]) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/3720
-- gerrit commit 6eb2151055bb5121150e5f0bcf8bdd4c4a367a15 Author: Tomas Vanek <[email protected]> Date: Mon Aug 22 19:42:54 2016 +0200 jtag, target: adapt reset infrastructure for multiple targets/SMP [WIP] SRST signal is common for all targets. Without this change target specific reset assert and deassert procedures manipulate SRST and this impose problems when more than one target is configured. Some targets suffered from double pulsed SRST with JTAG transport. New reset procedure replaces former 'jtag arp_init-reset' by arp_init_reset, now used for both JTAG and SWD transports. arp_init_reset holds SRST asserted if configured 'reset_config srst_no_gating' SRST control is moved from target specific routines like cortex_m_assert_reset to ocd_process_reset_inner in startup.tcl using overridable tcl procedures reset_assert_final/reset_deassert_initial and a new tcl command arp_adapter_reset. Change-Id: I8380a1f251068702ddfd4fcfcbef81c68709076d Signed-off-by: Tomas Vanek <[email protected]> diff --git a/src/jtag/adapter.c b/src/jtag/adapter.c index 5953de7..dbaac22 100644 --- a/src/jtag/adapter.c +++ b/src/jtag/adapter.c @@ -31,6 +31,7 @@ #endif #include "jtag.h" +#include "swd.h" #include "minidriver.h" #include "interface.h" #include "interfaces.h" @@ -47,6 +48,15 @@ extern struct jtag_interface *jtag_interface; const char * const jtag_only[] = { "jtag", NULL }; +static const Jim_Nvp nvp_assert[] = { + { .name = "assert", NVP_ASSERT }, + { .name = "deassert", NVP_DEASSERT }, + { .name = "T", NVP_ASSERT }, + { .name = "F", NVP_DEASSERT }, + { .name = "t", NVP_ASSERT }, + { .name = "f", NVP_DEASSERT }, + { .name = NULL, .value = -1 } +}; static int jim_adapter_name(Jim_Interp *interp, int argc, Jim_Obj * const *argv) { @@ -456,6 +466,55 @@ COMMAND_HANDLER(handle_adapter_khz_command) return retval; } +static int jim_arp_init_reset(Jim_Interp *interp, int argc, Jim_Obj*const *argv) +{ + int e = ERROR_OK; + Jim_GetOptInfo goi; + Jim_GetOpt_Setup(&goi, interp, argc-1, argv + 1); + if (goi.argc != 0) { + Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)"); + return JIM_ERR; + } + struct command_context *context = current_command_context(interp); + if (transport_is_jtag()) + e = jtag_init_reset(context); + else if (transport_is_swd()) + e = swd_init_reset(context); + + if (e != ERROR_OK) { + Jim_Obj *eObj = Jim_NewIntObj(goi.interp, e); + Jim_SetResultFormatted(goi.interp, "error: %#s", eObj); + Jim_FreeNewObj(goi.interp, eObj); + return JIM_ERR; + } + return JIM_OK; +} + +static int jim_arp_adapter_reset(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +{ + Jim_GetOptInfo goi; + Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1); + + if (goi.argc != 1) { + Jim_WrongNumArgs(interp, 0, argv, "([tT]|[fF]|assert|deassert)"); + return JIM_ERR; + } + + Jim_Nvp *n; + int e = Jim_GetOpt_Nvp(&goi, nvp_assert, &n); + if (e != JIM_OK) { + Jim_GetOpt_NvpUnknown(&goi, nvp_assert, 1); + return e; + } + + if (n->value == NVP_ASSERT) + adapter_assert_reset(); + else + adapter_deassert_reset(); + + return JIM_OK; +} + static const struct command_registration interface_command_handlers[] = { { .name = "adapter_khz", @@ -509,6 +568,21 @@ static const struct command_registration interface_command_handlers[] = { .help = "List all built-in debug adapter interfaces (drivers)", }, { + .name = "arp_init_reset", + .mode = COMMAND_ANY, + .jim_handler = jim_arp_init_reset, + .help = "Uses TRST and SRST to try resetting everything on the JTAG scan chain." + " If SWD transport is selected command uses SRST only." + " SRST is left asserted if 'reset_config srst_no_gating'." + }, + { + .name = "arp_adapter_reset", + .mode = COMMAND_ANY, + .jim_handler = jim_arp_adapter_reset, + .help = "Controls SRST line.", + .usage = "[assert|deassert]" + }, + { .name = "reset_config", .handler = handle_reset_config_command, .mode = COMMAND_ANY, diff --git a/src/jtag/core.c b/src/jtag/core.c index 77269e4..aba9d17 100644 --- a/src/jtag/core.c +++ b/src/jtag/core.c @@ -1491,9 +1491,10 @@ int swd_init_reset(struct command_context *cmd_ctx) LOG_DEBUG("Initializing with hard SRST reset"); - if (jtag_reset_config & RESET_HAS_SRST) + if ((jtag_reset_config & (RESET_HAS_SRST|RESET_SRST_NO_GATING)) == (RESET_HAS_SRST|RESET_SRST_NO_GATING)) swd_add_reset(1); - swd_add_reset(0); + /* leave SRST asserted if SWD trasport is usable in reset state */ + retval = jtag_execute_queue(); return retval; } @@ -1539,15 +1540,14 @@ int jtag_init_reset(struct command_context *cmd_ctx) } /* some targets enable us to connect with srst asserted */ - if (jtag_reset_config & RESET_CNCT_UNDER_SRST) { - if (jtag_reset_config & RESET_SRST_NO_GATING) - jtag_add_reset(0, 1); - else { + if (jtag_reset_config & RESET_SRST_NO_GATING) + jtag_add_reset(0, 1); + else { + if (jtag_reset_config & RESET_CNCT_UNDER_SRST) LOG_WARNING("\'srst_nogate\' reset_config option is required"); - jtag_add_reset(0, 0); - } - } else jtag_add_reset(0, 0); + } + retval = jtag_execute_queue(); if (retval != ERROR_OK) return retval; diff --git a/src/jtag/startup.tcl b/src/jtag/startup.tcl index d57cafb..a08f042 100644 --- a/src/jtag/startup.tcl +++ b/src/jtag/startup.tcl @@ -21,11 +21,19 @@ proc jtag_init {} { # startup (at OpenOCD server startup, when JTAG may not yet work); and # potentially more (for reset types like cold, warm, etc) proc init_reset { mode } { - if {[using_jtag]} { - jtag arp_init-reset + if {[using_jtag] || [using_swd]} { + arp_init_reset } } +proc reset_assert_final { mode } { + arp_adapter_reset assert +} + +proc reset_deassert_initial { mode } { + arp_adapter_reset deassert +} + ######### # TODO: power_restore and power_dropout are currently neither diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index a6a9309..b43ce07 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -976,16 +976,8 @@ static int cortex_m_assert_reset(struct target *target) return ERROR_OK; } - /* some cores support connecting while srst is asserted - * use that mode is it has been configured */ - - bool srst_asserted = false; - - if ((jtag_reset_config & RESET_HAS_SRST) && - (jtag_reset_config & RESET_SRST_NO_GATING)) { - adapter_assert_reset(); - srst_asserted = true; - } + /* Some cores support connecting while srst is asserted. + * If RESET_HAS_SRST and RESET_SRST_NO_GATING are configured, core is under SRST now */ /* Enable debug requests */ int retval; @@ -1029,10 +1021,6 @@ static int cortex_m_assert_reset(struct target *target) } if (jtag_reset_config & RESET_HAS_SRST) { - /* default to asserting srst */ - if (!srst_asserted) - adapter_assert_reset(); - /* srst is asserted, ignore AP access errors */ retval = ERROR_OK; } else { diff --git a/src/target/startup.tcl b/src/target/startup.tcl index cf2813b..de93482 100644 --- a/src/target/startup.tcl +++ b/src/target/startup.tcl @@ -83,6 +83,7 @@ proc ocd_process_reset_inner { MODE } { $t arp_reset assert $halt } } + reset_assert_final $MODE foreach t $targets { $t invoke-event reset-assert-post } @@ -92,6 +93,7 @@ proc ocd_process_reset_inner { MODE } { foreach t $targets { $t invoke-event reset-deassert-pre } + reset_deassert_initial $MODE foreach t $targets { # Again, de-assert code needs to know if we 'halt' if {![using_jtag] || [jtag tapisenabled [$t cget -chain-position]]} { -- ------------------------------------------------------------------------------ _______________________________________________ OpenOCD-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openocd-devel
