Skip to content

Commit cf0960e

Browse files
committed
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 <[email protected]>
1 parent 94ca0c7 commit cf0960e

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/platforms/hosted/dap.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ static bool dap_transfer_configure(uint8_t idle_cycles, uint16_t wait_retries, u
8484

8585
static uint32_t dap_current_clock_freq;
8686
static bool dap_nrst_state = false;
87+
static bool dap_ntrst_state = false;
8788

8889
bool dap_connect(void)
8990
{
@@ -236,6 +237,33 @@ bool dap_nrst_set_val(const bool nrst_state)
236237
return response == request.pin_values;
237238
}
238239

240+
bool dap_ntrst_get_val(void)
241+
{
242+
return dap_ntrst_state;
243+
}
244+
245+
bool dap_ntrst_set_val(const bool ntrst_state)
246+
{
247+
/* Setup the request for the pin state change request */
248+
dap_swj_pins_request_s request = {
249+
.request = DAP_SWJ_PINS,
250+
/* nRST is active low, so take that into account */
251+
.pin_values = ntrst_state ? 0U : DAP_SWJ_nTRST,
252+
.selected_pins = DAP_SWJ_nTRST,
253+
};
254+
/* Tell the hardware to wait for 10µs for the pin to settle */
255+
write_le4(request.wait_time, 0, 10);
256+
uint8_t response = 0U;
257+
/* Execute it and check if it failed */
258+
if (!dap_run_cmd(&request, 7U, &response, 1U)) {
259+
DEBUG_PROBE("%s failed\n", __func__);
260+
return false;
261+
}
262+
/* Extract the current pin state for the device, de-inverting it */
263+
dap_ntrst_state = !(response & DAP_SWJ_nTRST);
264+
return response == request.pin_values;
265+
}
266+
239267
uint32_t dap_read_reg(adiv5_debug_port_s *target_dp, const uint8_t reg)
240268
{
241269
const dap_transfer_request_s request = {.request = reg | DAP_TRANSFER_RnW};

src/platforms/hosted/dap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ extern uint8_t dap_quirks;
8181

8282
bool dap_connect(void);
8383
bool dap_disconnect(void);
84+
bool dap_ntrst_get_val(void);
85+
bool dap_ntrst_set_val(const bool ntrst_state);
8486
bool dap_led(dap_led_type_e type, bool state);
8587
size_t dap_info(dap_info_e requested_info, void *buffer, size_t buffer_length);
8688
bool dap_set_reset_state(bool nrst_state);

src/platforms/hosted/dap_jtag.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ bool dap_jtag_init(void)
5353
dap_disconnect();
5454
dap_mode = DAP_CAP_JTAG;
5555
dap_connect();
56+
dap_ntrst_set_val(true);
57+
dap_ntrst_set_val(false);
5658

5759
jtag_proc.jtagtap_reset = dap_jtag_reset;
5860
jtag_proc.jtagtap_next = dap_jtag_next;

0 commit comments

Comments
 (0)