From f0195868d3872d5acb4fbb834a4bbbcbd2d8281a Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Thu, 21 Sep 2017 14:53:12 -0700 Subject: [PATCH] Fall back on ndmreset if hartreset is unsupported. --- src/target/riscv/riscv-013.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 1dd801d3d..9f2b9d5fe 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -1220,6 +1220,16 @@ static int assert_reset(struct target *target) target->reset_halt ? 1 : 0); control = set_field(control, DMI_DMCONTROL_HARTRESET, 1); dmi_write(target, DMI_DMCONTROL, control); + + // Read back to check if hartreset is supported. + uint32_t rb = dmi_read(target, DMI_DMCONTROL); + if (!get_field(rb, DMI_DMCONTROL_HARTRESET)) { + // Use ndmreset instead. That will reset the entire device, but + // that's probably what OpenOCD wants anyway. + control = set_field(control, DMI_DMCONTROL_HARTRESET, 0); + control = set_field(control, DMI_DMCONTROL_NDMRESET, 1); + dmi_write(target, DMI_DMCONTROL, control); + } } target->state = TARGET_RESET;