Recently I killed on of SigFox Td1208 device by misprogramming it, destroying the bootloader. In a such situation serial port is not anymore accessible for programming. The use of JTAG port is a necessity. On the TD1208, jtag has been repaced by SWD which is a 2 wires port doing the same thing.
To use this port, you generally need a specific interface. These interfaces like Jlink are expensive (> 300€), some are less like BusPirate (30€). By the way, if you do not have it, you will have to order and wait for it. That’s why I’ve taken the choice of using my BeagleBone black device GPIO to pilot these signal. This code can easily be port to RaspberryPI…
Then, after trying to build my SWD stack myself and kill that way a lot of energy, I finally found this excellent project doing it in Python (easy to port on any platform) : PySWD
This project is based on BusPirate interface, my work was to rewrite an interface based on GPIO by creating BeagleBoneSWD.py file. The file is accessible from my fork of the project. The link to this fork is here.
Then, to use it, you should start reading the BeagleBone SWD header to get information on pinout, then make some little change in the file you want to use this new interface.
Here is an example to Flash a EFM32 chip:
File : flashFM32.py import time import sys import array from PirateSWD import * from SWDCommon import * from EFM32 import * def loadFile(path): arr = array.array('I') try: arr.fromfile(open(sys.argv, 'rb'), 1024*1024) except EOFError: pass return arr.tolist() def main(): busPirate = PirateSWD("/dev/tty.usbserial-buspirat", vreg = True)
The modification to be made are in red :
File : flashFM32.py import time import sys import array from PirateSWD import * from BeagleBoneSWD import * from SWDCommon import * from EFM32 import * def loadFile(path): arr = array.array('I') try: arr.fromfile(open(sys.argv, 'rb'), 1024*1024) except EOFError: pass return arr.tolist() def main(): busPirate = BeagleBoneSWD("", vreg = True)
Now the SWD interface can be accessed using beagle-bone gpio.
The BeagleBoneSWD.py File : BeagleBoneSWD.py
The execution to flash a device is really long as the use of file system gpio is really long, it has taken about 1 hour and an half to flash my device. In my case it was not a problem as it is the way to rebirth this device, then I’m able to flash it over serial port. By-the-way, the next time, I’ll optimize it by looking at the native python gpio libraries …
To connect the TD1204, TD1208, TD1205, you need to use a such schematic
The second way to pilot the GPIO is to use Adafruit_BBIO lib ; to install this lib get the tgz and execute on BBB
#set the date and time /usr/bin/ntpdate -b -s -u pool.ntp.org #install dependency opkg update && opkg install python-distutils cd adafruit-beaglebone-io-python python setup.py install
Then you can use BeagleBoneNewSWD.tar instead of the previous one. Do not forget to adapt the flashEFM32 file also.
Note that this code is better to be read, but it is not really faster 🙁