Skip to content

Commit 845f74c

Browse files
authored
Merge pull request #2 from marnovandermaas/sonata_fixes - Correct test logic reset
Mimics upstream somewhat: https://github.com/pulp-platform/riscv-dbg/blob/618ee6e0e2610ef47e0dcc4df6748af3dffff731/src/dmi_jtag_tap.sv#L76 The main problem that we were seeing with OpenOCD before this change was that the TAP never actually sent any DMI requests to the rest of the debug module. OpenOCD would just hang in this case. Essentially the values for the inputs of the flipflops were not reset to the correct value while in the test logic reset state. Again this is mimicking upstream: https://github.com/pulp-platform/riscv-dbg/blob/master/src/dmi_jtag_tap.sv#L97-L101 https://github.com/pulp-platform/riscv-dbg/blob/master/src/dmi_jtag_tap.sv#L140-L144
2 parents 145bc9e + e1080bf commit 845f74c

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

debug_rom/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# See LICENSE.SiFive for license details
22

3-
// Conversion to CHERIoT Ibex ISA from RISC-V
4-
// Copyright SCI Semiconductor 2025
3+
## Conversion to CHERIoT Ibex ISA from RISC-V
4+
## Copyright SCI Semiconductor 2025
55

66
debug_rom = debug_rom.sv debug_rom.dump
77

debug_rom/debug_rom.dump

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Disassembly of section .text:
4141
860: 23 26 05 10 csw zero, 268(ca0)
4242
864: 5b 05 a0 03 cspecialr ca0, 26
4343
868: 5b 04 90 03 cspecialr cs0, 25
44-
86c: 73 00 10 00 ebreak
44+
86c: 73 00 10 00 ebreak
4545

4646
00000870 <going>:
4747
870: 23 22 05 10 csw zero, 260(ca0)
@@ -54,4 +54,4 @@ Disassembly of section .text:
5454
884: 23 24 85 10 csw s0, 264(ca0)
5555
888: 5b 05 a0 03 cspecialr ca0, 26
5656
88c: 5b 04 90 03 cspecialr cs0, 25
57-
890: 73 00 20 7b dret
57+
890: 73 00 20 7b dret

debug_rom/debug_rom.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Conversion to CHERIoT Ibex ISA from RISC-V
33
* Copyright SCI Semiconductor 2025
44
*

src/dmi_cdc.sv

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,42 +44,38 @@ module dmi_cdc (
4444

4545
// TODO: Make it clean for synthesis.
4646

47-
prim_fifo_async #(
47+
prim_fifo_async_simple #(
4848
.Width ( $bits(dm::dmi_req_t) ),
49-
.Depth ( 4 )
49+
.EnRzHs ( 1 )
5050
) i_cdc_req (
5151
.clk_wr_i ( tck_i ),
5252
.rst_wr_ni ( trst_ni ),
5353
.wvalid_i ( jtag_dmi_valid_i ),
5454
.wready_o ( jtag_dmi_ready_o ), // wrclk
5555
.wdata_i ( jtag_dmi_req_i ),
56-
.wdepth_o ( ),
5756

5857
.clk_rd_i ( clk_i ),
5958
.rst_rd_ni ( rst_ni ),
6059
.rvalid_o ( core_dmi_valid_o ),
6160
.rready_i ( core_dmi_ready_i ),
62-
.rdata_o ( core_dmi_req_o ),
63-
.rdepth_o ( )
61+
.rdata_o ( core_dmi_req_o )
6462
);
6563

66-
prim_fifo_async #(
64+
prim_fifo_async_simple #(
6765
.Width ( $bits(dm::dmi_resp_t) ),
68-
.Depth ( 4 )
66+
.EnRzHs ( 1 )
6967
) i_cdc_resp (
7068
.clk_wr_i ( clk_i ),
7169
.rst_wr_ni ( rst_ni ),
7270
.wvalid_i ( core_dmi_valid_i ),
7371
.wready_o ( core_dmi_ready_o ), // wrclk
7472
.wdata_i ( core_dmi_resp_i ),
75-
.wdepth_o ( ),
7673

7774
.clk_rd_i ( tck_i ),
7875
.rst_rd_ni ( trst_ni ),
7976
.rvalid_o ( jtag_dmi_valid_o ),
8077
.rready_i ( jtag_dmi_ready_i ),
81-
.rdata_o ( jtag_dmi_resp_o ),
82-
.rdepth_o ( )
78+
.rdata_o ( jtag_dmi_resp_o )
8379
);
8480

8581
endmodule : dmi_cdc

src/dmi_jtag_tap.sv

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module dmi_jtag_tap #(
7272
logic [IrLength-1:0] jtag_ir_shift_d, jtag_ir_shift_q;
7373
// IR register -> this gets captured from shift register upon update_ir
7474
ir_reg_e jtag_ir_d, jtag_ir_q;
75-
logic capture_ir, shift_ir, update_ir; // pause_ir
75+
logic capture_ir, shift_ir, update_ir, test_logic_reset; // pause_ir
7676

7777
always_comb begin : p_jtag
7878
jtag_ir_shift_d = jtag_ir_shift_q;
@@ -92,6 +92,12 @@ module dmi_jtag_tap #(
9292
if (update_ir) begin
9393
jtag_ir_d = ir_reg_e'(jtag_ir_shift_q);
9494
end
95+
96+
if (test_logic_reset) begin
97+
// Bring all TAP state to the initial value.
98+
jtag_ir_shift_d = '0;
99+
jtag_ir_d = IDCODE;
100+
end
95101
end
96102

97103
always_ff @(posedge tck_i, negedge trst_ni) begin : p_jtag_ir_reg
@@ -129,6 +135,12 @@ module dmi_jtag_tap #(
129135
if (idcode_select) idcode_d = {td_i, 31'(idcode_q >> 1)};
130136
if (bypass_select) bypass_d = td_i;
131137
end
138+
139+
if (test_logic_reset) begin
140+
// Bring all TAP state to the initial value.
141+
idcode_d = IdcodeValue;
142+
bypass_d = 1'b0;
143+
end
132144
end
133145

134146
// ----------------
@@ -199,7 +211,7 @@ module dmi_jtag_tap #(
199211
// Determination of next state; purely combinatorial
200212
always_comb begin : p_tap_fsm
201213

202-
trst_no = trst_ni;
214+
test_logic_reset = 1'b0;
203215

204216
capture_dr = 1'b0;
205217
shift_dr = 1'b0;
@@ -213,7 +225,7 @@ module dmi_jtag_tap #(
213225
unique case (tap_state_q)
214226
TestLogicReset: begin
215227
tap_state_d = (tms_i) ? TestLogicReset : RunTestIdle;
216-
trst_no = 1'b1;
228+
test_logic_reset = 1'b1;
217229
end
218230
RunTestIdle: begin
219231
tap_state_d = (tms_i) ? SelectDrScan : RunTestIdle;
@@ -287,7 +299,7 @@ module dmi_jtag_tap #(
287299

288300
always_ff @(posedge tck_i or negedge trst_ni) begin : p_regs
289301
if (!trst_ni) begin
290-
tap_state_q <= RunTestIdle;
302+
tap_state_q <= TestLogicReset;
291303
idcode_q <= IdcodeValue;
292304
bypass_q <= 1'b0;
293305
end else begin
@@ -300,6 +312,7 @@ module dmi_jtag_tap #(
300312
// Pass through JTAG signals to debug custom DR logic.
301313
// In case of a single TAP those are just feed-through.
302314
assign tck_o = tck_i;
315+
assign trst_no = !test_logic_reset;
303316
assign tdi_o = td_i;
304317
assign update_o = update_dr;
305318
assign shift_o = shift_dr;

0 commit comments

Comments
 (0)