From f92d7174cc09e153b47985a31d20a7f1ed5fe3a9 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Thu, 15 Nov 2018 12:30:30 -0500 Subject: [PATCH] target/arm_adi_v5: power off chip debug hardware on shutdown Change-Id: I759442371439ec54597f75964115776bfaa67949 --- src/target/arm_adi_v5.c | 20 ++++++++++++++++++++ src/target/arm_adi_v5.h | 3 +++ src/target/cortex_m.c | 2 ++ 3 files changed, 25 insertions(+) diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c index 2d47da3ea..6fa7d2018 100644 --- a/src/target/arm_adi_v5.c +++ b/src/target/arm_adi_v5.c @@ -731,6 +731,26 @@ int dap_dp_init(struct adiv5_dap *dap) return retval; } +/** + * Deinitialize a DAP. This turns off power to the debug domain. + * + * @param dap The DAP being initialized. + */ +int dap_dp_uninit(struct adiv5_dap *dap) +{ + int retval; + + LOG_DEBUG("%s", adiv5_dap_name(dap)); + + /* Deassert CDBGPWRUPREQ and CSYSPWRUPREQ */ + dap->dp_ctrl_stat = 0; + retval = dap_queue_dp_write(dap, DP_CTRL_STAT, dap->dp_ctrl_stat); + if (retval != ERROR_OK) + return retval; + + return dap_run(dap); +} + /** * Initialize a DAP. This sets up the power domains, prepares the DP * for further use, and arranges to use AP #0 for all AP operations diff --git a/src/target/arm_adi_v5.h b/src/target/arm_adi_v5.h index 17365bddb..9466c17ba 100644 --- a/src/target/arm_adi_v5.h +++ b/src/target/arm_adi_v5.h @@ -552,6 +552,9 @@ int mem_ap_write_buf_noincr(struct adiv5_ap *ap, int dap_dp_init(struct adiv5_dap *dap); int mem_ap_init(struct adiv5_ap *ap); +/* Deinitialisation of the debug system and power domains */ +int dap_dp_uninit(struct adiv5_dap *dap); + /* Invalidate cached DP select and cached TAR and CSW of all APs */ void dap_invalidate_cache(struct adiv5_dap *dap); diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index 9a1f2b16f..a937d28b4 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -1800,6 +1800,8 @@ void cortex_m_deinit_target(struct target *target) { struct cortex_m_common *cortex_m = target_to_cm(target); + dap_dp_uninit(cortex_m->armv7m.debug_ap->dap); + free(cortex_m->fp_comparator_list); cortex_m_dwt_free(target);