Debugging device for Arduino?

Compared with previous microcontroller software design I've worked with, I find it a bit restricting that there's no 'proper' debugging available for the Arduino devices (or is there?).

Using 'serial.print' is pretty much all there is. No single-stepping, into/out of functions, inspecting of variables without recompling, etc. I'm aware that by using something like VisualMicro things improve a little (no need for 'serial.print' for example) but it's still very limited.

Before Arduino I worked with a Texas chip series (CC25xx) which are low-cost, based on an 8051. You can also by a 'CC Debugger' which (when controlled by suitable PC software) enables you to single-step, inspect variables, etc etc, without recompling and uploading new code each time. The debugger module itself seems to consist of not much more than an additional 8051-derived device and some level shifters. It has a 10-core ribbon cable to the target board, and a USB connection to a PC. It only costs about $50.

So, I'm just thinking it should be possible to design something similar for Arduino. Has anyone tried doing this, I wonder? I realise it's a lot of work and the market may be small (I appreciate there would need to be slightly different variants for the different Arduino processors), but could be a good hobby project for someone!

Sounds great. How does the single-stepping and variable examination work?

AWOL: How does the single-stepping and variable examination work?

Ha! That's the $64m question. I doubt Texas will divulge their secrets. Hardware-wise, Nick Gammon's debug device would be a good start, although I suspect more than one SPI or i2c connection will be required. I'll have a bit more of a think about it. You can read more about the general principle here and a description of a similar system for PICs is here

Nick's approach is neat, but is really just a riff on serial prints.

I'll have a bit more of a think about it.

Maybe AVR/Microchip already have. That may be worth some research.

Yes, they have.

Just found the 'Dragon' which looks as if it would work fine with a mega256, but not with a UNO. (The connection is made through four pins TCK,TDS, TDO and TDI which are available on the 256 (shared with ADC4-7) but not on the UNO. Although the list of supported processors for the Dragon includes a 328P, I don't see how it would be connected.

It's only £40 ($50), I may order one to play with but it's not in stock until end of March.

Well quilkin, I think that would be a good hobby for you to share with us. ;) Single stepping and watch points would be interesting.

However, I don't see the need for this in this environment. One can do a lot with: SPI, print, toggling an output and a scope or logic analyzer.

.

In circuit debugging of the Atmega328p (as used on the Arduino Uno) is supported by Dragon via Atmel's "DebugWire" protocol. This involves burning a fuse that re-purposes the reset pin as debug control. Debugging in this manner is supported by Atmel Studio. This takes one outside of the "Arduino Ecosystem" which is fine if one wants to go there, but it's not really novice friendly territory.

  • think twice about getting a dragon. They're pretty obsolete. the "current" debugger of choice is the Atmel ICE. A less-featured version (fewer cables) used to sell for about the same price as the dragon, but Microchip raised prices significantly when they took over. There was a sale recently (might still be going on.) http://forum.arduino.cc/index.php?topic=91399.msg3124548#msg3124548
  • It WOULD connect to an ATmega328 via the "DebugWire" protocol, which runs over the RESET signal. Unfortunately, the Arduino auto-reset circuitry interferes with this, so you'd have to modify your uno board to use debugwire.
  • The debugwire protocol commands themselves (as well as the commands you send over JTAG on the bigger chip) have been kept proprietary by Atmel. No one knows why. but that means that only Atmel can build debuggers.
  • There's been some reverse engineering. It looks like single stepping is sort-of the default mode of debugging with DW. Setting registers is done via a sequence like "put a "IN r1,debugwirereg" instruction on the instruction bus, put your value in the debugwirereg "other side", and let the instruction execute."

The VisualMicro people claim to have implemented a useful debugger that communicates over the serial port (rather like the "gdb stubs" used on many larger embedded systems.) I haven't used it, and can't comment. You can also buy an "Atmega328p Xplained Mini" development board from Atmel (which is pretty cheap.) It's almost equivalent to and compatible with an Arduino, but includes a debug chip, and can be used with Atmel Studio to debug things, probably including Arduino sketches (which can be imported.)

LarryD: Well quilkin, I think that would be a good hobby for you to share with us. ;) Single stepping and watch points would be interesting.

However, I don't see the need for this in this environment. One can do a lot with: SPI, print, toggling an output and a scope or logic analyzer.

There's no real need, no. But for anyone who starts their 'micro' life with ardunio, and goes on to get employed with micros, this is the type of device they'd be working with. It's just so much faster to debug than the 'older' methods. If you'd used one you'd know what I mean, and you wouldn't want to go back.

When I started with micros I had to write in assembler; there was no SPI or print output. All I had was scope & analyser. The rest was blind trial-and-error.

westfw:
think twice about getting a dragon. They’re pretty obsolete. the “current” debugger of choice is the Atmel ICE.

Thanks for that, I hadn’t found the ICE for some reason. It’s about £105 (after £50 off) but again no delivery for a month or so. Will you be using yours for Arduino? I’d be interested to see how you get on.

MrMark: In circuit debugging of the Atmega328p (as used on the Arduino Uno) is supported by Dragon via Atmel's "DebugWire" protocol. This involves burning a fuse that re-purposes the reset pin as debug control. Debugging in this manner is supported by Atmel Studio. This takes one outside of the "Arduino Ecosystem" which is fine if one wants to go there, but it's not really novice friendly territory.

OK, thanks, I can see that now. I agree, having to burn internal fuses would make it unsuitable. Any debug system designed for general Arduino use would have to work seamlessly with a Uno.