AVR/Arduino Hardware Debugger on the Cheap - Page 1
Forum section: electronics / general

author: wholder
author_rank: Regular Contributor
timestamp: February 01, 2018, 09:32:28 pm
content: I’ve developed an Arduino sketch that runs on one Arduino and allows it to control and debug another Arduino, or an AVR-Series micro-controller such as an ATTiny85. With some limitations, you can use the controlling Arduino to disassemble code, single step code, inspect and modify the current value of registers. I/O ports and SRAM and run code with a hardware breakpoint set.You can read more about my project athttps://sites.google.com/site/wayneholder/debugwireand/or watch a short demo video athttps://youtu.be/kI_Z78a_0y0Wayne

author: ez24
author_rank: Super Contributor
timestamp: February 01, 2018, 10:27:16 pm
content: I like your videos so I added you to the YT list. If you want me to add your forum name let me know. If you have time, it would be easier on your viewers if you make Playlists. So for now I just put Misc for Content and Info.I suggest you add your YT link to your Forum Profile so it would be easier to find your videos. Now back to watching..

author: wholder
author_rank: Regular Contributor
timestamp: February 01, 2018, 10:55:54 pm
content: Thanks. I've updated my profile to add a link to my web page "Wayne's Tinkering Page" (https://sites.google.com/site/wayneholder/), which is the main place I post. I've only recently started to produce YT videos, but thanks for adding me to the YT list.

author: phil from seattle
author_rank: Super Contributor
timestamp: February 02, 2018, 10:08:05 pm
content: Thanks for doing this. I've been using atmelICE and while it claims to do arduino code, I have yet to be able to get it to work with arduino on an 85.I've recently been playing with the the ATTiny161x series and really like them. Lots of power, flash, ram and modern peripherals. Cheaper than an 85. Been looking at putting arduino on it - doesn't look that hard to come up with the core. I've been looking at how I might write a sketch that does UPDI (follow on to debugwire) to allow inexpensive programming of the 161x series from the IDE. There's enough room to put a bootloader on the 161x though loading via UPDI makes a lot more sense.

author: wholder
author_rank: Regular Contributor
timestamp: February 03, 2018, 11:14:51 am
content: Thanks for the positive feedback. The ATTiny161x series looks interesting, especially with a hardware multiplier. But, it appears to use yet another, "one pin" interface for debugging called the Unified Program and Debug Interface (UPDI). As usual, it's another "proprietary" interface according to the data sheet. However, from the description, it sounds very similar to debugWire, being based on the same type of "UART based half-duplex interface using the RESET pin for data reception and transmission." Perhaps it's just an upgraded version of debugWire and will also yield to analysis.Wayne

author: sleemanj
author_rank: Super Contributor
timestamp: February 03, 2018, 03:02:30 pm
content: Have not finished watching, but, mellis' "core" for the tiny is terrible, do not use that, it's not a core, it;s just definitions to use the standard arduino core which simply does not support tiny chips well, properly, efficiently or completely.Biasedly I recommend my fork of ATTinyCore which is specifically made for the 4/5/9/10/13/x4/x5 tinys, as a proper core, installable from the boards manager, it will produce much better results in all respects.https://github.com/sleemanj/optiboot/blob/master/dists/README.md#attinyI really wish that Mellis would remove that page of his, it maybe served a purpose once, but for too long it has just led people down a wrong path and caused them problems.

author: sleemanj
author_rank: Super Contributor
timestamp: February 03, 2018, 03:18:21 pm
content: Great work indeed! Have you looked into what is necessary to talk to a gdb frontend?

author: phil from seattle
author_rank: Super Contributor
timestamp: February 03, 2018, 05:47:33 pm
content: Quote from: wholder on February 03, 2018, 11:14:51 amUPDI is documented in the datasheets (at least the 161x one section 33) and there is a python implementation that I haven't really looked at. UPDI is really nice and is quite fast. We can bemoan the yet-another-programming-interface disease that the Atmel folks have but this one is pretty good.

author: phil from seattle
author_rank: Super Contributor
timestamp: February 03, 2018, 05:52:04 pm
content: @sleemanj, I agree. I fumbled around with the mellis stuff until I did more searching and found a number of cores. Didn't know about your stuff, though.

author: wholder
author_rank: Regular Contributor
timestamp: February 03, 2018, 09:23:45 pm
content: Thanks for the link to your ATTinyCore page. I'll check it out when I have a chance and look into referencing it in my future articles and videos. I'm happy to see you've added support for the tiny10 series, as I have a special fondness for them having written my own IDE for them a few years back (recently published athttps://github.com/wholder/ATTiny10IDE).I'm not familiar with a "gdb frontend" but I tried to write my debugger in a modular fashion so that others could pick out pieces for use in other projects. While I wrote it as a fairly conventional, command line-style debugger, there are many other ways one could use the core logic. For one, I think a subset of the debugWire commands could be used to implement something like the Arduino IDE's "Serial Monitor" display, but using the debugWire interface for communication. For example, the target chip could use an AVR "break" instruction to get the attention of a controlling host which could then receive and print a message from it before resuming execution on the target. Just having the ability to "print" from a running ATTiny program could make debugging it a lot easier.Wayne

author: wholder
author_rank: Regular Contributor
timestamp: February 03, 2018, 09:27:24 pm
content: BTW, I recently updated the code for both DebugWireDebugger and OnePinSerial in order to improve the automatic baud rate detection and the reliability of debugWire communication using OnePinSerial. Using this new version, I've successfully been able to debug code on an ATTiny85 running at 8 MHz. See:https://sites.google.com/site/wayneholder/debugwireWayne

author: sleemanj
author_rank: Super Contributor
timestamp: February 05, 2018, 01:04:25 am
content: Quote from: wholder on February 03, 2018, 09:23:45 pmGDB is the gnu debugger, of which there is avr-gdb variant, and plenty of guis etc...gdb can talk to external debuggers like yours over serial (or tcp), if they speak the protocolSome links which maybe will inspire you one day :-)http://winavr.sourceforge.net/AVR-GDB_and_AVaRICE_Guide.pdfhttp://avarice.sourceforge.net/http://www.avrfreaks.net/forum/tutsoftgcc-avr-debugging-using-gdb-and-avr-dragon-under-linux-ubuntuThe AVR Simulator also is a remote target for gdbhttp://www.nongnu.org/simulavr/intro.htmlGDB's manual on remote debugginghttps://sourceware.org/gdb/current/onlinedocs/gdb/Remote-Debugging.html#Remote-Debugging

author: wholder
author_rank: Regular Contributor
timestamp: February 05, 2018, 01:56:11 am
content: Thanks for all the information. I'll add it to my possible future projects stack (which is quite large at the moment, so perhaps some pruning is in order.)It's interesting that you mention an AVR Emulator, as I spent quite a bit of time writing one in Java some time back. It was originally intended as a way to simulate and debug code in my ATTiny10IDE project, as there are no hardware debug features on the ATTiny10. However, there are so many special cases to test and verify that I put it on the back burner.But, now that I understand how debugWire works, I think it may be possible to use my debugger code as a way to verify simulated code. One of the key features of debugWire is the ability to send an arbitrary opcode to the target device and execute it. In fact, this is how many of the higher level operations are implemented in my debugger. For example, the command to set and clear bits in I/O registers (IOxx.0=b) is implemented by dynamically generating an "sbi/cbi addr,bit" instruction and then using a special debugWire command to execute it, like this:// Set or clear bit in I/O address 0x00 - 0x1F by generating and executing an "sbi" or "cbi" instructionvoid setClrIOBit (byte addr, byte bit, boolean set) {// Generate an "sbi/cbi addr,bit" instructionbyte cmd[] = {0x64, 0xD2, set ? 0x9A : 0x98, ((addr & 0x1F) << 3) + (bit & 0x7), 0x23}; // 1001 10x0 aaaa abbbsendCmd(cmd, sizeof(cmd));}So, in similar fashion, I could use this feature to "shadow" execute all the same code the emulator processes, read back the state of the target machine after execution and then compare this to the state computed by the emulator. Of course, this still leave another, rather daunting problem, which is to generate test code that will exercise all the possible states that need to be tested.Wayne

author: obiwanjacobi
author_rank: Super Contributor
timestamp: February 05, 2018, 06:38:51 am
content: Hats off Wayne, that is excellent work.

author: wholder
author_rank: Regular Contributor
timestamp: February 07, 2018, 04:58:11 am
content: Thanks.BTW, for anyone following this thread, I've just released a new and improved version of my code that adds the ability to upload code to a target device from the Arduino IDE by integrating code from the ArduinoISP sketch. You can read more in my article "AVR/Arduino Hardware Debugger on the Cheap (revisited)" athttps://sites.google.com/site/wayneholder/debugwire2.Wayne

author: wholder
author_rank: Regular Contributor
timestamp: February 13, 2018, 07:29:03 pm
content: I’ve posted a new, part 3 article on my debugger project, along with new code and an overview video. The new code is now able debug an Arduino UNO running at 16 MHz and also includes some bug fixes and enhancements.https://sites.google.com/site/wayneholder/debugwire3https://youtu.be/F1202b0l5DAWayne

author: pma32904
author_rank: Newbie
timestamp: April 27, 2018, 08:04:16 pm
content: Thanks for posting this! I am looking forward to learning as much as I can about debugWire.Paul