Hacking the Teensy V3.1 for SWD Debugging
Join the DZone community and get the full member experience.
Join For Freei *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 )).
no debug?
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 :-).
summary
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.
Trending
-
Understanding Dependencies...Visually!
-
Microservices With Apache Camel and Quarkus (Part 2)
-
Competing Consumers With Spring Boot and Hazelcast
-
Microservices With Apache Camel and Quarkus (Part 3)
Comments