Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/platforms/hosted/dap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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};
Expand Down
2 changes: 2 additions & 0 deletions src/platforms/hosted/dap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/platforms/hosted/dap_jtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading