Use of BeagleBone GPIO for SWD programming

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…

To start, for those who are curious about SWD protocol here are some good link I used to understand how it works – here & here.

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[1], '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[1], '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 …

 

This entry was posted in Hardware and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>