Skip to content

Commit 617485e

Browse files
committed
Abort after timeout
1 parent 3b46da4 commit 617485e

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

src/dap.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use crate::{
2-
jtag::{self, TransferInfo, TransferResult},
2+
jtag::{
3+
self, TransferInfo, TransferResult, JTAG_IR_ABORT, JTAG_IR_APACC, JTAG_IR_DPACC,
4+
JTAG_IR_IDCODE,
5+
},
36
swd::{self, APnDP, RnW},
47
swj, swo, usb,
58
};
@@ -306,8 +309,7 @@ where
306309
return;
307310
}
308311

309-
const JTAG_ABORT: u32 = 0x08;
310-
jtag.shift_ir(JTAG_ABORT);
312+
jtag.shift_ir(JTAG_IR_ABORT);
311313
jtag.write_abort(word);
312314

313315
resp.write_ok();
@@ -655,9 +657,7 @@ where
655657
return;
656658
}
657659

658-
const JTAG_IDCODE: u32 = 0x0E;
659-
660-
jtag.shift_ir(JTAG_IDCODE);
660+
jtag.shift_ir(JTAG_IR_IDCODE);
661661
let data = jtag.shift_dr(0);
662662

663663
resp.write_ok();
@@ -814,8 +814,6 @@ where
814814
return;
815815
}
816816

817-
const JTAG_DPACC: u32 = 0x0A;
818-
const JTAG_APACC: u32 = 0x0B;
819817
const DP_RDBUFF: u8 = 0x0C;
820818
let read_rdbuff = TransferInfo {
821819
r_nw: RnW::R,
@@ -834,9 +832,9 @@ where
834832
let request_value = jtag::TransferInfo::from(req.next_u8());
835833
ntransfers -= 1;
836834
let request_ir = if request_value.ap_ndp == APnDP::AP {
837-
JTAG_APACC
835+
JTAG_IR_APACC
838836
} else {
839-
JTAG_DPACC
837+
JTAG_IR_DPACC
840838
};
841839
if request_value.r_nw == RnW::R {
842840
// Read register
@@ -854,8 +852,8 @@ where
854852
);
855853
} else {
856854
// Select JTAG chain
857-
if ir != JTAG_DPACC {
858-
ir = JTAG_DPACC;
855+
if ir != JTAG_IR_DPACC {
856+
ir = JTAG_IR_DPACC;
859857
jtag.shift_ir(ir);
860858
}
861859

@@ -956,8 +954,8 @@ where
956954
// Write register
957955
if post_read {
958956
// Select JTAG chain
959-
if ir != JTAG_DPACC {
960-
ir = JTAG_DPACC;
957+
if ir != JTAG_IR_DPACC {
958+
ir = JTAG_IR_DPACC;
961959
jtag.shift_ir(ir);
962960
}
963961
// Read previous data
@@ -1017,8 +1015,8 @@ where
10171015

10181016
if matches!(response_value, TransferResult::Ok(_)) {
10191017
// Select JTAG chain
1020-
if ir != JTAG_DPACC {
1021-
jtag.shift_ir(JTAG_DPACC);
1018+
if ir != JTAG_IR_DPACC {
1019+
jtag.shift_ir(JTAG_IR_DPACC);
10221020
}
10231021

10241022
// Check last write, or read previous read's result.
@@ -1131,8 +1129,6 @@ where
11311129
mut req: Request,
11321130
resp: &mut ResponseWriter,
11331131
) {
1134-
const JTAG_DPACC: u32 = 0x0A;
1135-
const JTAG_APACC: u32 = 0x0B;
11361132
const DP_RDBUFF: u8 = 0x0C;
11371133
let read_rdbuff = TransferInfo {
11381134
r_nw: RnW::R,
@@ -1165,9 +1161,9 @@ where
11651161

11661162
// Select JTAG chain
11671163
let ir = if request_value.ap_ndp == APnDP::AP {
1168-
JTAG_APACC
1164+
JTAG_IR_APACC
11691165
} else {
1170-
JTAG_DPACC
1166+
JTAG_IR_DPACC
11711167
};
11721168
jtag.shift_ir(ir);
11731169

@@ -1184,8 +1180,8 @@ where
11841180
// Read DP/AP register
11851181
if nrequests == 0 {
11861182
// Last read
1187-
if ir != JTAG_DPACC {
1188-
jtag.shift_ir(JTAG_DPACC);
1183+
if ir != JTAG_IR_APACC {
1184+
jtag.shift_ir(JTAG_IR_APACC);
11891185
}
11901186
request_value = read_rdbuff;
11911187
}
@@ -1219,8 +1215,8 @@ where
12191215

12201216
if request_count == 0 {
12211217
// Check last write
1222-
if ir != JTAG_DPACC {
1223-
jtag.shift_ir(JTAG_DPACC);
1218+
if ir != JTAG_IR_DPACC {
1219+
jtag.shift_ir(JTAG_IR_DPACC);
12241220
}
12251221
response_value =
12261222
transfer_with_retry(jtag, read_rdbuff, transfer_config, 0, retry);
@@ -1301,6 +1297,12 @@ fn transfer_with_retry<DEPS>(
13011297
}
13021298
retry -= 1;
13031299
}
1300+
1301+
if retry == 0 {
1302+
jtag.shift_ir(JTAG_IR_ABORT);
1303+
jtag.write_abort(1);
1304+
}
1305+
13041306
response_value
13051307
}
13061308

src/jtag.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ const IDLE_TO_SHIFT_IR: &[bool] = &[true, true, false, false];
162162
const SHIFT_TO_IDLE: &[bool] = &[true, true, false];
163163
const EXIT1_TO_IDLE: &[bool] = &[true, false];
164164

165+
pub(crate) const JTAG_IR_ABORT: u32 = 0x08;
166+
pub(crate) const JTAG_IR_DPACC: u32 = 0x0A;
167+
pub(crate) const JTAG_IR_APACC: u32 = 0x0B;
168+
pub(crate) const JTAG_IR_IDCODE: u32 = 0x0E;
169+
165170
// TODO: currently this only supports JTAG DP V0.
166171
const DAP_TRANSFER_OK_FAULT: u32 = 0x02;
167172

0 commit comments

Comments
 (0)