Author Topic: AVR/Arduino Hardware Debugger on the Cheap  (Read 6281 times)

0 Members and 1 Guest are viewing this topic.

Offline wholderTopic starter

  • Regular Contributor
  • *
  • Posts: 72
  • Country: us
    • Wayne's Tinkering Page
AVR/Arduino Hardware Debugger on the Cheap
« on: February 01, 2018, 09:32:28 pm »
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 at https://sites.google.com/site/wayneholder/debugwire and/or watch a short demo video at https://youtu.be/kI_Z78a_0y0

Wayne
 
The following users thanked this post: jimmc, thm_w, ez24

Offline ez24

  • Super Contributor
  • ***
  • Posts: 3082
  • Country: us
  • L.D.A.
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #1 on: February 01, 2018, 10:27:16 pm »
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..

 :-+
YouTube and Website Electronic Resources ------>  https://www.eevblog.com/forum/other-blog-specific/a/msg1341166/#msg1341166
 

Offline wholderTopic starter

  • Regular Contributor
  • *
  • Posts: 72
  • Country: us
    • Wayne's Tinkering Page
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #2 on: February 01, 2018, 10:55:54 pm »
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.
 

Offline phil from seattle

  • Super Contributor
  • ***
  • Posts: 1038
  • Country: us
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #3 on: February 02, 2018, 10:08:05 pm »
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.
 

Offline wholderTopic starter

  • Regular Contributor
  • *
  • Posts: 72
  • Country: us
    • Wayne's Tinkering Page
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #4 on: February 03, 2018, 11:14:51 am »
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
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3040
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #5 on: February 03, 2018, 03:02:30 pm »
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#attiny

I 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.
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3040
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #6 on: February 03, 2018, 03:18:21 pm »
Great work indeed!  Have you looked into  what is necessary to talk to a gdb frontend?
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 
The following users thanked this post: firewalker, wholder

Offline phil from seattle

  • Super Contributor
  • ***
  • Posts: 1038
  • Country: us
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #7 on: February 03, 2018, 05:47:33 pm »
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

UPDI 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.
 

Offline phil from seattle

  • Super Contributor
  • ***
  • Posts: 1038
  • Country: us
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #8 on: February 03, 2018, 05:52:04 pm »
@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.
 

Offline wholderTopic starter

  • Regular Contributor
  • *
  • Posts: 72
  • Country: us
    • Wayne's Tinkering Page
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #9 on: February 03, 2018, 09:23:45 pm »
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 at https://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
 

Offline wholderTopic starter

  • Regular Contributor
  • *
  • Posts: 72
  • Country: us
    • Wayne's Tinkering Page
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #10 on: February 03, 2018, 09:27:24 pm »
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/debugwire

Wayne
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3040
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #11 on: February 05, 2018, 01:04:25 am »

I'm not familiar with a "gdb frontend"

GDB 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 protocol

Some links which maybe will inspire you one day :-)

http://winavr.sourceforge.net/AVR-GDB_and_AVaRICE_Guide.pdf
http://avarice.sourceforge.net/
http://www.avrfreaks.net/forum/tutsoftgcc-avr-debugging-using-gdb-and-avr-dragon-under-linux-ubuntu

The AVR Simulator also is a remote target for gdb
http://www.nongnu.org/simulavr/intro.html

GDB's manual on remote debugging
https://sourceware.org/gdb/current/onlinedocs/gdb/Remote-Debugging.html#Remote-Debugging
« Last Edit: February 05, 2018, 01:06:16 am by sleemanj »
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline wholderTopic starter

  • Regular Contributor
  • *
  • Posts: 72
  • Country: us
    • Wayne's Tinkering Page
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #12 on: February 05, 2018, 01:56:11 am »
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" instruction
void setClrIOBit (byte addr, byte bit, boolean set) {
  // Generate an "sbi/cbi addr,bit" instruction
  byte cmd[] = {0x64, 0xD2, set ? 0x9A : 0x98, ((addr & 0x1F) << 3) + (bit & 0x7), 0x23};  // 1001 10x0 aaaa abbb
  sendCmd(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
 

Offline obiwanjacobi

  • Super Contributor
  • ***
  • Posts: 1013
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #13 on: February 05, 2018, 06:38:51 am »
Hats off Wayne, that is excellent work.  :clap:
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline wholderTopic starter

  • Regular Contributor
  • *
  • Posts: 72
  • Country: us
    • Wayne's Tinkering Page
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #14 on: February 07, 2018, 04:58:11 am »
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)" at https://sites.google.com/site/wayneholder/debugwire2.

Wayne
 

Offline wholderTopic starter

  • Regular Contributor
  • *
  • Posts: 72
  • Country: us
    • Wayne's Tinkering Page
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #15 on: February 13, 2018, 07:29:03 pm »
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/debugwire3
 https://youtu.be/F1202b0l5DA

Wayne
 
The following users thanked this post: Vasi

Offline pma32904

  • Newbie
  • Posts: 2
  • Country: us
Re: AVR/Arduino Hardware Debugger on the Cheap
« Reply #16 on: April 27, 2018, 08:04:16 pm »
Thanks for posting this! I am looking forward to learning as much as I can about debugWire.

Paul
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf