Hacking the Teensy V3.1 for SWD Debugging
Hacking the Teensy V3.1 for SWD Debugging
Join the DZone community and get the full member experience.Join For Free
Digi-Key Electronics’ Internet of Things (IoT) Resource Center Inspires the Future: Read More
I *love* the Freescale Freedom boards, and you probably recognized that with all my projects using them. The Freedom boards are small, inexpensive and can be easily extended with Arduino shields which makes them a great platform for prototyping. But sometimes I just need an ARM microcontroller with some headers, and then the 85mm x 55mm size of the Freedom board is not ideal. That’s nothing new, but I realized that yet again when I did my Adafruit NeoPixel clock: the FRDM board was rather bulky, even if hidden behind that clock. I need something much smaller: the Teensy board!
Meet the Teensy V3.1 Board
I have met the Teensy board the first time when it was featured on Hack-a-Day with the 3.0 and later with the 3.1 version. The Teensy V3.1 board (https://www.pjrc.com/teensy/index.html) is a tiny 35×17 mm board (Hint: the board name tells it all!) with following main features:
- Freescale K20DX256 ARM Cortex-M4 Processor (72 MHz, 256 KByte FLASH, 64 KByte SRAM)
- MINI54TAN Bootloader Device, an ARM Cortex-M0 (see this thread) which acts as USB Bootloader
- Prog Button, connected to the Nuvoton MINI54TAN
- A User LED, connected to the K20
- USB port connected to the K20. The board supports by default USB device class, but can be modified for USB host functionality (I have not tried that yet).
- Pins on outer headers and lower pin pads, bread board friendly
On the backside the board is prepared for a 32 kHz oscillator and USB host mode. Additionally it features added pin pads and various test points:
The schematics are found on https://www.pjrc.com/teensy/schematic.html. The board costs below US$20 and can be ordered from multiple sources (I ordered mine from Adafruit (https://www.adafruit.com/products/1625)).
So far so good. I was very reluctant to order the board because it has a problem: It does *not* expose the JTAG/SWD debug pins :-(. That means, it is not possible to debug the ARM processor on that board with the usual JTAG/SWD debugging tools.
:idea: Maybe it is just me: I respect the ‘Arduino way of programming’, but it is just not the way I think development should be done. I need full control of the hardware which includes deep inspection (debugging) of the application. Because in my experience the hard problems (and there are many!) of embedded development can only be solved with good debugging tools.
Instead, a USB based bootloader is used, the Teensy Loader (https://www.pjrc.com/teensy/loader.html). With that loader programs can be loaded to the board, but it does not allow me to debug the board by any normal means. That topic is discussed in the forums too (see http://forum.pjrc.com/threads/6-JTag-on-Teensy). So the board is open, but not that bootloader on the MINI54TAN device. Not having the JTAG/SWD pins exposed at least on test pads on that great board is definitely a pity.
:idea: I only can speculate that Paul Stoffregen (https://www.pjrc.com/about/about_us.html) want to protect the board IP from beeing cloned, which I can understand. But why not at least expose testing pads for JTAG/SWD?
Adding SWD Debugging
:!: WARNING: of course, any change of the Teensy board like this will void any warranty!
Looking at the schematics and the board layout under the microscope, it was clear that it would be possible to add SWD debug functionality to it. As SWD only needs 5 pins (GND, 3.3V (power sense), DIO, CLK and Reset, it should not be too hard to route it to a standard 10 pin SWD/JTAG header:
So I checked the schematics (https://www.pjrc.com/teensy/schematic.html), and all the signals are available, and SWD_CLK is on PTA0, and SWD_DIO is on PTA3:
:idea: To keep things simple, I only used the SWD pins, and not the two additional ones for JTAG (PTA1_JTAG-TDI and PTA2_JTAG-TDO), but that would be certainly doable with two extra wires.
Teensy v3.1 Schematic with SWD Pins (Source: based on https://www.pjrc.com/teensy/schematic.html)
:idea: Interestingly, the USB DP and DM pins are *not* connected to the MINI54TAN device, but it manages the bootloading to the K20 through USB? I belive upon press of the ‘Prog’ button, the MINI54TAN programs a small USB bootloader program to the K20 which then runs the update? Would be an interesting approach just to use a single USB connector.
- 3.3V andGND are easily available on the back side oftheTeensy:
- For SWD_CLK and SWD_DIO there are no easy accessible pads. But an inspection of the layout of the board suggested to cut the traces to the MINI54TAN and solder wires directly to the K20 pads.
:idea: The idea to remove the MINI54TAN and to use its pads has been considered. But then this would be a non-revertible change (or at least not easy). So cut two traces and wire some wires sounds the better approach. Maybe cutting is not necessary, but I did to isolate it just in case.
With this, wires get soldered on the microcontroller K20 pads (use soldering flux and head the pin with a wire wrap wire):
Then cut the traces to the MINI54TAN:
Compared to the previous step, the 3.3V, GND and Reset wires on the backside of the board are easy:
Next step is to connect the wires to the normal 2×5 pin SWD/JTAG pin header (or an adapter to it). I had a header with cable at hand, I decided to solder the wires to header.
:idea: The pin pitch is rather small. Next time I better create a small adapter PCB which would make soldering easier.
With this, I was able to debug the Teensy V3.1 with a normal JTAG/SWD hardware debugging tool, and within minutes I had a Processor Expert blinking LED program made with Eclipse plus GNU ARM tool chain running on the Teensy:
Now with this that board is finally useful for me: I can debug with my favorite Eclipse tools :-).
The Teensy V3.1 is a fabulous board, with a processor I love: an ARM Cortex-M4 powerful for most of my projects. The board is tiny and small. The bad thing is that the usual JTAG/SWD pins are not available either on the outside or on test pads, making JTAG/SWD debugging not possible by default. But with some hacking and good soldering skills, a Teensy board can be turned into a board which talks with a JTAG/SWD cable like a P&E Multilink or Segger J-Link. And then the board can be utilized with an IDE like CodeWarrior, Kinetis Design Studio or a DIY Eclipse ARM Toolchain :-).
:idea: My wish is that future Teensy boards have at least the footprint of a standard 2×5 JTAG/SWD header on it, with some isolation traces. That way I can solder a header, cut a few traces and I have a board I can debug with the tools I’m used to. And if I have an extra wish: Replace the MINI54TAN with a Kinetis K20 running OpenSDAv2.1 as on the Freedom boards, and the Teensy would be the perfect board for me: a small and tiny open source board with an open source bootloader and firmware :-)
Time to use that board now for my projects….
Published at DZone with permission of Erich Styger , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.