square / pylink

Python Library for device debugging/programming via J-Link
https://pylink.readthedocs.io/en/latest/
Other
346 stars 127 forks source link

Cortex-M33 not connecting as expected #158

Closed s-bruce13 closed 1 year ago

s-bruce13 commented 1 year ago

Hello Im having an issue with CORTEX-M33 devices. I have tested using other devices such as CORTEX-M4 and those connect as expected.

Environment Windows 10. Python version 3.11.1 Pylink 1.0.0 (I've tested using Python2.7 as well with same results)

Expected behaviour

After opening a connection with JLink and connecting to the target, methods communicating with the target work properly. Interrogating for target_connected returns true.

Actual behaviour

After opening a connection with JLink and connecting to the target, methods communicating with the target report a JLinkException: target is not connected error. target)connected returns false

Steps to reproduce

import pylink jlink=pylink.JLink() jlink.open(600110070) jlink.product_name 'SEGGER J-Link ARM' jlink.oem jlink.opened() True jlink.connected() True jlink.target_connected() False jlink.connect('CORTEX-M33') jlink.target_connected() False

I can connect to target device just fine if I use Jlink directly: Connecting to target via SWD Found SW-DP with ID 0x6BA02477 DPIDR: 0x6BA02477 CoreSight SoC-400 or earlier Scanning AP map to find all available APs AP[3]: Stopped AP scan as end of AP map has been reached AP[0]: AHB-AP (IDR: 0x84770001) AP[1]: AHB-AP (IDR: 0x84770001) AP[2]: JTAG-AP (IDR: 0x002A0000) Iterating through AP map to find AHB-AP to use AP[0]: Core found AP[0]: AHB-AP ROM base: 0xE00FE000 CPUID register: 0x410FD213. Implementer code: 0x41 (ARM) Feature set: Mainline Found Cortex-M33 r0p3, Little endian. FPUnit: 8 code (BP) slots and 0 literal slots Security extension: implemented Secure debug: enabled CoreSight components: ROMTbl[0] @ E00FE000 [0][0]: E00FF000 CID B105100D PID 000BB4C9 ROM Table ROMTbl[1] @ E00FF000 [1][0]: E000E000 CID B105900D PID 000BBD21 DEVARCH 47702A04 DEVTYPE 00 Cortex-M33 [1][1]: E0001000 CID B105900D PID 000BBD21 DEVARCH 47701A02 DEVTYPE 00 DWT [1][2]: E0002000 CID B105900D PID 000BBD21 DEVARCH 47701A03 DEVTYPE 00 FPB [1][3]: E0000000 CID B105900D PID 000BBD21 DEVARCH 47701A01 DEVTYPE 43 ITM [0][1]: E0040000 CID B105900D PID 000BBD21 DEVARCH 00000000 DEVTYPE 11 TPIU Memory zones: Zone: Default Description: Default access mode Cortex-M33 identified.

Is there anything to change in order to test this connection. Ive tried modifying speed as well but behavior is the same and I have tried several devices that are CORTEX-M33 based.

hkpeprah commented 1 year ago

Have you tried with the exact device as opposed to passing in Cortex-M33? E.g., the STM32L552ZC is a Cortex-M33, so passing STM32L552CZ instead of Cortex-M33 when you call .connect()?

s-bruce13 commented 1 year ago

Hello the end device I am working with is not currently in supported jlink list, I can connect to it using CORTEX-M33.. However I have tested with other devices such as LPC55S69 and it does not connect either as the specific device name or CORTEX-M33.

Additionally I tested with K64(specific device name) and CORTEX-M4 and both of these options connect successfully.

I should add that when I runt .connect() function I do not get error message.

hkpeprah commented 1 year ago

Hm. So the M33 does have secure features that can prevent connection. You might need to look into seeing if you need to use the CoreSight functions in order to enable connection. The executable might be doing some logic on your behalf to facilitate that connection that this library does not do as its up to the developer.

s-bruce13 commented 1 year ago

ok that is a good tip i can take a look into. I did try to run some coresight functions that are done in the regular jlink connect script, but seems that the coresight write/read calls the .connect function as i will get an error like "Target not connected"

I've tried to connect through jlink and jump back to the pylink functions once I knew jlink had connected, but this did not work.

Do you have any suggestion as to how i may enable the connection prior to being able to succesfully connect to target?

hkpeprah commented 1 year ago

You should be able to use the coresight_configure() and coresight_write() / coresight_read() functions without calling .connect(); just .open(); the later two require configuration before you can read / write.

s-bruce13 commented 1 year ago

Thanks for information. I attempted to configure the coresight. However it causes the jlink to disconnect. Do you have any examples using a CORTEX-M33 device that i can use for reference? Here is my output:

import pylink jlink = pylink.JLink() jlink.open(600110070) jlink.product_name 'SEGGER J-Link ARM' jlink.oem jlink.opened() True jlink.connected() True jlink.coresight_configure(0,0,0,0,4) Communication timed out: Requested 4 bytes, received 0 bytes ! jlink.connected() False jlink.opened() True jlink.close() jlink.opened() False jlink.connected() False jlink.open(600110070) jlink.product_name 'SEGGER J-Link ARM' jlink.oem jlink.opened() True jlink.connected() True jlink.coresight_configure(0,0,0,0,4) jlink.connected() False jlink.opened() True

s-bruce13 commented 1 year ago

I was able to connect using a line i found from another issue:

I added jlink.set_tif(pylink.enums.JLinkInterfaces.SWD) prior to calling .connect()

Thanks for your help!

enjeru15 commented 11 months ago

Hi @s-bruce13 , when you implemented the jlink.set_tif, did it work already with Cortex-M33 without the coresight_configure() and coresight_write() functions? 'Cause until now, I'm having the same issue connecting with Cortex-M33. I think I'm not properly setting the core ー application core or net core.

enjeru15 commented 11 months ago

Are you using a dual core? If so, how are you setting it using the jlink functions?

s-bruce13 commented 11 months ago

Hi @s-bruce13 , when you implemented the jlink.set_tif, did it work already with Cortex-M33 without the coresight_configure() and coresight_write() functions? 'Cause until now, I'm having the same issue connecting with Cortex-M33. I think I'm not properly setting the core ー application core or net core.

Hi my full configuration is the following, this worked for me connecting then using coresight write functions. jlink1 = pylink.JLink() jlink1.open(600110070) jlink1.product_name jlink1.oem jlink1.opened() jlink1.connected() jlink1.set_tif(pylink.enums.JLinkInterfaces.SWD) jlink1.connect('cortex-m33', 4000, verbose=True) jlink1.target_connected()

jlink1.coresight_configure()

s-bruce13 commented 11 months ago

Are you using a dual core? If so, how are you setting it using the jlink functions?

im not using dual core just single.