hosted: assert ntrst as part of connecting

Assert the nTRST when connecting via JTAG. This is required for targets that
use this pin to enable the JTAG circuitry.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross
2025-06-03 21:02:51 +08:00
parent 41ca92fd0d
commit 942817692d
3 changed files with 32 additions and 0 deletions

View File

@@ -84,6 +84,7 @@ static bool dap_transfer_configure(uint8_t idle_cycles, uint16_t wait_retries, u
static uint32_t dap_current_clock_freq;
static bool dap_nrst_state = false;
static bool dap_ntrst_state = false;
bool dap_connect(void)
{
@@ -236,6 +237,33 @@ bool dap_nrst_set_val(const bool nrst_state)
return response == request.pin_values;
}
bool dap_ntrst_get_val(void)
{
return dap_ntrst_state;
}
bool dap_ntrst_set_val(const bool ntrst_state)
{
/* Setup the request for the pin state change request */
dap_swj_pins_request_s request = {
.request = DAP_SWJ_PINS,
/* nRST is active low, so take that into account */
.pin_values = ntrst_state ? 0U : DAP_SWJ_nTRST,
.selected_pins = DAP_SWJ_nTRST,
};
/* Tell the hardware to wait for 10µs for the pin to settle */
write_le4(request.wait_time, 0, 10);
uint8_t response = 0U;
/* Execute it and check if it failed */
if (!dap_run_cmd(&request, 7U, &response, 1U)) {
DEBUG_PROBE("%s failed\n", __func__);
return false;
}
/* Extract the current pin state for the device, de-inverting it */
dap_ntrst_state = !(response & DAP_SWJ_nTRST);
return response == request.pin_values;
}
uint32_t dap_read_reg(adiv5_debug_port_s *target_dp, const uint8_t reg)
{
const dap_transfer_request_s request = {.request = reg | DAP_TRANSFER_RnW};

View File

@@ -81,6 +81,8 @@ extern uint8_t dap_quirks;
bool dap_connect(void);
bool dap_disconnect(void);
bool dap_ntrst_get_val(void);
bool dap_ntrst_set_val(const bool ntrst_state);
bool dap_led(dap_led_type_e type, bool state);
size_t dap_info(dap_info_e requested_info, void *buffer, size_t buffer_length);
bool dap_set_reset_state(bool nrst_state);

View File

@@ -52,6 +52,8 @@ bool dap_jtag_init(void)
dap_disconnect();
dap_mode = DAP_CAP_JTAG;
dap_connect();
dap_ntrst_set_val(true);
dap_ntrst_set_val(false);
jtag_proc.jtagtap_reset = dap_jtag_reset;
jtag_proc.jtagtap_next = dap_jtag_next;