From c9193f8f491ef9c385afcd48d58f87e028250a74 Mon Sep 17 00:00:00 2001 From: liangzhen Date: Thu, 4 Sep 2025 16:49:07 +0800 Subject: [PATCH] target/riscv: hard reset DTM if dmistat is busy Due to certain reasons, the DMI scan is busy, leading to a timeout and exit. When restarting OpenCD, a hard reset of the DTM is required. --- src/target/riscv/riscv-013.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index b5c6bfb07..f1a297a97 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -2016,6 +2016,12 @@ static int examine(struct target *target) return ERROR_FAIL; } + if (get_field(dtmcontrol, DTM_DTMCS_DMISTAT) != DTM_DMI_OP_SUCCESS) { + if (dtmcs_scan(target->tap, DTM_DTMCS_DTMHARDRESET, + NULL /* discard result */) != ERROR_OK) + return ERROR_FAIL; + } + riscv013_info_t *info = get_info(target); info->index = target->coreid;