• Stars
    star
    122
  • Rank 282,976 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created about 9 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python wrapper for Segger's J-Link Commander & STMicro STLink V2 to flash various ARM MCUs

Adalink ARM CPU Tool

Tool to automate flashing ARM CPUs with new program code using a Segger J-link or STMicro STLink V2 device.

Currently supported cores:

  • atsamd21g18
  • lpc824
  • lpc1343
  • nrf51822
  • nrf52832
  • nrf52840
  • stm32f2

Installation

There are three options for installing and using adalink:

  • Use a pre-built standalone binary distribution. See the releases tab for the current release for each platform (Windows, OSX). You don't need Python installed for this option to work, but you will need JLink and/or OpenOCD tools installed. You will also need to manually add the downloaded adalink executable to your system path so the command is available from any terminal.

  • Download the source and run it directly with Python. This is a good option if the binary distribution doesn't work and you don't want to install the code globally. You will also need JLink and/or OpenOCD tools installed. Jump to the Running Without Installation section to learn more about this option.

  • Install from source using the setup.py script. This is useful if you're developing or modifying adalink code. You will need JLink and/or OpenOCD tools installed. Jump to the Install from Source section to learn more about this option.

Once you've installed or downloaded a release of adalink see the Usage section for information on how to use it.

Running Without Installation

To run the tool without having to install it simply clone the repository, navigate to the repository's folder in a terminal (i.e. the directory with the setup.py file) and run:

python -m adalink.main

This will invoke the program as if you ran the adalink command. All the command line parameters, etc. are the same and specified after the -m adalink.main part of the command.

Note that you will still need JLink and/or OpenOCD executables in your path--see the Install JLink and Install OpenOCD sections above.

In addition you might need to manually install the click module. Using pip run sudo pip install click (omit sudo on Windows) to install this module, then try running adalink as describe above.

Install from Source

On Linux and MacOS run:

sudo python setup.py develop

On Windows run:

python setup.py develop

Note that currently the setuptools 'develop' mode is used because of an issue/bug under investigation.

Install J-Link Tools

To use the Segger J-Link programmer you must install Segger's J-Link tools. Note that there is currently no version of Segger's tools which will work on a Raspberry Pi--check out the STLink V2 programmer if using the Pi.

Once the tools are installed you must make sure they are in your system path. On Windows the tools are by default installed to C:\Program Files (x86)\SEGGER\JLink_V496h so add that to your path. On Linux and MacOSX the path is the location of download.

To check if JLink's tools are in your path, on Linux/MacOSX try running JLinkExe or on Windows try running JLink in a command Window. If you receive a command not found error then carefully check you have the JLink tools installed and in your system path.

Install OpenOCD

To use the STLink V2 programmer you must install OpenOCD version 0.9.0. Below are the easiest options for installing OpenOCD on your platform:

Debian, Ubuntu, and Raspbian (Raspberry Pi)

Run the included install_openocd_debian.sh script to download, compile, and install OpenOCD 0.9.0 automatically. After cloning this repository navigate to it in a terminal and run:

chmod +x install_openocd_debian.sh
./install_openocd_debian.sh

The script will download, compile, and install OpenOCD. When if finishes you should see a message such as:

=====================================
Successfully installed OpenOCD 0.9.0!
=====================================

Note that on a Raspberry Pi that installation will take around 30 minutes to an hour as the code is compiled.

Mac OSX

On Mac OSX the easiest way to install OpenOCD 0.9.0 is with the homebrew software installation tool. After installing homebrew open a terminal and execute:

brew install openocd

If you already have homebrew installed make sure it has up to date formulas for building software by first running:

brew update

Then run the brew install command above to install openocd. This will ensure you get the latest 0.9.0 version of OpenOCD.

Windows

On Windows the easiest way to install OpenOCD is with an unofficial pre-built binary package. Download the OpenOCD 0.9.0 package from here, open the archive (using 7zip). Then add the extracted openocd-0.9.0\bin or \bin-x64 (if on a 64-bit operating system) path to your system path.

When using the STLink V2 programmer with OpenOCD on Windows you will also need to use Zadig tool to force Windows to use a libusb driver for the STLink device. Follow the basic usage here, but look for an STLink device and install the libusbK driver for the device. This driver installation only needs to be done once for the STLink device.

Uninstall

If you installed adalink using its setup.py you can uninstall it using the pip package manager. Note that if you are running adalink from a stand-alone binary or directly from its source then you just need to delete the files to remove it.

You can install pip by downloading and executing the get-pip.py script here.

Then run the following to uninstall adalink:

sudo pip uninstall adalink

Note on Windows the sudo part of the command should be omitted.

Usage

Once installed run the following command to see the usage information:

adalink --help

There are two command line parameters which are required when using adalink. The first is a positional argument that specifies the CPU core to program. You can see a full list of supported cores by running the --help command above.

The second required parameter is the --programmer option which chooses the programming hardware to use to communicate with the chip. Once you've chosen a CPU core you can see the supported programmers for it by running the --help option again, for example to see the supported programmers for the nRF51822 run:

adalink nrf51822 --help

The --programmer option shows both the jlink and stlink options are available:

-p, --programmer [jlink|stlink]
                                Programmer type.  [required]

You can also see other options for the core which represent available actions to perform, such as listing information or programming a hex file:

-w, --wipe                      Wipe flash memory before programming.
-i, --info                      Display information about the core.
-h, --program-hex PATH          Program the specified .hex file. Can be
                                specified multiple times.
-b, --program-bin PATH ADDRESS  Program the specified .bin file at the
                                provided address. Address can be specified
                                in hex, like 0x00FF.  Can be specified
                                multiple times.

To perform one of the actions invoke adalink with the core parameter, programmer option, and the desired action option. For example to wipe a nRF51822 board and program it using a JLink with a bootloader, soft device, app, and app signature hex file you can run:

adalink nrf51822 --programmer jlink --wipe --program-hex bootloader.hex --program-hex soft_device.hex --program-hex app.hex --program-hex app_signature.hex

You can also issue the --info command to try to retrieve basic info about the connected nRF51822 device, which can be done with the following command (again assuming the JLink programmer):

adalink nrf51822 --programmer jlink --info

Which should give you a response like the following (depending on the device connected to the J-Link):

Hardware ID : QFACA10 (32KB)
SD Version  : S110 8.0.0
Device Addr : C1:99:FC:D9:8A:D1
Device ID   : ****************

Note: Make sure the JLink device and board are connected and powered before running the command!

Common Problems

Windows Path Errors

If you get an error on Windows trying to run adalink (ex. adalink nRF51822 --info), you likely need to add the Python Scripts folder (ex C:\PythonXX\Scripts) to your system path so that Windows knows where to find the adalink.exe file generated by setup.py.

The exact path is displayed in the output when running setup.py, for example:

Installing adalink-script.py script to C:\Python27\Scripts
Installing adalink.exe script to C:\Python27\Scripts

If it isn't already present, you may also need to add the J-Link binary folder to your system path so that adalink can run JLink.exe, which is used to communicate with the J-Link via generated script files.

Depending on the version of the J-Link drivers you installed, the folder to add to your system path should resemble the following:

C:\Program Files (x86)\SEGGER\JLink_V494f

Can't find CPU core when using STLink programmer on Windows

If you receive an error that adalink can't find the desired CPU core when using an STLink programmer on Windows you might not have the programmer setup with libusb correctly. Follow the steps in the OpenOCD Windows install section above to use Zadig tool to install a libusb driver for the STLink device.

Extending AdaLink

adalink is built with a modular structure in mind and can be extended to support new CPUs and programmer types without much effort.

Adding new CPU cores

Look in the adalink/core.py file to see the abstract base class that each core needs to inherit from and implement. Each core implementation should be inside the adalink/cores folder and the core should be imported explicitly inside the adalink/cores/init.py file.

Each core needs to at a minimum implement these functions:

  • list_programmers - This function should return a list of strings that define the available programmers for the core.

  • create_programmer - This function will be called with the chosen programmer type (a string provided by list_programmers) and expects a programmer instance to be created and returned. For example if a user chooses the jlink programmer option then create_programmer is called with 'jlink' as the parameter and the function should return a programmer instance that uses the JLink to program the core.

  • info - This function is called if the user runs the --info option. The selected programmer instance is passed to the function and it can be used to read parts of the core memory and display them. It is entirely up to each core to choose what information it reads and displays with the info function. The default info implementation will do nothing.

The logic to program and wipe the memory of a core is defined by the core's programmers. There are generic JLink and STLink programmer implementations available and they can be subclassed by a core to provide a custom programmer that performs core-specific commands to program or wipe a core. See the nRF51822 core for an example of building a STLink-specific core to program and wipe the nRF51822.

Adding new Programmers

Look in the adalink/programmers/base.py file to see the abstract base class that a programmer needs to implement. You can also see the provided concrete programmer implementations in the adalink/programmers directory, like jlink.py and stlink.py.

Each programmer needs to implement the following functions:

  • is_connected - This returns True if the programmers is connected to a CPU and False if not connected.

  • program - This function takes a list of hex file paths and will program them to the CPU.

  • wipe - This function will wipe the flash memory of the CPU.

  • readmem32, readmem16, readmem8 - This function takes an address and returns the 32, 16, or 8 bit value at that address.

To add support for a programmer to a core make sure the core's list_programmers function returns a string that identifies the programmer, and the core's create_programmer function builds an instance of that programmer when requested.

Producing Binary releases

To build a standalone binary release for Windows, OSX, etc. you can use the PyInstaller tool. This tool will package up the adalink source into an executable that can run without python or other dependencies being installed.

To produce the binary first install PyInstaller (typically using pip). Then download this source repository for adalink, open a terminal, navigate to the root of the source and run:

pyinstaller --onefile adalink.py

This will point PyInstaller at simple adalink bootstrap script which helps it find all the dependencies and package up a standalone executable. When PyInstaller finishes it will output the executable in the dist directory.

More Repositories

1

Adafruit_NeoPixel

Arduino library for controlling single-wire LED pixels (NeoPixel, WS2812, etc.)
C++
2,862
star
2

Adafruit-GFX-Library

Adafruit GFX graphics core Arduino library, this is the 'core' class that all our other graphics libraries derive from
C
2,111
star
3

DHT-sensor-library

Arduino library for DHT11, DHT22, etc Temperature & Humidity Sensors
C++
1,835
star
4

Fritzing-Library

Adafruit parts, components, breakouts, etc...in Fritzable format!
1,605
star
5

Adafruit_SSD1306

Arduino library for SSD1306 monochrome 128x64 and 128x32 OLEDs
C++
1,587
star
6

Adafruit-Raspberry-Pi-Python-Code

Adafruit library code for Raspberry Pi
1,414
star
7

Adafruit_Python_DHT

Python library to read the DHT series of humidity and temperature sensors on a Raspberry Pi or Beaglebone Black.
C
1,091
star
8

Adafruit-Eagle-Library

Slowly building up a collection of parts we use here ... This file includes some library parts from microbuilder.eu Most of 'em are either Eagle parts that I've changed a little to make them easier to solder, some are 'handmade' and a few are from microbuilder.eu Its released into the Public Domain - that means you can do whatever you want. We'd like it if you kept the author email/url in the part description, just so we can be alerted if there are errors. Enjoy!
1,005
star
9

Adafruit_Learning_System_Guides

Programs and scripts to display "inline" in Adafruit Learning System guides
C
952
star
10

Adafruit_Sensor

Common sensor library
C++
887
star
11

Adafruit-Pi-Finder

Find and set up your brand new Raspberry Pi
JavaScript
844
star
12

Adafruit_CAD_Parts

CAD files for various boards, components and parts
SMT
829
star
13

RTClib

A fork of Jeelab's fantastic RTC Arduino library
C++
760
star
14

Adafruit_CircuitPython_Bundle

A bundle of useful CircuitPython libraries ready to use from the filesystem.
Shell
737
star
15

awesome-circuitpython

A curated list of awesome CircuitPython guides, videos, libraries, frameworks, software and resources.
593
star
16

Adafruit_nRF52_Arduino

Adafruit code for the Nordic nRF52 BLE SoC on Arduino
C
588
star
17

Adafruit_MQTT_Library

Arduino library for MQTT support
C++
541
star
18

Adafruit_Python_SSD1306

Python library to use SSD1306-based 128x64 or 128x32 pixel OLED displays with a Raspberry Pi or Beaglebone Black.
Python
519
star
19

Adafruit-ST7735-Library

This is a library for the Adafruit 1.8" SPI display http://www.adafruit.com/products/358 and http://www.adafruit.com/products/618
C++
495
star
20

Adafruit-WebIDE

This is a simple editor to be used on the Raspberry Pi (or anywhere?).
JavaScript
474
star
21

adafruit-beaglebone-io-python

Adafruit's BeagleBone IO Python Library
C
465
star
22

Adafruit_GPS

An interrupt-based GPS Arduino library for no-parsing-required use
C++
450
star
23

pi_video_looper

Application to turn your Raspberry Pi into a dedicated looping video playback device, good for art installations, information displays, or just playing cat videos all day.
Python
438
star
24

Adafruit-PWM-Servo-Driver-Library

Adafruit PWM Servo Driver Library
C++
436
star
25

Adafruit_TinyUSB_Arduino

Arduino library for TinyUSB
C
432
star
26

Adafruit-PN532

Arduino library for SPI and I2C access to the PN532 RFID/Near Field Communication chip
C++
397
star
27

Adafruit_nRF52_Bootloader

USB-enabled bootloaders for the nRF52 BLE SoC chips
C
394
star
28

Adafruit_Python_GPIO

DEPRECATED! Please use Adafruit Blinka instead (was: Library to provide a cross-platform GPIO interface on the Raspberry Pi and Beaglebone Black using the RPi.GPIO and Adafruit_BBIO libraries.)
Python
393
star
29

Adafruit_Python_BluefruitLE

Python library to simplify access to Bluetooth low energy devices and services on Linux (using bluez) and Mac OSX.
Python
390
star
30

Adafruit-PCD8544-Nokia-5110-LCD-library

Arduino driver for PC8544, most commonly found in small Nokia 5110's
C++
385
star
31

Adafruit_Blinka

Add CircuitPython hardware API and libraries to MicroPython & CPython devices
Python
384
star
32

Adafruit-Fingerprint-Sensor-Library

Arduino library for interfacing to the fingerprint sensor in the Adafruit shop
C++
364
star
33

Adafruit_ILI9341

Library for Adafruit ILI9341 displays
C++
357
star
34

Adafruit_CircuitPython_HID

USB Human Interface Device drivers.
Python
355
star
35

Adafruit-Retrogame

Raspberry Pi GPIO-to-virtual-keyboard utility for classic game emulators
C
348
star
36

Raspberry-Pi-Installer-Scripts

Shell
348
star
37

Adafruit-Motor-Shield-library

Adafruit Motor shield V1 firmware with basic Microstepping support. Works with all Arduinos and the Mega
C++
329
star
38

Adafruit-MCP23017-Arduino-Library

Arduino Library for Adafruit MCP23017
C++
322
star
39

Adafruit_BME280_Library

Arduino Library for BME280 sensors
C++
312
star
40

Adafruit_BNO055

Unified sensor driver for the Adafruit BNO055 orientation sensor breakout
C++
308
star
41

TFTLCD-Library

Arduino library for 8-bit TFT LCDs such as ILI9325, ILI9328, etc
C
301
star
42

Adafruit-Thermal-Printer-Library

Arduino Library for Small Thermal Printers
C++
300
star
43

Reference-Cards

Business card-sized references for Arduino and basic electronics
294
star
44

Adafruit_LED_Backpack

Adafruit LED Backpack Library for our various LED backpacks.
C++
286
star
45

Adafruit_CircuitPython_NeoPixel

CircuitPython drivers for neopixels.
Python
277
star
46

RGB-matrix-Panel

Arduino library and example code for the 16x32 RGB matrix panels in the shop
C++
275
star
47

Adafruit_CC3000_Library

Library code for Adafruit's CC3000 WiFi breakouts &c
C++
270
star
48

Adafruit_ADS1X15

Driver for TI's ADS1015: 12-bit Differential or Single-Ended ADC with PGA and Comparator
C++
268
star
49

Adafruit_Python_PCA9685

Python code to use the PCA9685 PWM servo/LED controller with a Raspberry Pi or BeagleBone black.
Python
258
star
50

Adafruit_TouchScreen

Arduino library for 4-wire resistive touchscreens
C++
251
star
51

Adafruit_CircuitPython_SSD1306

Adafruit CircuitPython framebuf driver for SSD1306 or SSD1305 OLED displays. Not for use with displayio. See README.
Python
249
star
52

Adafruit_BMP280_Library

Arduino Library for BMP280 sensors
C++
230
star
53

Adafruit-BMP085-Library

A powerful but easy to use BMP085/BMP180 Arduino library
C++
223
star
54

Adafruit_SleepyDog

Arduino library to use the watchdog timer for system reset and low power sleep.
C++
218
star
55

Python-Thermal-Printer

Python
213
star
56

Adafruit_IO_Python

Adafruit IO Python Client Library
Python
213
star
57

LPD8806

Arduino library for LED strips and pixels using LPD8806 (and probably LPD8803/LPD8809)
C++
210
star
58

Adalight

Processing
210
star
59

Adafruit_Python_CharLCD

Python library for accessing Adafruit character LCDs from a Raspberry Pi or BeagleBone Black.
Python
208
star
60

Adafruit_BusIO

Arduino library for I2C & SPI abstractions
C++
206
star
61

Adafruit_FONA

Arduino library for the Adafruit FONA
C++
206
star
62

Adafruit-Trinket-USB

Arduino libraries allowing Trinket to act as USB devices
C
205
star
63

Bluefruit_LE_Connect

iOS app for use with Bluefruit Bluetooth LE breakout board
Swift
203
star
64

TinyWireM

I2C library for Trinket and Gemma, adapted from BroHogan's code on Arduino Playground
C++
196
star
65

Adafruit_Floppy

C++
193
star
66

Adafruit_BluefruitLE_nRF51

Arduino library for nRF51822-based Adafruit Bluefruit LE modules
C++
190
star
67

Adafruit_IO_Arduino

Arduino library to access Adafruit IO from WiFi, cellular, and ethernet modules.
C++
188
star
68

Adafruit-WS2801-Library

Arduino library for controlling strips/pixels using WS2801 driver chips
C++
185
star
69

Adafruit_INA219

INA219 Current Sensor
C++
181
star
70

Adafruit_AHRS

Arduino library for AHRS (Attitude and Heading Reference System) for Adafruit motion sensors
C++
175
star
71

Adafruit_Motor_Shield_V2_Library

Arduino library for Adafruit Motor Shield v2!
C++
171
star
72

AccelStepper

A small fork of AccelStepper v1.3 with AF_motor (Adafruit motor shield) support!
C++
167
star
73

Adafruit_NeoMatrix

Adafruit_GFX-compatible library for NeoPixel grids
C++
167
star
74

SD

fixes & updates to the Arduino SD library - totally in progress. works but in beta
C++
166
star
75

Adafruit_ESP8266

Example code for ESP8266 chipset
C++
165
star
76

RadioHead

A github'ified version of http://www.airspayce.com/mikem/arduino/RadioHead/
C++
164
star
77

Adafruit_CircuitPlayground

library for Circuit Playground board
C++
159
star
78

Raw-IR-decoder-for-Arduino

Take raw IR signal from a remote receiver and print out pulse lengths
C++
158
star
79

Bluefruit_LE_Connect_v2

iOS app for use with Bluefruit Bluetooth LE modules and dev boards from Adafruit (v2.0)
Swift
152
star
80

circuitpython-org

CircuitPython's website
HTML
141
star
81

MAX6675-library

Arduino library for interfacing with MAX6675 thermocouple amplifier
C++
136
star
82

CircuitPython_Community_Bundle

A bundle of useful CircuitPython libraries from the CircuitPython community.
Shell
134
star
83

Adafruit_TCS34725

Arduino library driver for Adafruit's TCS34725 RGB Color Sensor Breakout
C++
133
star
84

Adafruit-VC0706-Serial-Camera-Library

Library for VC0706-based Serial JPEG Cameras
C++
132
star
85

adafruit-bluefruit-le-desktop

Desktop application to interact with Bluefruit LE and other Bluetooth low energy devices on Mac OSX, Windows, and Linux.
JavaScript
131
star
86

Adafruit_VL53L0X

Arduino library for Adafruit VL53L0X
C++
131
star
87

Adafruit_NFCShield_I2C

I2C Driver for Adafruit's PN532-based NFC Shield
C++
128
star
88

awesome-feather

A curated list of awesome Feather form factor boards, guides, videos, libraries, software and resources.
127
star
89

Adafruit_CircuitPython_ADS1x15

CircuitPython drivers for the ADS1x15 series of ADCs.
Python
127
star
90

Adafruit_VS1053_Library

This is a Arduino library for the Adafruit VS1053 Codec Breakout and Music Maker Shields
C++
124
star
91

Adafruit_SPIFlash

Arduino library for external (Q)SPI flash device
C++
124
star
92

FreqShow

Raspberry Pi & PiTFT-based RTL-SDR frequency scanning and display tool.
Python
123
star
93

FifteenStep

A general purpose Arduino MIDI sequencer library
C++
121
star
94

TV-B-Gone-kit

*Pew* *Pew* TV's are toast!
C
120
star
95

Adafruit-MLX90614-Library

Arduino library for the MLX90614 sensors in the Adafruit shop
C++
117
star
96

Bluefruit_LE_Connect_Android

Android port of Adafruit's Bluefruit LE Connect app
Java
117
star
97

Adafruit_Python_BME280

Python Driver for the Adafruit BME280 Breakout
Python
116
star
98

Adafruit_CircuitPython_BLE

Bluetooth Low Energy (BLE) library for CircuitPython
Python
116
star
99

Adafruit_Python_ADS1x15

Python code to use the ADS1015 and ADS1115 analog to digital converters with a Raspberry Pi or BeagleBone black.
Python
114
star
100

circup

CircuitPython library updater.
Python
112
star