Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R9A02G021 OpenOCD errors "Error: JTAG scan chain interrogation failed: all ones" , "Error: r9A02g021.cpu: IR capture error; saw 0x1f not 0x01" and "Error: Unsupported DTM version: 15" #1197

Open
MikelB03 opened this issue Jan 3, 2025 · 14 comments

Comments

@MikelB03
Copy link

MikelB03 commented Jan 3, 2025

Hi,

I am generating a program in Rust with Visual Studio Code for the R9A02G021 microcontroller. Using OpenOCD to program de microcontroller I have this errors before conecting with OpenOCD:

I don't have an especific file ".cfg" for the microcontroller so just I generated one, using this one as an example (https://github.com/openocd-org/openocd/blob/master/tcl/target/renesas_rz_five.cfg).

This are the errors, debug and info when I execute openOCD:

ikerlan@21310-638:~/sf/r9a02g021_rust/sf_rust/FrenoEmergencia$ openocd -f openocd.cfg -d
Open On-Chip Debugger 0.12.0
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
User : 3 1 options.c:52 configuration_output_handler(): debug_level: 3
User : 4 1 options.c:52 configuration_output_handler():
Debug: 5 1 options.c:233 add_default_dirs(): bindir=/usr/local/bin
Debug: 6 1 options.c:234 add_default_dirs(): pkgdatadir=/usr/local/share/openocd
Debug: 7 1 options.c:235 add_default_dirs(): exepath=/usr/local/bin
Debug: 8 1 options.c:236 add_default_dirs(): bin2data=../share/openocd
Debug: 9 1 configuration.c:33 add_script_search_dir(): adding /home/ikerlan/.config/openocd
Debug: 10 1 configuration.c:33 add_script_search_dir(): adding /home/ikerlan/.openocd
Debug: 11 1 configuration.c:33 add_script_search_dir(): adding /usr/local/bin/../share/openocd/site
Debug: 12 1 configuration.c:33 add_script_search_dir(): adding /usr/local/bin/../share/openocd/scripts
Debug: 13 1 command.c:155 script_debug(): command - ocd_find openocd.cfg
Debug: 14 1 configuration.c:88 find_file(): found openocd.cfg
Debug: 15 1 command.c:155 script_debug(): command - ocd_find interface/jlink.cfg
Debug: 16 1 configuration.c:88 find_file(): found /usr/local/bin/../share/openocd/scripts/interface/jlink.cfg
Debug: 17 1 command.c:155 script_debug(): command - adapter driver jlink
Debug: 18 1 command.c:155 script_debug(): command - transport select jtag
Debug: 19 1 command.c:155 script_debug(): command - reset_config trst_and_srst srst_gates_jtag
Debug: 20 1 command.c:155 script_debug(): command - adapter speed 1000
Debug: 21 1 adapter.c:251 adapter_config_khz(): handle adapter khz
Debug: 22 1 adapter.c:215 adapter_khz_to_speed(): convert khz to adapter specific speed value
Debug: 23 1 adapter.c:215 adapter_khz_to_speed(): convert khz to adapter specific speed value
Debug: 24 1 command.c:155 script_debug(): command - adapter driver jlink
Warn : 25 1 adapter.c:435 handle_adapter_driver_command(): Interface already configured, ignoring
Debug: 26 1 command.c:155 script_debug(): command - adapter srst delay 500
Debug: 27 1 command.c:155 script_debug(): command - jtag newtap r9A02g021 cpu -irlen 5 -expected-id 0x0E000447
Debug: 28 1 tcl.c:557 jim_newtap_cmd(): Creating New Tap, Chip: r9A02g021, Tap: cpu, Dotted: r9A02g021.cpu, 4 params
Debug: 29 1 tcl.c:582 jim_newtap_cmd(): Processing option: -irlen
Debug: 30 1 tcl.c:582 jim_newtap_cmd(): Processing option: -expected-id
Debug: 31 1 core.c:1474 jtag_tap_init(): Created Tap: r9A02g021.cpu @ abs position 0, irlen 5, capture: 0x1 mask: 0x3
Debug: 32 1 command.c:155 script_debug(): command - target create r9A02g021.cpu riscv -chain-position r9A02g021.cpu
Debug: 33 1 target.c:2199 target_free_all_working_areas_restore(): freeing all working areas
Debug: 34 1 riscv.c:432 riscv_create_target(): riscv_create_target()
Debug: 35 1 command.c:155 script_debug(): command - riscv set_reset_timeout_sec 120
Debug: 36 1 command.c:155 script_debug(): command - riscv set_command_timeout_sec 120
Debug: 37 1 command.c:155 script_debug(): command - riscv set_mem_access sysbus progbuf
Info : 38 1 server.c:297 add_service(): Listening on port 6666 for tcl connections
Info : 39 1 server.c:297 add_service(): Listening on port 4444 for telnet connections
Debug: 40 2 command.c:155 script_debug(): command - init
Debug: 41 2 command.c:155 script_debug(): command - target init
Debug: 42 2 command.c:155 script_debug(): command - target names
Debug: 43 2 command.c:155 script_debug(): command - r9A02g021.cpu cget -event gdb-flash-erase-start
Debug: 44 2 command.c:155 script_debug(): command - r9A02g021.cpu configure -event gdb-flash-erase-start reset init
Debug: 45 2 command.c:155 script_debug(): command - r9A02g021.cpu cget -event gdb-flash-write-end
Debug: 46 2 command.c:155 script_debug(): command - r9A02g021.cpu configure -event gdb-flash-write-end reset halt
Debug: 47 2 command.c:155 script_debug(): command - r9A02g021.cpu cget -event gdb-attach
Debug: 48 2 command.c:155 script_debug(): command - r9A02g021.cpu configure -event gdb-attach halt 1000
Debug: 49 2 target.c:1657 handle_target_init_command(): Initializing targets...
Debug: 50 2 riscv.c:445 riscv_init_target(): riscv_init_target()
Debug: 51 2 semihosting_common.c:109 semihosting_common_init():
Debug: 52 2 jlink.c:635 jlink_init(): Using libjaylink 0.3.1 (compiled with 0.3.1)
Debug: 53 3 jlink.c:514 jaylink_log_handler(): Found device (VID:PID = 1366:1020, bus:address = 001:002)
Debug: 54 5 jlink.c:514 jaylink_log_handler(): Device: USB address = 0
Debug: 55 5 jlink.c:514 jaylink_log_handler(): Device: Serial number = 1089561578
Debug: 56 5 jlink.c:514 jaylink_log_handler(): Allocating new device instance
Debug: 57 5 jlink.c:514 jaylink_log_handler(): Found 1 USB device(s)
Debug: 58 5 jlink.c:514 jaylink_log_handler(): Trying to open device (bus:address = 001:002)
Debug: 59 5 jlink.c:514 jaylink_log_handler(): Using endpoint 81 (IN) and 02 (OUT)
Debug: 60 5 jlink.c:514 jaylink_log_handler(): Device opened successfully
Info : 68 7 jlink.c:707 jlink_init(): J-Link OB-RA4M2 compiled Oct 9 2024 11:01:47
Info : 81 10 jlink.c:748 jlink_init(): Hardware version: 1.00
Info : 90 13 jlink.c:789 jlink_init(): VTarget = 3.300 V
Debug: 96 14 jlink.c:514 jaylink_log_handler(): Last read operation left 16 bytes in the buffer
Debug: 106 16 jlink.c:942 jlink_reset(): TRST: 0, SRST: 0
Debug: 124 23 adapter.c:215 adapter_khz_to_speed(): convert khz to adapter specific speed value
Debug: 125 23 adapter.c:219 adapter_khz_to_speed(): have adapter set up
Debug: 132 25 adapter.c:215 adapter_khz_to_speed(): convert khz to adapter specific speed value
Debug: 133 25 adapter.c:219 adapter_khz_to_speed(): have adapter set up
Info : 134 25 adapter.c:179 adapter_init(): clock speed 1000 kHz
Debug: 135 25 openocd.c:134 handle_init_command(): Debug Adapter init complete
Debug: 136 25 command.c:155 script_debug(): command - transport init
Debug: 137 25 transport.c:219 handle_transport_init(): handle_transport_init
Debug: 138 25 jlink.c:942 jlink_reset(): TRST: 0, SRST: 0
Debug: 143 26 core.c:830 jtag_add_reset(): SRST line released
Debug: 144 26 core.c:855 jtag_add_reset(): TRST line released
Debug: 145 26 core.c:328 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 146 547 command.c:155 script_debug(): command - jtag arp_init
Debug: 147 547 core.c:1509 jtag_init_inner(): Init JTAG chain
Debug: 148 547 core.c:328 jtag_call_event_callbacks(): jtag event: TAP reset
Debug: 156 551 core.c:1234 jtag_examine_chain(): DR scan interrogation for IDCODE/BYPASS
Debug: 157 551 core.c:328 jtag_call_event_callbacks(): jtag event: TAP reset
Error: 165 556 core.c:1122 jtag_examine_chain_check(): JTAG scan chain interrogation failed: all ones
Error: 166 556 core.c:1124 jtag_examine_chain_check(): Check JTAG interface, timings, target power, etc.
Error: 167 556 core.c:1554 jtag_init_inner(): Trying to use configured scan chain anyway...
Debug: 168 556 core.c:1364 jtag_validate_ircapture(): IR capture validation scan
Error: 176 560 core.c:1413 jtag_validate_ircapture(): r9A02g021.cpu: IR capture error; saw 0x1f not 0x01
Debug: 177 560 core.c:328 jtag_call_event_callbacks(): jtag event: TAP reset
Warn : 185 565 core.c:1577 jtag_init_inner(): Bypassing JTAG setup events due to errors
Debug: 186 565 command.c:155 script_debug(): command - dap init
Debug: 187 565 arm_dap.c:97 dap_init_all(): Initializing all DAPs ...
Debug: 188 565 openocd.c:151 handle_init_command(): Examining targets...
Debug: 189 565 target.c:1843 target_call_event_callbacks(): target event 19 (examine-start) for core r9A02g021.cpu
Debug: 190 565 riscv.c:1121 riscv_examine(): riscv_examine()
Debug: 198 569 riscv.c:406 dtmcontrol_scan(): DTMCONTROL: 0x0 -> 0xffffffff
Debug: 199 569 riscv.c:1131 riscv_examine(): dtmcontrol=0xffffffff
Debug: 200 569 riscv.c:1133 riscv_examine(): version=0xf
Error: 201 569 riscv.c:425 get_target_type(): Unsupported DTM version: 15
Debug: 202 569 target.c:1843 target_call_event_callbacks(): target event 20 (examine-fail) for core r9A02g021.cpu
Warn : 203 569 target.c:802 target_examine(): target r9A02g021.cpu examination failed
Debug: 204 569 openocd.c:153 handle_init_command(): target examination failed
Debug: 205 569 command.c:155 script_debug(): command - flash init
Debug: 206 569 tcl.c:1375 handle_flash_init_command(): Initializing flash devices...
Debug: 207 569 command.c:155 script_debug(): command - nand init
Debug: 208 569 tcl.c:487 handle_nand_init_command(): Initializing NAND devices...
Debug: 209 569 command.c:155 script_debug(): command - pld init
Debug: 210 570 pld.c:194 handle_pld_init_command(): Initializing PLDs...
Debug: 211 570 command.c:155 script_debug(): command - tpiu init
Info : 212 570 gdb_server.c:3791 gdb_target_start(): starting gdb server for r9A02g021.cpu on 3333
Info : 213 570 server.c:297 add_service(): Listening on port 3333 for gdb connections

Did anyone else have these problems? Any ideas of how to fix this?

Thanks for any help

@TommyMurphyTM1234
Copy link
Collaborator

This:

Error: 165 556 core.c:1122 jtag_examine_chain_check(): JTAG scan chain interrogation failed: all ones

means that TDO is stuck at 1 so may indicate some problem with the target side configuration of the debug mechanism. E.g. problem with reset, clocking, pull-ups/pull-downs, etc. on the target board.

You need to ensure that the target board is configured correctly for debug access to work.

Other than the possibility that the OpenOCD script isn't doing an appropriate reset for your target this almost certainly isn't an OpenOCD problem per se.

@MikelB03
Copy link
Author

MikelB03 commented Jan 3, 2025

And how I configured correctly the target board, that is, the TDO?
I didnt't configure anything of the target board.

I only create a ".cfg" file for this board. This is what I have in my openocd.cfg file:

Sample OpenOCD configuration for R9A02G021 / JLink

JLink

source [find interface/jlink.cfg]

transport select jtag

reset_config trst_and_srst srst_gates_jtag
adapter speed 100
adapter driver jlink
adapter srst delay 500

if { [info exists CHIPNAME] } {
set _CHIPNAME $CHIPNAME
} else {
set _CHIPNAME r9A02g021
}

jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x0E000447

set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME riscv -chain-position $_TARGETNAME

riscv set_reset_timeout_sec 120
riscv set_command_timeout_sec 120
riscv set_mem_access sysbus progbuf

@TommyMurphyTM1234
Copy link
Collaborator

And how I configured correctly the target board, that is, the TDO?

I don't understand the question.

I didnt't configure anything of the target board.

You'll probably have to check with the board/vendor documentation and maybe their forums to see what, if anything, needs to be done in order to allow debugging via J-Link and/or OpenOCD.

Can you connect to the board using the J-Link and their software or the vendor's software?

@MikelB03
Copy link
Author

MikelB03 commented Jan 7, 2025

Yes, I can connect to the board using the J-Link and their software.

@TommyMurphyTM1234
Copy link
Collaborator

Yes, I can connect to the board using the J-Link and their software.

Can you get a log from a working J-Link session in order to compare it to the OpenOCD -d3 log to see if that gives any clues? Especially in regard to initial connectivity and reset issues?

@MikelB03
Copy link
Author

MikelB03 commented Jan 7, 2025

With J-Link Commander gives this:

J-Link>connect R9A02G021
Please specify device / core. : R9A02G021
Type '?' for selection dialog
Device>R9A02G021
Device "R9A02G021" selected.

Connecting to target via cJTAG
ConfigTargetSettings() start
ConfigTargetSettings() end - Took 39us
Could not measure total IR len. TDO is constant high.
Failed to identify target. Resetting via Reset pin and trying again.
ConfigTargetSettings() start
ConfigTargetSettings() end - Took 11us
TotalIRLen = 5, IRPrint = 0x05
JTAG chain detection found 1 devices:
#0 Id: 0x00000001, IRLen: 05, Unknown device
Assuming RISC-V TAP with DTM setup
Debug architecture:
RISC-V debug: 0.13
AddrBits: 14
DataBits: 32
IdleClks: 4
Memory access:
Via system bus: No
Via ProgBuf: Yes (8 ProgBuf entries)
Via abstract command (AAM): May be tried as last resort
DataBuf: 4 entries
autoexec[0] implemented: Yes
Detected: RV32 core
Temp. halting CPU for for feature detection...
HW instruction/data BPs: 4
Support set/clr BPs while running: No
HW data BPs trigger before execution of inst
CSR access via abs. commands: Yes
Compressed instruction support: Yes
Feature detection done. Restarting core...
BG memory access support: No
SetupTarget() start
Memory access: CPU temp. halted: https://wiki.segger.com/Memory_accesses#Stop_mode
SetupTarget() end - Took 28.8ms
Initializing 12288 bytes work RAM @ 0x20004000
Reset type: Normal (https://wiki.segger.com/J-Link_Reset_Strategies)
RISC-V: Performing reset via

****** Error: Communication timed out: Requested 4 bytes, received -2 bytes !
Error occurred: Could not connect to the target device.
For troubleshooting steps visit: https://wiki.segger.com/J-Link_Troubleshooting
J-Link>

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Jan 7, 2025

This may be relevant:

Could not measure total IR len. TDO is constant high.
Failed to identify target. Resetting via Reset pin and trying again.

I don't know what "reset pin" this is referring to but whatever is being done here probably needs to be somehow replicated in your OpenOCD script.

@MikelB03
Copy link
Author

MikelB03 commented Jan 9, 2025

Hi,

Without changing the speed to 100Khz, using the default one. I have this:

SEGGER J-Link Commander V8.12 (Compiled Dec 18 2024 15:24:46)
DLL version V8.12, compiled Dec 18 2024 15:23:49

Connecting to J-Link via USB...O.K.
Firmware: J-Link OB-RA4M2 compiled Oct 9 2024 11:01:47
Hardware version: V1.00
J-Link uptime (since boot): 0d 00h 34m 41s
S/N: 1089561578
USB speed mode: Full speed (12 MBit/s)
VTref=3.300V

Type "connect" to establish a target connection, '?' for help
J-Link>connect
Please specify device / core. : R9A02G021
Type '?' for selection dialog
Device>R9A02G021
Please specify target interface:
J) JTAG (Default)
S) SWD
T) cJTAG
TIF>T
Device position in JTAG chain (IRPre,DRPre) : -1,-1 => Auto-detect
JTAGConf>
Specify target interface speed [kHz]. : 4000 kHz
Speed>
Device "R9A02G021" selected.

Connecting to target via cJTAG
ConfigTargetSettings() start
ConfigTargetSettings() end - Took 27us
TotalIRLen = 5, IRPrint = 0x05
JTAG chain detection found 1 devices:
#0 Id: 0x00000001, IRLen: 05, Unknown device
Assuming RISC-V TAP with DTM setup
Debug architecture:
RISC-V debug: 0.13
AddrBits: 14
DataBits: 32
IdleClks: 4
Memory access:
Via system bus: No
Via ProgBuf: Yes (8 ProgBuf entries)
Via abstract command (AAM): May be tried as last resort
DataBuf: 4 entries
autoexec[0] implemented: Yes
Detected: RV32 core
Temp. halting CPU for for feature detection...
HW instruction/data BPs: 4
Support set/clr BPs while running: No
HW data BPs trigger before execution of inst
CSR access via abs. commands: Yes
Compressed instruction support: Yes
Feature detection done. Restarting core...
BG memory access support: No
SetupTarget() start
Memory access: CPU temp. halted: https://wiki.segger.com/Memory_accesses#Stop_mode
SetupTarget() end - Took 28.3ms
Initializing 12288 bytes work RAM @ 0x20004000
Reset type: Normal (https://wiki.segger.com/J-Link_Reset_Strategies)
RISC-V: Performing reset via
Memory zones:
Zone: "Default" Description: Default access mode
RISC-V identified.

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Jan 9, 2025

Connecting to target via cJTAG

The J-Link is connecting over cJTAG.
(I failed to notice this in your first J-Link log!)
I don't think that OpenOCD supports cJTAG connectivity to RISC-V targets?
If that's the case then you probably need to try connecting the J-Link over JTAG for meaningful comparison with the OpenOCD case and in order to see if any clues can be identified to make the latter work.

@aap-sc
Copy link
Collaborator

aap-sc commented Jan 9, 2025

@MikelB03

Connecting to target via cJTAG

My guess that this line is the problem. It looks like your tools connect via cJTAG.

  1. There is nothing in your jlink configuration (listed here R9A02G021 OpenOCD errors "Error: JTAG scan chain interrogation failed: all ones" , "Error: r9A02g021.cpu: IR capture error; saw 0x1f not 0x01" and "Error: Unsupported DTM version: 15" #1197 (comment)) that indicates that cjtag is configured properly.
  2. I'm not even sure that support for cjtag is implemented for jlink adapters in OpenOCD. I've scanned the codebase and I don't see anything resembling cjtag in jlink driver. riscv-openocd has support for ftdi adapters, though. I think that it's better to ask in upstream regarding the status of cjtag for jlink: https://openocd.org/pages/mailing-lists.html

@MikelB03
Copy link
Author

MikelB03 commented Jan 9, 2025

The J-Link is connecting over cJTAG. I don't think that OpenOCD supports cJTAG connectivity to RISC-V targets? If that's the case then you probably need to try connecting the J-Link over JTAG for meaningful comparison with the OpenOCD case and in order to see if any clues can be identified to make the latter work.

That true because when I configure the interface with cJtag in the openocd.cfg file, openocd tells me that doesn't support cJtag. Meaby is not possible using openOCD for this microcontroller.

If I try connecting the J-Link over JTAG. I have the problem of TDO and I don't know how to fix it.
"Could not measure total IR len. TDO is constant high.
Failed to identify target. Resetting via Reset pin and trying again."

This is what I have with JTAG interface in J-Link:

SEGGER J-Link Commander V8.12 (Compiled Dec 18 2024 15:24:46)
DLL version V8.12, compiled Dec 18 2024 15:23:49

Connecting to J-Link via USB...O.K.
Firmware: J-Link OB-RA4M2 compiled Oct 9 2024 11:01:47
Hardware version: V1.00
J-Link uptime (since boot): 0d 00h 00m 08s
S/N: 1089561578
USB speed mode: Full speed (12 MBit/s)
VTref=3.300V

Type "connect" to establish a target connection, '?' for help
J-Link>connect
Please specify device / core. : R9A02G021
Type '?' for selection dialog
Device>R9A02G021
Please specify target interface:
J) JTAG (Default)
S) SWD
T) cJTAG
TIF>J
Device position in JTAG chain (IRPre,DRPre) : -1,-1 => Auto-detect
JTAGConf>
Specify target interface speed [kHz]. : 4000 kHz
Speed>
Device "R9A02G021" selected.

Connecting to target via JTAG
ConfigTargetSettings() start
ConfigTargetSettings() end - Took 17us
Could not measure total IR len. TDO is constant high.
Failed to identify target. Resetting via Reset pin and trying again.
ConfigTargetSettings() start
ConfigTargetSettings() end - Took 9us
Could not measure total IR len. TDO is constant high.
Error occurred: Could not connect to the target device.
For troubleshooting steps visit: https://wiki.segger.com/J-Link_Troubleshooting

@aap-sc
Copy link
Collaborator

aap-sc commented Jan 9, 2025

Could not measure total IR len. TDO is constant high.

Yep. Your SW tells you the same thing that @TommyMurphyTM1234 said above (#1197 (comment))

I have the problem of TDO and I don't know how to fix it.

Thats about physical connection and schematic of your board. I doubt that you can fix it in SW. At this point I would suggest to ask in https://openocd.org/pages/mailing-lists.html and ask if anyone is working on cjtag for jlink (maybe there is even a fork somewhere?)

@TommyMurphyTM1234
Copy link
Collaborator

You probably also need to check the relevant Renesas documentation and/or forums to see if something needs to be done with this device in order to get JTAG connectivity working.

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Jan 9, 2025

You might also need to check the relevant Renesas documentation and/or forums relating to this device to find out if something specific needs to be done in order to enable/allow JTAG access for debugging purposes.

E.g. could this "ID authentication" be required perhaps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants