GithubHelp home page GithubHelp logo

square / pylink Goto Github PK

View Code? Open in Web Editor NEW
331.0 23.0 124.0 440 KB

Python Library for device debugging/programming via J-Link

Home Page: https://pylink.readthedocs.io/en/latest/

License: Other

Python 89.14% Gherkin 1.04% GDB 0.23% Makefile 1.01% Assembly 4.77% C 3.81%
arm debugging firmware

pylink's Introduction

pylink

Build Status

Python interface for the SEGGER J-Link.

Requirements

Installation

Clone the project into a local repository, then navigate to the directory and run:

$ python setup.py install

External Dependencies

In order to use this library, you will need to have installed the SEGGER tools. The tools can be installed from the SEGGER website here. This package is compatible with versions of the SEGGER tool >= 6.0b. Download the software under J-Link Software and Documentation Pack for your specific hardware. PyLink will automatically find the library if you have installed it this way, but for best results, you should use one of the two methods listed below depending on your operating system:

On Mac

# Option A: Copy the library to your libraries directory.
$ cp libjlinkarm.dylib /usr/local/lib/

# Option B: Add SEGGER's J-Link directory to your dynamic libraries path.
$ export DYLD_LIBRARY_PATH=/Applications/SEGGER/JLink:$DYLD_LIBRARY_PATH

On Windows

Windows searches for DLLs in the following order:

  1. The current directory of execution.
  2. The Windows system directory.
  3. The Windows directory.

You can copy the JLinkARM.dll to any of the directories listed above. Alternatively, add the SEGGER J-Link directory to your %PATH%.

On Linux

# Option A: Copy the library to your libraries directory.
$ cp libjlinkarm.so /usr/local/lib/

# Option B: Add SEGGER's J-Link library path to your libraries path.
$ export LD_LIBRARY_PATH=/path/to/SEGGER/JLink:$LD_LIBRARY_PATH

Usage

import pylink

if __name__ == '__main__':
   serial_no = '123456789'
   jlink = pylink.JLink()

   # Open a connection to your J-Link.
   jlink.open(serial_no)

   # Connect to the target device.
   jlink.connect('device', verbose=True)

   # Do whatever you want from here on in.
   jlink.flash(firmware, 0x0)
   jlink.reset()

Troubleshooting

Should you run into any issues, refer to the documentation, as well as check out our troubleshooting document.

Documentation

Documentation follows the Google Python Style Guide, and uses Sphinx documentation generator with the Napoleon extension to provide Google style Python support. To generate the documentation, these packages will need to be installed (they are included in the provided requirements.txt file). With these packages installed, you can generate the documentation as follows:

$ cd docs
$ make html

Developing for PyLink

First install the development requirements by running:

$ pip install -r requirements.txt

After you've installed the requirements, decide on the development work you want to do. See the documentation about contributing before you begin your development work.

Testing

To run tests, execute the following:

# Unit tests
$ python setup.py test

# Functional tests
$ python setup.py bddtest

There are two types of tests: functional and unit. Information about both can be found under tests/README.md.

Coverage

Code coverage can be generated as follows:

$ python setup.py coverage
$ open htmlcov/index.html

Contributing

Please see the documentation on contributing.

License

Copyright 2017 Square, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

See terms and conditions here.

pylink's People

Contributors

avi-jois avatar bojanpotocnik avatar boraozgen avatar chanqueo avatar charlesnicholson avatar charliebruce avatar cpattenden-sq avatar curtishx avatar cy18 avatar denravonska avatar dottspina avatar eldonrivers avatar gargy007 avatar hkpeprah avatar johannesneyer avatar jsiverskog avatar kettenbach-it avatar kylemanna avatar mareknovaknxp avatar mhummels avatar michalfita avatar moral-ecomo avatar risint96 avatar rjshade avatar sauci avatar sstallion avatar thetic avatar twam avatar wallacbe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pylink's Issues

SWO output only works in debug mode?

I am trying out the Serial Wire Viewer example: serial-wire-viewer

While it does work, it only seems to work when I put the device in debug mode from the SES IDE.
Why is that? Can I do the same thing via pylink, so that the tool runs on its own?

Thanks

Kinetis/Freescale renamed to NXP

Since Freescale was bought by NXP, the newer SDK has renamed the device manufacturer to NXP. This causes .unlock() to fail with unsupported device. The unlock method in unlockers/__init__.py should call unlock_kinetis() if the name is nxp (kinetis and freescale retained for backwards compat). Should also add it to the unit test for unlocking a Kinetis device.

memory_read endianness issue

I'm facing to a strange behaviour regarding the memory_read32 function.

When I read data from a big endian target (tms570lc4357zwt), the resulting values returned from pylink are returned as big endian. However, doing the same operation in Ozone, the displayed values are correct.

As the variable I try to read holds the result of a function call, I also tried to read it using the register_read function, with R0 as parameter. This function returns the expected value.

To summarize, knowing that the expected value is 6, and the 32-bits big endian representation of 6 is 100663296:

  • Ozone shows R0 = 6, as well as the value of my variable, rst_source = 6
  • pylink returns 6 from register_read, but the value of rst_source = 100663296 with memory_read32

I'm not sure if the issue is in my script, the pylink package, or the dll itself, I just thought it was in the pylink package because of the mismatch between the value in R0 and the value returned from memory_read32

Thanks in advance for any feedacks

provide an enum for registers

Hi,

I would like to know if it would be possible to provide an enumeration to clarify the calls to register_read(self, register_index). I guess that calling this function with register_index = 0 the value of register r0 will be returned, but I'm not sure what index should be used for CPS register, more generally what index should be used for banked registers. I guess that an enum like shown bellow might help the users:

REG_R0 = 0
...
REG_R7 = 7
REG_R8_USR = ?
REG_R8_FIQ = ?
REG_R9_USR = ?
REG_R9_FIQ = ?

I know it is possible to read the banked register r8_fiq with GDB, even if the controller is not in FIQ mode, but I don't know if it would be possible using the DLL.

here's a link showing different registers available for a cortex-r5 controller (only as example).

Thanks for your feedback

can not erase by pylink

i use jlink.JLink.erase() in my project but i found it is useless by reading memory.why is that?

Old buffer contents

I have found small issue, When I use flash_file function or bigger buffer and next flash function with small buffer contents of the old buffer are still programmed. jtag_flush() don't help. Is there another function to flush buffer ?
Please check last bytes after memory_read8

Here is my log

>>> import pylink
>>> jlink = pylink.JLink()
>>> serial_no = 'xxxxxxxx'
>>> jlink.open(serial_no)
>>> jlink.product_name
'SEGGER J-Link ARM'
>>> jlink.set_tif(pylink.enums.JLinkInterfaces.SWD)
True
>>> jlink.connect('STM32F405RG', verbose=True)
>>> jlink.erase()
0
>>> jlink.memory_read8(0x8000000, 20)
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]
>>> data1 = [ 11, 11, 11, 11, 11, 11, 11]
>>> jlink.flash(data1, 0x8000000)
16384
>>> jlink.memory_read8(0x8000000, 20)
[11, 11, 11, 11, 11, 11, 11, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]
>>> data2 = [ 22, 22, 22, 22, 22, 22, 22]
>>> jlink.flash(data2, 0x8000001)
16384
>>> jlink.memory_read8(0x8000000, 20)
[11, 22, 22, 22, 22, 22, 22, 22, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]
>>> jlink.flash_file('/root/ch.bin', 0x8000000)
0
>>> jlink.memory_read8(0x8000000, 20)
[0, 4, 0, 32, 185, 2, 0, 8, 187, 2, 0, 8, 81, 26, 0, 8, 186, 2, 0, 8]
>>> jlink.erase()
0
>>> jlink.memory_read8(0x8000000, 20)
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]
>>> jlink.flash(data1, 0x8000000)
16384
>>> jlink.memory_read8(0x8000000, 20)
[11, 11, 11, 11, 11, 11, 11, 8, 187, 2, 0, 8, 81, 26, 0, 8, 186, 2, 0, 8]
>>> jlink.jtag_flush()
>>> jlink.erase()
0
>>> jlink.memory_read8(0x8000000, 20)
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]
>>> data1
[11, 11, 11, 11, 11, 11, 11]
>>> jlink.flash(data1, 0x8000000)
16384
>>> jlink.memory_read8(0x8000000, 20)
[11, 11, 11, 11, 11, 11, 11, 8, 187, 2, 0, 8, 81, 26, 0, 8, 186, 2, 0, 8]
>>> data3 = [33, 33, 33]
>>> jlink.jtag_flush()
>>> jlink.erase()
0
>>> jlink.memory_read8(0x8000000, 20)
[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]
>>> jlink.flash(data3, 0x8000000)
16384
>>> jlink.memory_read8(0x8000000, 20)
[33, 33, 33, 11, 11, 11, 11, 8, 187, 2, 0, 8, 81, 26, 0, 8, 186, 2, 0, 8]

Disable popups

When using an STM32 board as a JLink device, every day a popup appears so you cannot execute scripts in an automated manner, because you need to close the window. Is it possible to disable all the popups?

Why does it appear that 'pylink.errors.JLinkException: Unsupported device was connected to.'

``
from pylink import jlink

dllpath = 'C:\SoftWare\Office SoftWare\keil5.14\SEGGER\JLink_V614b\JLinkARM.dll'

def start():
jlk = jlink.JLink(lib=jlink.library.Library(dllpath=dllpath))
jlk.open(serial_no=123456)
print(jlk.product_name)
jlk.oem
print(jlk.opened())
print(jlk.connected())
print(jlk.target_connected())
print(jlk.update_firmware())

jlk.connect(chip_name='chip')

print(jlk.core_id())

if name == 'main':
start()
``

add support Segger tunnel server

I'm not sure if it would be possible, but it would be great to be able to open a device over the Segger's remote server using the name/serial number and optional password parameters.

To launch the server, provide either the serial number or the name, and an optional password:

  • ./JLinkRemoteServerCLExe -UseTunnel -TunnelBySN <serial_number> -TunnelPW <password>
  • ./JLinkRemoteServerCLExe -UseTunnel -TunnelByName <name> -TunnelPW <password>

Once the server is running, it is possible to connect to it using JLinkExe application:

  • JLinkExe ip tunnel:<serial_number>:<password>
  • JLinkExe ip tunnel:<tunnel_name>:<password>

Does anyone knows if this feature is available in the latest version of the DLL? My first guess would be to call the DLL function JLINKARM_SelectIP with "tunnel:<name>:<password>", but I don't know how to handle the second port parameter.

flash_file() from GUI - WindowsError: exception: access violation writing 0x000000CE00000000

Hello,

I have created a GUI (using PyQt4) that implements pylink flash_file() capability. It works great when developing in my IDE (PyCharm), but after bundling the GUI in an executable (using pyinstaller) I get this error (with varying locations 0x00____ ):

WindowsError: exception: access violation writing 0x000000CE00000000

This is the full error output:

Traceback (most recent call last):
  File "main_gui.py", line 87, in run
  File "main_gui.py", line 57, in _flash_binary
  File "build\bdist.win-amd64\egg\pylink\jlink.py", line 172, in wrapper
  File "build\bdist.win-amd64\egg\pylink\jlink.py", line 2021, in flash_file
WindowsError: exception: access violation writing 0x000000CE00000000

Also, it seems that the Segger J-flash/J-Link software is executed because this window pops up, but is stuck in this state:
image

I am able to open the J-Link and connect to the target just fine, but it crashes when trying to flash the file to the target. Here is a segment of my code that calls the flash_file method. It successfully executes all of the code but raises the Windows Exception in the line jlink.flash_file(bin_file, 0x0).

def _flash_binary():
    # Instantiate J-Link
    jlink = pylink.JLink()
    # Binary file to be used
    bin_file = 'f446re_led_blink_fast.bin'

    # Open a connection to the J-Link using Serial Number
    try:
        serial_num = 600107062
        jlink.open(serial_num)
        print "J-Link Opened."
    except pylink.errors.JLinkException as e:
        print "Error CONNECTING to J-LINK: <%s>" % e

    # Set appropriate interface to flash target
    jlink.set_tif(pylink.JLinkInterfaces.SWD)

    # Connect to the STM target device/micro-controller.
    try:
        target = 'STM32F446RE'
        jlink.connect(target)
        print "Connected to <%s> successfully." % target
    except pylink.errors.JLinkException as e:
        print "Error CONNECTING to TARGET: <%s>" % e

    try:
        # Flash the selected file to the target.
        jlink.flash_file(bin_file, 0x0)
        print "Flashed <%s> to target successfully." % bin_file
    except pylink.errors.JLinkException as e:
        print "Error FLASHING file to TARGET: " % e

Is there a way to show more detail on what is happening on the pylink side? The message does not seem very informative to me. Or could you inform me on what is happening and if there is a solution?

Thank you!

Unable to program NXP MIMXRT1064CVL5A using Pylink - supported devices look-up problem

In the jlink.py file (part of pylink) at approximately line #1055, there is a for loop used to search for the user-supplied chip name in a list of supported devices. I added a line within the for loop to write names of all of the supported devices to a disk file. There are several single entries in the resulting list that indicate support for a group devices, instead of just one device. Example: "MIMXRT1064xxx5A" appears in Segger's list of supported devices, one of only two MIMXRT1064-related list entries. Because pylink's search loop is performing a simple equality test to see if a specific chip name (such as "MIMXRT1064CVL5A") is in the list of supported devices, no specific chip name in the MIMXRT1064xxx5A group will ever be recognized as a supported device. "MIMXRT1064xxx5A" does not equal "MIMXRT1064CVL5A". Thus, setting the chip name to MIMXRT1064CVL5A and attempting to connect results in the exception message "'Unsupported device was connected to." To make things even more unhappy, if you set chip name to "MIMXRT1064xxx5A" to get pylink's search/equality test to work, then the device name "MIMXRT1064xxx5A" subsequently gets passed to Segger's JLink program, causing their software to fail during the attempt to program flash memory, because the passed-in chip name is not specific enough. If you look at all of the entries in Segger's list of supported devices, many of them are not simple device names that will properly match a specific chip name. This means that several devices will not be considered supported when they actually should be. The search for a supported device (chip name) should be made more sophisticated, to account for non-specific or otherwise complex entries in Segger's list. The specific chip name must then be passed to Segger's JLink software, as far as I can tell. Segger JLink software version: 6.82f. Pylink version: 0.7 (installed today). Python Version: 3.8.2. OS: Ubuntu 20.04.

Initialize RTT with address of RTT control block

I want to use the library to log and plot some data. When using the RTT viewer, I have to specify the exact address of the RTT control block (address is found in the .map file).

This is fine for me, but this option is not available in this library. Is there a possible solution for this?

This is what my settings look like in the RTT Viewer, I would like to reproduce these as accurately as possible with pylink.
device

JLink instantiation looking for DLL on linux platform

After installing JLink tools v6.32d for ARM on Raspbian, I am able to access the device using command line tools. Using python 2.7.9 under a virtual environment and ipython session, pylink cannot create a JLink object:

Python 2.7.9 (default, Sep 17 2016, 20:26:04)
Type "copyright", "credits" or "license" for more information.

IPython 5.7.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import pylink

In [2]: jlink = pylink.JLink()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-2e2659994c13> in <module>()
----> 1 jlink = pylink.JLink()

/home/pi/jlink/JLink_Linux_V632d_arm/venv/local/lib/python2.7/site-packages/pylink/jlink.pyc in __init__(self, lib, log, detailed_log, error, warn, unsecure_hook)
    250
    251         if lib.dll() is None:
--> 252             raise TypeError('Expected to be given a valid DLL.')
    253
    254         self._library = lib

TypeError: Expected to be given a valid DLL.

I have already copied the libjlinkarm.so file to /usr/local/lib, as well as creating a symlink in the same directory to libjlinkarm.so.6.32.4 from the JLink installation.

I also tried exporting the library path:
export LD_LIBRARY_PATH=~/jlink/JLink_Linux_V632d_arm/:$LD_LIBRARY_PATH

Individual Contributor License Agreement

Description

The CLA must be signed by all contributors. Should probably have it automatically appear when pull requests are opened so that users have to sign it, or add it into the CONTRIBUTING document.

Feature Request - HSS

I would like to see the high speed data interface HSS in the pylink library. I have seen that there are some preparations of standard calls of HSS in library.py. Any plans to support HSS in future?

how to download the elf file

very sorry for interrupting you.
can you tell me how to download the elf file?
i can't use the flash() or flash_file() to download the elf file.

how to get RTT buffer size?

The J-Link RTT Viewer can get channel description include buffer size,like below
channel info
Is there a API to do this? I try rtt_control,but failed.

OSError: [WinError 193] %1 is not a valid Win32 application

I Installed Jlink seggar and i am able to connect over SWD using Jlink commander tool. So Jlink installation works fine. I added JLinkARM.dll to path.
I installed python 3.6, pylink-square. I am able to import pylink. But getting OSError while crating JLink object. Please help.

C:\Users\nxf41542>python
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import pylink
>>> pylink.JLink()
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python36\lib\site-packages\pylink_square-0.0.7-py3.6.egg\pylink\jlink .py", line 249, in __init__ File "C:\Python36\lib\site-packages\pylink_square-0.0.7-py3.6.egg\pylink\libra ry.py", line 239, in __init__ File "C:\Python36\lib\site-packages\pylink_square-0.0.7-py3.6.egg\pylink\libra ry.py", line 277, in load_default File "C:\Python36\lib\site-packages\pylink_square-0.0.7-py3.6.egg\pylink\libra ry.py", line 331, in load File "C:\Python36\lib\ctypes\__init__.py", line 426, in LoadLibrary return self._dlltype(name) File "C:\Python36\lib\ctypes\__init__.py", line 348, in __init__ self._handle = _dlopen(self._name, mode) OSError: [WinError 193] %1 is not a valid Win32 application

Debug:
This line is failing-
ctypes.cdll.LoadLibrary('C:\\windows\\JLinkARM.dl gives above error.

Race condition when accessing library

Description

We create a temporary file that is a copy of the library when we instantiate a Library instance. This is necessary to avoid a bug in the software that prevents accessing multiple hardware peripherals in a single process. On rare occasions, dlopen will fail with an error along the lines of No Suitable Image found. It seems to best resemble this GRPC issue #5568. The solution seems to be forcing the file to be committed to disk through an atomic write.

Suggested Changes

  • Use fsync after os.write when creating a JLock object.
  • Flush the outputfile created in Library.load after write, then before closing the temporary file, call fsync on it.
  • Add a test to catch this behaviour before the patch, then ensure it's fixed after the patch.

Programming problems with MKL16 core

Hello,
I have several target MCUs in different devices I am working on. The pylink library is working great with STM32F401 cores, but I am having problems with an NXP MKL16Z64VFM4 chip.

Using JLink v6.30e, Windows 7, pylink 0.1.0 or 0.0.10
Running Segger J-Link Commander or J-Flash, it is reported that the protection settings in memory 0x400-0x40F indicate readout is disabled. Pressing "OK" triggers a mass erase and subsequent programming through that software succeeds.

However, I cannot do this through the pylink interface. Attempting to connect() to the device, I get one of several issues - not always the same. They include:

  1. WindowsError(-1073741795, 'Windows Error 0xC000001D')
  2. WindowsError('exception: access violation writing 0xCE941527',)
  3. WindowsError('exception: access violation reading 0xFFFFFFFF',)
  4. PCode returned with error code -1
    JLinkException('Unspecified error.',)

Since I cannot connect, I cannot unlock. Related to this, unlocking the Kinetis family appears to be supported in the library, but is it only a subset? I saw mention of K40 and K60 specifically - is the L family not supported?

So, my specific question is - do you have any suggestions for what might be wrong with the connection method? Any debugging tips?

Thanks in advance!

Contributors List

Description

Would be good to add a contributors list. Either as a new document, or as a part of the README.md or CONTRIBUTING.md. We'd want to standardize on a format like FirstName LastName <@handle>, or something.

JLinkMOEInfo Index always -1 for code breakpoints

I use pylink on a Ubuntu 18 64bit and an R7FS7G27H (Renesas Synergy) core via the integrated USB debug interface of the Synergy device. Everything works fine except a problem with breakpoints.
To work with breakpoints, the breakpoint is set via breakpoint_set which returns a valid handle. I then run the program until halted() returns true. Then the reason for the halt is retrieved via cpu_halt_reasons().
The instance of JLinkMOEInfo returns True for code_breakpoint(), but always contains -1 for Index.
Is there a way to retrieve which breakpoint was triggered?

provide a way to read/write system control coprocessor CP15

According to this link, the DLL seems to provide some functions to access the CP15:

  • JLINKARM_CP15_IsPresent
  • JLINKARM_CP15_ReadEx
  • JLINKARM_CP15_ReadReg
  • JLINKARM_CP15_WriteEx
  • JLINKARM_CP15_WriteReg

However, I can't find any of those functions in the project.

I tried to call the long __declspec(dllimport) JLINKARM_CP15_IsPresent() (signature available in previously mentioned link):

@connection_required
def cp15_present(self):
    """Returns whether target has CP15 co-processor.

    Returns:
        ``True`` if the target has CP15 co-processor, otherwise ``False``.
    """
    result = False
    if self._dll.JLINKARM_CP15_IsPresent() != 0:
        result = True
    return result

and it doesn't crash.

I would be happy to implement this functionality, but the content of the header file in the link does not provide enough documentation to do it.

Can't connect the device if the device had been secured.

l used the script below, but if the device had been secured, the script occurs error.
# Init the jlink
jlink = pylink.JLink()

# Open a connection to your J-Link.
jlink.open(serial_no)

# Set SWD as the interface
jlink.set_tif(pylink.enums.JLinkInterfaces.SWD)

# Connect to the target device.
jlink.connect('stm32f301k8',4000, verbose=True)

the error is shown below.

Traceback (most recent call last):
File "jlink_flash.py", line 49, in
jlink.connect('stm32f301k8',4000, verbose=True)
File "D:\APP\Python27\lib\site-packages\pylink\jlink.py", line 141, in wrapper
return func(self, *args, **kwargs)
File "D:\APP\Python27\lib\site-packages\pylink\jlink.py", line 910, in connect
result = self._dll.JLINKARM_Connect()
WindowsError: exception: priviledged instruction

I tried to use "unlock()", but it didn't work.
# jlink.unlock() #does not work

Looking forward your help! Thank you!

Not finding ATSAMD20E18A support

I can establish device ATSAMD20E18 as my device, but not ATSAMD20E18A.

Using JLink Commander, either device appears to be acceptable.

Calling pylink command line causes confusing error

Looks like the tool assumes that the argument is always provided. Its bit difficult to track down why the error is shown.

$ pylink
Traceback (most recent call last):
  File "/Users/sam/.local/share/virtualenvs/pylink-d8aVmqP2/bin/pylink", line 11, in <module>
    load_entry_point('pylink-square', 'console_scripts', 'pylink')()
  File "/Users/sam/Code/entia/aptus/pylink/pylink/__main__.py", line 598, in main
    args.command(args)
AttributeError: 'Namespace' object has no attribute 'command'

Can we replace the pusutil.pid_exists with another method?

Hi,

pylink is a greate tool and we use it to test MCU devices.
However I always met some trobules if install it on windows 10 system.
It fails to when installing psutil module and it report missing Visual Studio C++2015...
I have to cost many time to download vistual studio installer and then install C++ build tools.

I checked the code and there only one place to use psutil.pid_exists check pid is alive.
Can we remove the module psutil and replace it with other workaround?
https://stackoverflow.com/questions/568271/how-to-check-if-there-exists-a-process-with-a-given-pid-in-python

Device list different from Jlink.exe

Hello:
I'm working with NXP's MCIMX7U5_M4 processor. Using Jlink Commander 6.32a, I can connect to JTAG port and debug. If I do not pass the "-device MCIMX7U5_M4" paramenter on command line, the SEGGER J-link Target Device Settings selection menu opens and I can find the correct device name.
In python, when connecting using pylink, the MCIMX7U5_M4 is not accepted as a valid device.
jlink.connect(verbose=True, chip_name="MCIMX7U5_M4")
When I cannot pass chip_name= in the connect method, the device selection menu opens, but the MCIMX7U5_M4 is not present in the device list. The number of devices in the pylink connection is lower than the number in Jlink Commander.

I'using WIN10.
Jlink version 6.32a
Python 3.6 (pycharm 2018.1.2)
pylink 0.1.0

I debugged the DLL loading and it is copying it from correct path: C:\Program Files (x86)\SEGGER\JLink_V632a\JLinkARM.dll.

Thanks
mcimx7

calling num_memory_zones() leads to a crash

The script stop working when calling DLL function JLINK_GetMemZones (invoked inside num_memory_zones), a segmentation fault is raised.

some informations on the setup:

  • OS: MacOS Mojave 10.14.6
  • DLL: version V6.50a, compiled Aug 26 2019 10:26:25
  • firmware: J-Trace PRO V2 Cortex compiled Jun 28 2019 16:31:57
  • target: tms570lc4357zwt (ARM-Cortex R5f)

segmentation fault when unloading library on linux

We observe regular segmentation faults on linux when exiting python that seem to be related to Library.unload(). It's not fully deterministic, but it appears much more regularly when the pylink.Library() object is created on a non-main thread.

I'm not sure that there's a 100% safe way to unload the dll on linux. I think it might be reasonable to get rid of the del and unload methods entirely, and simply leave the dll resident. Is there a use case for unloading and reloading the Library object and underlying dll?

Repro case:

> uname -a
Linux nicholsonc.<redacted>.google.com 4.9.0-4-amd64 #1 SMP Debian 4.9.65-3 (2017-12-03) x86_64 GNU/Linux

> python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)                          
[GCC 6.3.0 20170118] on linux                                          
Type "help", "copyright", "credits" or "license" for more information. 
>>> import pylink                                                      
>>> l = pylink.Library('../external/vendor/JLink/linux/libjlinkarm.so')
>>> j = pylink.JLink(l)                                                
>>> del j                                                              
>>> l.unload()                                                         
Segmentation fault                                                     

Connect/Attach to existing session

Hello,

I'd like to attach to an existing session from pylink, instead of opening new connection the same way the JLink RTT Viewer does.

The open() and connect() APIs don't seem to have support for this.
I have also read through JLink docs and I can't find API to call as well.

image
image

Any ideas?

Cheers

Cannot create JLink object on Windows

On Windows 10, using SEGGER Jlink tools v6.16d, using python 3.5.2 I cannot create a JLink object:

Python 3.5.2 |Anaconda 4.3.0 (64-bit)| (default, Jul  5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
More than one account associated with username

In [1]: import pylink

In [2]: jlink = pylink.JLink()
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-2-b073914a14e8> in <module>()
----> 1 jlink = pylink.JLink()

C:\Anaconda3\lib\site-packages\pylink\jlink.py in __init__(self, lib, log, detailed_log, error, warn, unsecure_hook)
    247
    248         if lib is None:
--> 249             lib = library.Library()
    250
    251         if lib.dll() is None:

C:\Anaconda3\lib\site-packages\pylink\library.py in __init__(self, dllpath)
    237             self.load(dllpath)
    238         else:
--> 239             self.load_default()
    240
    241     def __del__(self):

C:\Anaconda3\lib\site-packages\pylink\library.py in load_default(self)
    275
    276         if path is not None:
--> 277             return self.load(path)
    278
    279         return False

C:\Anaconda3\lib\site-packages\pylink\library.py in load(self, path)
    329
    330         self._temp = tf
--> 331         self._lib = ctypes.cdll.LoadLibrary(tf.name)
    332
    333         if self._windows:

C:\Anaconda3\lib\ctypes\__init__.py in LoadLibrary(self, name)
    423
    424     def LoadLibrary(self, name):
--> 425         return self._dlltype(name)
    426
    427 cdll = LibraryLoader(CDLL)

C:\Anaconda3\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    345
    346         if handle is None:
--> 347             self._handle = _dlopen(self._name, mode)
    348         else:
    349             self._handle = handle

OSError: [WinError 193] %1 is not a valid Win32 application

I have copied the JLinkARM.dll and JLink_x64.dll files to the Windows/system32 directory and a user directory where the session is being run.

I have also attempted to pass in a path for the DLL:

In [3]: jlink = pylink.JLink('./JLink_x64.dll')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-e018fd92e1f4> in <module>()
----> 1 jlink = pylink.JLink('./JLink_x64.dll')

C:\Anaconda3\lib\site-packages\pylink\jlink.py in __init__(self, lib, log, detailed_log, error, warn, unsecure_hook)
    249             lib = library.Library()
    250
--> 251         if lib.dll() is None:
    252             raise TypeError('Expected to be given a valid DLL.')
    253

AttributeError: 'str' object has no attribute 'dll'

And using ctypes to create a DLL object for the same:

In [4]: import ctypes

In [5]: jlink_dll = ctypes.WinDLL('./JLink_x64.dll')

In [6]: jlink = pylink.JLink(jlink_dll)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-067fffa0f666> in <module>()
----> 1 jlink = pylink.JLink(jlink_dll)

C:\Anaconda3\lib\site-packages\pylink\jlink.py in __init__(self, lib, log, detailed_log, error, warn, unsecure_hook)
    249             lib = library.Library()
    250
--> 251         if lib.dll() is None:
    252             raise TypeError('Expected to be given a valid DLL.')
    253

C:\Anaconda3\lib\ctypes\__init__.py in __getattr__(self, name)
    358         if name.startswith('__') and name.endswith('__'):
    359             raise AttributeError(name)
--> 360         func = self.__getitem__(name)
    361         setattr(self, name, func)
    362         return func

C:\Anaconda3\lib\ctypes\__init__.py in __getitem__(self, name_or_ordinal)
    363
    364     def __getitem__(self, name_or_ordinal):
--> 365         func = self._FuncPtr((name_or_ordinal, self))
    366         if not isinstance(name_or_ordinal, int):
    367             func.__name__ = name_or_ordinal

AttributeError: function 'dll' not found

I assume there is some issue with the library related to 32/64-bit support, or perhaps it is not supported in python 3.5.

Windows10 pylink.JLink() fail

Windows10 pylink.JLink() fail:

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    jlink = pylink.JLink()
  File "build\bdist.win-amd64\egg\pylink\jlink.py", line 249, in __init__
  File "build\bdist.win-amd64\egg\pylink\library.py", line 239, in __init__
  File "build\bdist.win-amd64\egg\pylink\library.py", line 277, in load_default
  File "build\bdist.win-amd64\egg\pylink\library.py", line 331, in load
  File "D:\env\tools\Python27\lib\ctypes\__init__.py", line 443, in LoadLibrary
    return self._dlltype(name)
  File "D:\env\tools\Python27\lib\ctypes\__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 不是有效的 Win32 应用程序。

Have problem PYTHON ENV:

$ python
Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

No problem PYTHON ENV:

PS D:\Git\github\pylink> python
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Incorrect decorators in raw pin operation functions in the JLink class

The functions in JLink class

set_reset_pin_high(self):
set_reset_pin_low(self):
set_tck_pin_high(self):
set_tck_pin_low(self):
set_tdi_pin_high(self):
set_tdi_pin_low(self):
set_tms_pin_high(self):
set_tms_pin_low(self):
set_trst_pin_high(self):
set_trst_pin_low(self):

are raw operations and hence should be @open_required, not @connection_required.

target_connected() return error status

  1. At the beginning,target_connected() return True;
  2. then disconnect all cables between jlink and target(connection between PC and JLink still exist);
  3. target_connected() still return True

Documentation Generation

Description

Whenever a new release is cut, it would be great if we could automatically generate documentation and publish it somewhere like ReadTheDocs.

flash_file address parameter being ignored

When trying to download a bin file using flash_file() it seems the file isn't written to the passed address. The file is written to address 0x0. It seems like a DLL issue and i've tried the most recent DLL V6.86f still with the same issue.

sync_firmware() fails for JLink v6.80b

I tried to use sync_firmware() with JLink v6.80b. However the function always raises this failure: errors.JLinkException('Failed to sync firmware version.'). I checked the DLL version and firmware version. I think they are not the same for JLink v 6.80. Is there anyway to resolve the issue?

OSError: [WinError 193] %1 n’est pas une application Win32 valide

Hello, when I import openslide I get this error
import openslide
Traceback (most recent call last):

File "", line 1, in
import openslide

File "C:\Users\China\Anaconda3\envs\machine\lib\site-packages\openslide_init_.py", line 29, in
from openslide import lowlevel

File "C:\Users\China\Anaconda3\envs\machine\lib\site-packages\openslide\lowlevel.py", line 41, in
_lib = cdll.LoadLibrary('libopenslide-0.dll')

File "C:\Users\China\Anaconda3\envs\machine\lib\ctypes_init_.py", line 426, in LoadLibrary
return self._dlltype(name)

File "C:\Users\China\Anaconda3\envs\machine\lib\ctypes_init_.py", line 348, in init
self._handle = _dlopen(self._name, mode)

OSError: [WinError 193] %1 n’est pas une application Win32 valide

GPIO Control

Hello,

I'm trying to control the GPIOs on the JLink but noticed that JLINK_EMU_GPIO_SetState has been obsoleted in the SDK which makes jlink.gpio_set()'s implementation obsolete as well. As a workaround, I'm trying to use the JLINK_IFUNC_PIN_OVERRIDE function as mentioned in the SDK user guide. They provide an example in the guide and I tried implementing the example in Python using ctypes, but I cannot figure out how to successfully implement this in Python. I do not see any code in Pylink that uses these JLINK_IFUNC functions, so, I'm a little stuck. Can someone suggest a way to implement this or point me in the right direction?

Thanks,
Henry

CC: @charlesnicholson

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.