pylink icon indicating copy to clipboard operation
pylink copied to clipboard

Can support C-JTAG

Open EasonNothingToSing opened this issue 1 year ago • 14 comments

Segger support c-jtag,can pylink implement it?

EasonNothingToSing avatar Jan 05 '24 08:01 EasonNothingToSing

I'm not sure. Have you tried to connect and use it with your target? What is the output?

hkpeprah avatar Jan 08 '24 19:01 hkpeprah

In my chip that supports both C-JTAG and JTAG protocols, in pylink enum type, i can't find corresponding C-JTAG type, so i just use set_tif(pylink.enums.JLinkInterfaces.JTAG) function? i will try

EasonNothingToSing avatar Jan 10 '24 06:01 EasonNothingToSing

I would try that.

hkpeprah avatar Jan 10 '24 17:01 hkpeprah

__jlink_dll = pylink.library.Library("JLink_x64.dll")

jtag = pylink.JLink(lib=__jlink_dll)
jtag.open()
jtag.set_tif(pylink.enums.JLinkInterfaces.JTAG)
jtag.connect(chip_name="N308")

print(jtag.connected()) # Ture
print(jtag.target_connected()) # False

I ran the above code and found that it can connect to J-Link, but the target cannot be connected. I'm not sure what the reason is

EasonNothingToSing avatar Jan 19 '24 06:01 EasonNothingToSing

n308_cjtag I could connect N308 with jlink commander using C-JTAG

EasonNothingToSing avatar Jan 19 '24 07:01 EasonNothingToSing

Maybe something naive, but could you try passing a different target interface from here for the target interfaces? Maybe C2? https://github.com/square/pylink/blob/master/pylink/enums.py#L274

hkpeprah avatar Feb 01 '24 18:02 hkpeprah

i try it, but when i use C2, it will print "RISC-V is not supported via C2", and i then try other option, all trigger error

EasonNothingToSing avatar Feb 06 '24 08:02 EasonNothingToSing

Are you sure your target is supported via C2? This seems to suggest that C2 is proprietary to Silicon Labs MCUs: https://community.silabs.com/s/article/jtag-and-c2-debug-interfaces?language=en_US, which to my understanding are ARM-based.

hkpeprah avatar Feb 06 '24 14:02 hkpeprah

Maybe you need to perform your own connect sequence for cJTAG, and use that instead of C2: https://wiki.segger.com/J-Link_cJTAG_specifics

hkpeprah avatar Feb 06 '24 14:02 hkpeprah

Ok, i will try that

EasonNothingToSing avatar Feb 07 '24 03:02 EasonNothingToSing

Hello, sorry to bother you again. I tried to use the DLL file provided by SEGGER to access CJTAG devices. However, when using JLINKARM_TIF_Select, I was unsure about the specific enum type and just filled in one randomly. It seems like I was still able to access the device, but I'm not clear on what happened in the middle. The specific code is as follows:

////////////////////////////////////////////////////////////
import ctypes
#
my_dll = ctypes.windll.LoadLibrary("../Jlink_x64.dll")
# # Open USB
my_dll.JLINKARM_SelectUSB(0)
# Connect to JLINK
my_dll.JLINKARM_Open()

uint_var = ctypes.c_uint32()

my_dll.JLINKARM_TIF_GetAvailable(ctypes.byref(uint_var))
print(uint_var.value)

value = my_dll.JLINKARM_TIF_Select(1 << 7)
print("prv: ", ctypes.c_uint32(value).value)

# my_dll.JLINKARM_DEVICE_GetIndex("N308".encode("ascii"))
err_buf = (ctypes.c_char * 336)()
# my_dll.JLINKARM_ExecCommand("Tif = T".encode(), err_buf, 336) // error
# err_buf = ctypes.string_at(err_buf).decode()
# print("TIF:", err_buf)

my_dll.JLINKARM_ExecCommand("Device = N308".encode(), err_buf, 336)
err_buf = ctypes.string_at(err_buf).decode()
print("DEVICE:", err_buf)

result = my_dll.JLINKARM_Connect()
print("RESULT:", result)


value = my_dll.JLINKARM_ReadMem(0, 4, ctypes.byref(uint_var))     /// I can get the correct value
print("ret: ", value)
print("value: ", hex(uint_var.value))

my_dll.JLINKARM_Close()

EasonNothingToSing avatar Apr 08 '24 03:04 EasonNothingToSing

Do you happen to know what error you saw?

hkpeprah avatar Apr 18 '24 16:04 hkpeprah

I found the macro for CJTAG in SEGGER, and by using version 7.9.4 of the DLL, calling my_dll.JLINKARM_TIF_Select(7) can successfully connect to CJTAG. Will this parameter be considered for inclusion in PyLink in the future?

EasonNothingToSing avatar Apr 28 '24 02:04 EasonNothingToSing

Feel free to make a PR to add the enum value.

hkpeprah avatar Apr 29 '24 20:04 hkpeprah