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

Can support C-JTAG #190

Open
EasonNothingToSing opened this issue Jan 5, 2024 · 14 comments
Open

Can support C-JTAG #190

EasonNothingToSing opened this issue Jan 5, 2024 · 14 comments

Comments

@EasonNothingToSing
Copy link

Segger support c-jtag,can pylink implement it?

@hkpeprah
Copy link
Contributor

hkpeprah commented Jan 8, 2024

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

@EasonNothingToSing
Copy link
Author

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

@hkpeprah
Copy link
Contributor

I would try that.

@EasonNothingToSing
Copy link
Author

__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
Copy link
Author

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

@hkpeprah
Copy link
Contributor

hkpeprah commented Feb 1, 2024

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

@EasonNothingToSing
Copy link
Author

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

@hkpeprah
Copy link
Contributor

hkpeprah commented Feb 6, 2024

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
Copy link
Contributor

hkpeprah commented Feb 6, 2024

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

@EasonNothingToSing
Copy link
Author

Ok, i will try that

@EasonNothingToSing
Copy link
Author

EasonNothingToSing commented Apr 8, 2024

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()

@hkpeprah
Copy link
Contributor

Do you happen to know what error you saw?

@EasonNothingToSing
Copy link
Author

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?

@hkpeprah
Copy link
Contributor

hkpeprah commented Apr 29, 2024

Feel free to make a PR to add the enum value, and we can get it in 🙏

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

2 participants