JTAG/cJTAG/SWD on teensy and achitecture

Status
Not open for further replies.

summers

Active member
Hi,

Just building a system with teensy 3.2/pressure sensor (MS5611) and SD card - to fit inside a Kinder Egg, and fly on MarsBalloon (http://marsballoon.com/). Its where we give school children a chance to fly experiments on a weather balloon, with the constraint that the experiment needs to fit in a kinder egg ...

Anyway I developing code on mbed - as I'm familiar with that set up, have a few hassles bringing up a UART across the usb interface for debugging. That was when I noticed that the teensy wires up the usb device different from many mbed devices. Often there like teensy boards have two arm cpus on, one the target, and one for programming. My other freedom card has a target UART connected to the programming cpu, and that cpu runs the code that puts the uart in a usb-otg gadget.

Now on teensy, the usb d+ and d- go straight into the target cpu (m4), indeed the programming cpu (m0) the only input it has into it seems to be the reset button. So how does it program the m4?

Next clue, the M0 is wired into pins PTA0-3 on the M4, these are the M4 jtag/cjtag/swd pins. So it looks like all the m0 can do to program the m4, is write a program direct to the M4 RAM. That program brings up halfkey on the USB, and writes it to flash. The crux being that it must run on the M4.

Whats interesting is that the M0 is doing this via the debug pins. on the M4. So I got to wondering - can a more general JTAG/cJTAG/SWD interface be brought up via the M0?

Of course the problem is there is no way to communicate with the M0, or is there? One strange bit of the teensy 3.2 schematic (that isn't done on the 3.6) is that the USB id pin goes to one of the lines between the M0 and M4. Now usually with micro-B usb plugs, the id pin is left floating. But if a micro-A plug is used, the id pin gets earthed. Now for the M4, this probably means that it can't be programmed any more - e.g. not enough of the jtag comes up. What isn't clear to me though is what happens to the M0 when PTA6 is pulled to Earth? E.g. does this give extra functionality, e.g. the ability for the M4 to rewrite the M0 flash? If thats possible, then maybe some jtag code could be got on the M0? Alas I don't have a micro-A plug, so can't try this ...

So has anyone else been down this line? Its only possible because of the interesting teensy architecture, and the relation of the M0 to the M4. Any thoughts anyone?
 
That is really cool to get to make something that small to launch! Do they provide power - or does that have to be in the egg too?

Indeed the M0 holds the PJRC 'Magic Sauce' - and it can be updated by PJRC. The USB indeed uses M4 hardware for direct and configurable support for multiple USB interfaces - unlike those with off chip or lesser CPU's that present a single interface. And that USB/M0 interface is the only PJRC supported way to program the Teensy.

If you insist ... some web searching can find you ways to cut/splice/solder the T_3.2 for JTAG support cutting the M0 out of the loop. But the most helpful PJRC forum support is generally geared to Arduino 'kool-aid' drinkers - because PJRC makes it taste good and cost less, and allows Arduino IDE/toolset to provide very robust control of the entire capabilities of the Atypically awesome ( for Arduino ) 32 bit ARM hardware that Teensy 3++/LC board holds.

<edit>: I should have added that SparkFun or Adafruit may have suitable hardware and sample sketches that would provide a more Kid friendly Arduino interface to Teensy without having to re-engineer it.
 
In the past we have offered to do logging of some analogue voltages for the kids. I can't remember if we offered them power as well - I know that most that needed power had batteries inside the egg.

For my pressure sensor, I'll aim to have 3 1.5V batteries. The most likely option is that 9V batteries are made up of 6 batteries internally. The kind that have 6 vertical batteries look best split into two sets of three. The 9V internals are slightly smaller than AAAA batteries, and 9V batteries are easier to find than AAAA. Another hassle is the batteries need to work at something like -20celius - and many don't (e.g. think lipo has problems).

Yes I noticed most people access the teensy via arduino IDE; me I come from an mbed background - and one thing that is good with MBED OS is that much is programmed directly by arm, and they do code that follows standards. This means code is reliable. [This said though, I can't find the infrastrucre to bring up USB properly in mbed - and just the basic structure described in the K20 Reference Manual is quite onerous).

Ah - so JTAG access needs lifting pins or something - that was what I was half expecting. Its not a direction I'll go in, as too much hassle - and I want this teensy focused on going into a kinder egg. Lifting pins and it gets a mess - and JTAG via the FTDI cable is a hassle anyway ...

Really just looking at easiest logging I can do whist developing code, easiest seems to be to wire a 3.3 FTDA usb-uart cable to the teensy. I'll try and get that working this afternoon ...
 
Couldn't sleep last night, so checked the M0 pin out - to see how its programmed. Before was looking for the JTAG interface, but looks like this arm just has a SWD debug interface. This comes out on PTA0 and PTA2. SWD makes sense, it only 2 wire, whereas jtag is 4. When you only have 16 pins on the arm, don't want to use too many for debugging. Anyway back to the teensy 3.2 schematic, and those two pins are shown as going to pads, but not connected.

So looking at the picture of the teensy, looks like those pins go through the board on vias. They terminate on the pads on the back of the teensy just above pin 1 and 2. This means that the m0 could be reprogrammed, but only using an external connection; so there is no way to do this from the M4.

Practically this isn't really worth doing, the only pins that are attached to the M0, are 4 for the jtag on the M4, then reset, the button and power. The M0 may only have 16 pins, but only half of them are used. This means its only really useful for the one function it was designed for, that is getting the M4 to run halfkey.

Its interesting to compare to my frdm-kl25z board, that also has two arm cpu on board, one the target, and the other used for programming. But on the frdm board, the two cpus are fairly similar; both KL25Z cpu IIRC. The target cput has more pins than the programming cpu; but otherwise both have similar functionally. e.g. the programming cpu has the USB interface, and thats whats used to program the board.

Now the teensy 3.2 is very different, also two cpu; but one big target M4 with huge amounts of functionality; where as the programming M0 only has a i2c, uart and few pins. My guess is other than the logic to toggle the M4 jtag pins, most of the M4 flash is just used to store the halfkey program that is transferred to the M4. Does make it an interesting design ...
 
In the past we have offered to do logging of some analogue voltages for the kids. I can't remember if we offered them power as well - I know that most that needed power had batteries inside the egg.

For my pressure sensor, I'll aim to have 3 1.5V batteries. The most likely option is that 9V batteries are made up of 6 batteries internally. The kind that have 6 vertical batteries look best split into two sets of three. The 9V internals are slightly smaller than AAAA batteries, and 9V batteries are easier to find than AAAA. Another hassle is the batteries need to work at something like -20celius - and many don't (e.g. think lipo has problems).

Yes I noticed most people access the teensy via arduino IDE; me I come from an mbed background - and one thing that is good with MBED OS is that much is programmed directly by arm, and they do code that follows standards. This means code is reliable. [This said though, I can't find the infrastrucre to bring up USB properly in mbed - and just the basic structure described in the K20 Reference Manual is quite onerous).

...

-20 is cold - interesting.

Teesny code as reliable as years of use and testing can provide - uses a standard toolchain - and everything is generally by the book if PJRC includes it.

You hit on a BIG point Paul has made note of - getting USB running. That was no small ... and perhaps more of a herculean task.

For what you want to do an afternoon learning the Arduino IDE : Install - find sample - adjust should get you most of the way for using a supported device. If you get stuck perhaps a kid can help you :) I played with mbed one day with a Kickstarter mDuino? - it is much more limiting and cryptic to my hands and the support here comes in handy, especially for Teensy Specific devices than have most everything on the T_3.2 fleshed out and working.
 
Agreed, you really ought to give Arduino+Teensyduino a try. If you prefer using some other program to edit the code, Arduino has an "external editor" feature in File > Preferences.

And yeah, writing a good USB stack is a lot of work, especially crafting one that performs well when user code has a lot of latency due to other libraries.
 
Thanks both.

Yes the concept behind MarsBalloon, is that one a weather balloon conditions are much like Mars. So Thin atmosphere, and cold, also UV is higher. Its why its a good one for school children to think of, as to how it makes things different. Few children actually go the electronics direction, which is probably good - there are to many things that can go wrong with electronics. If there is space on the balloon, usually staff fly some eggs - and that when the electronics and things come in. With children, the best are though that think about how to exploit the conditions on a balloon. E.g. something that reacts to the higher UV, or the lower pressure. So a good example is a marshmallow in an egg - when taken to low pressure, they expand to many times their normal size - and that clear when they come back down again.

Yes on the USB interface, I'll take a look at ardunino, as well as mbed. It would be good to compare the two. Turns out that there was a USB interface in an older version of mbed, back at version 2 or so; but now that they are on version 5 - and it isn't included. Seems a bit surprising, but yes I guess it make just be a hassle getting the stack correct.

Latancy problems? Hmmm does this mean we can't multithread? I know M4 don't have MMU, which makes multithread a bit of a hassle. Maybe problems with regular interupts needed when threading?

Must admit I'm still trying to get on top of the various bits of hardware in the M4, and how best to use whats available. The USBserail is just for debugging, so its a nice to have - but won't be needed in the field. This said though is far easier to develop code, if the code can tell you whats its doing. Debugging code via a single flashing led is never fun ;)
 
I actually reviewed a project (in the late 1990s) that had been designed this way. It literally blinked Morse code with a single LED. Apparently he developer was an old HAM guy fluent in Morse code. Fortunately I was able to decline getting involved in that one.

Needless to say, it was all built around a PIC chip...
 
My old Volvo 850 station wagon from 1994 had a similar (pre-ODB) diagnose system for ecu, automatic gearbox, and abs. There was a box which allowed you to put a plug in one of the holes to select the control unit you wanted to check, then to press a button for 1s in order to see the LED blinking the error code sequence : "blink - pause -blink - pause - blink - off" (1-1-1) meant that everything was ok.
 
Ah! people that work in the embedded world!

Although I've written code that has to run right first time, I don't enjoy it - its FAR too much effort, and actually makes it harder to do subtle code.

Paul, is the source of your USB library available? I found the compiled library. (OK if it isn't, I understand your position!).

For the moment, I'm using a UART on the teensy - but as its a non permanent part of the design, I just have wires looped through the pcb holes, that go off to pins on my FTDI adaptor. This works, but loose wires aren't the best connection ...
 
Status
Not open for further replies.
Back
Top