Skip to content

Commit

Permalink
riscv: check if hw reset worked, if not do a DM reset
Browse files Browse the repository at this point in the history
  • Loading branch information
mean authored and dragonmux committed Oct 31, 2023
1 parent 037a35f commit 7d936f9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/target/riscv_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,17 +826,20 @@ static target_halt_reason_e riscv_halt_poll(target_s *const target, target_addr_
static void riscv_reset(target_s *const target)
{
riscv_hart_s *const hart = riscv_hart_struct(target);
bool has_reset = false;
/* If the target does not have the nRST pin inhibited, use that to initiate reset */
if (!(target->target_options & RV_TOPT_INHIBIT_NRST)) {
platform_nrst_set_val(true);
riscv_dm_poll_state(hart->dbg_module, RV_DM_STAT_ALL_RESET);
has_reset = riscv_dm_poll_state(hart->dbg_module, RV_DM_STAT_ALL_RESET);
platform_nrst_set_val(false);
/* In theory we're done at this point and no debug state was perturbed */
} else {
/*
* Otherwise, if nRST is not usable, use instead reset via dmcontrol. In this case,
* when reset is requested, use the ndmreset bit to perform a system reset
*/
}

/*
* Otherwise, if nRST is not usable (or failed), use instead reset via dmcontrol. In this case,
* when reset is requested, use the ndmreset bit to perform a system reset
*/
if (!has_reset) {
riscv_dm_write(hart->dbg_module, RV_DM_CONTROL, hart->hartsel | RV_DM_CTRL_SYSTEM_RESET);
riscv_dm_poll_state(hart->dbg_module, RV_DM_STAT_ALL_RESET);
/* Complete the reset by resetting ndmreset */
Expand Down

0 comments on commit 7d936f9

Please sign in to comment.