Low-cost debugger from Xplained kits

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Briefly 

Debugger is powerful tool for embedded programmer. Most of Atmel amateur users lives in Arduino (and programs their aplications thru bootloader) or outside arduino with USBASP (programs applications by ISP). With some exceptions most of them use programmer only and therefore must use hard invasive complicated debug mechanisms like printf, printf to display, led toggling etc. Almost due relative high prices of Atmel Debug tools. Last years Atmel comes with Xplained kits with embedde (mEDBG) debugger, unfortunately it is not full-feature debugger (in contrast with ST and their Nucleo and Discovery kits). I dont know if it is business politics or Atmel has some practical reasons but true is that Xplained kit hide its potential as low-cost debugger. I've done some succeful "hacks" to convert Xplained kits into limited debuggers. I believe there will be amateurs who will want to rebuild the debugger kit. That's why I place a pictorial commentary here. 
 

First i'll show how to hack Xplained Mini (328 or 168) into DebugWIRE debugger, because it have the most potential for arduino users (i've tested debug at UNO and Nano modules). Of course it is not dedicated for Arduino only, most of Attiny's can be debugged that way. Primary limitation of that "home-made" debugger is clock configuration. mEDBG needs to clock target application with its own clock (later i'll discus details). mEDBG generates 16MHz respective 8MHz clock (selected with source voltage 5V respective 3.3V) and its easy connect that clock to target application even if its equipped by crystal oscillator. You simply connect clock to XTAL1 and it simply "beat" crystal. It is possible to clock application by lower frequency then 16 or 8MHz, but it looks there is no way how to clock it by crystal or internal RC oscillator. Not good but not bad situation. And now let's look to do it. (Sorry for czech comments in picuters - i am to lazy to redraw it to english)
 

You probably want to power your application from "debugger" (lets call it by its name mEDBG). You have to populate Jumper J300 nad remove R300 (its bypassing voltage regulator). Next step you have to disconnect target chip at Xplained board. Best way is to remove mega328 by hotair gun, but if you havent any, there is another simple way - cut lines. You need cut SCK,MISO,MOSI and RESET. Good idea is cut them in such places to work 6pin ISP connector. Necessary cuts are show at images below. Note that you have to cut between vias and chip ! As next move you can remove R107 and R108 and disconnect Rx,Tx lines. After populating J104 you can use USB->UART bridge ability of mEDBG. Dont forgot connect cable to clock (EXT_CLK), you'll need it for debugging. Its good idea disconnect clock from rest of board by cut on its back.

 


To be able select voltage (and frequency) populate J300 and remove R300
 


Carefuly cut ISP lines. Good idea is to scrape off surface varnish before cutting.
 


By removing R107 and R108 you can get acces to USB->UART brigde ability of mEDBG. In yellow box is pin with External clock, which must be connected to debugged application.
 


Disconnect clock from rest of board by cut.
 

Now its time to connect debugger to some aplication and show how to start debugging. For example i've conect Attiny24, ISP like usualy at MISO, MOSI,SCK, RST and clock to XTAL1.


Connected Attiny24 - standard ISP + Clock to XTAL1
 

Start Atmel studio, connect Xplained board to USB and you should see it in View->Available Atmel Tools. Click it by right mouse button and select Device Programming (another way is Tools->Device programming). Picture tutorial have been created for "hack" Xnano module to TPI programmer (more about this later), but setup for Xplained is the same so do not stop over that "tiny104" and "TPI". Now you can select only one device - mega328/168 (depends which kit you have). At website of Jay Carlson i've read that limitation is only software block in Atmel studio. Lets remove it. Click at icon "gear" (options). Select Tools->Tool Setting and change Hide Unsupported devices to False. Close and open window again and now you have acces to all Atmels. (Follow screenshots)
 





Its done, thanks mr Carlson

 

Now you are able to debug, but dont forgot. With start debugging session mEDBG switch fuses to external clock. Its possible by python script reconfigure mEDBG to dont do this, but i have not tried it. mEDBG hide many of fuses configuration (also can be repaired in python script). If you need (and you will) reconfigure fuses by mEDBG you have to input hexavalues manually (for example from engbedded AVR Fuse calc). Now let's take a look at debug starting. At Project->Properties->Tools select mEDBG and debugWIRE. When you start debugging, mEDBG ask you if you want to enable DWEN fuse (switch from ISP to DebugWIRE interface), select yes (and dont forgon that from this point you have not acces to ISP). If you connect everything correctly (dot forgot clock!) Atmel studio reporst succes and ask you to "cycle power" (its not necessary). If debug dont start immediately, slect "start debugging" one more time (and be patient - flashing chip by debugWIRE is slow). Program should start and break at first line of code - you are in debug mode ! If you want to stop debugging - click Stop debugging. But if you want to disable debugWIRE and get acces to ISP, you have to click Disable DebugWIRE and close.
 


Select right tool and interface
 


If you are starting debug first time, be prepared to enable DWEN fuse
 


 .. enabling DWEN fuse (only first time you are enabling debugWIRE)
 


Debug wire enabled succefuly
 


Stopping debug or Disabling debugWIRE - if you want use ISP you have to disable debug wire

 

Similar hack can be done with Xplained Nano kit and its TPI programmer. TPI interface can only program smalles Attiny's. If anyone is interested i can add tutorial how to modify that kit. Probably the most interesting and promising is modifiying ATtiny416 Xplained Nano, because it opens doors to new, peripheral rich, Atmel chips with debugging interface. If i succes with that, i'll publish instructions. I'am waiting kit in week or two. Posible i can post picture based tutorial how to modify Arduino UNO or Nano kits to debug by this "debugger" (simply remove capacitor from reset line, and connect clock).
 

Last Edited: Tue. Jul 24, 2018 - 02:26 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thats one helluva hack!

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gripennn wrote:
First i'll show how to hack Xplained Mini (328 or 168) into DebugWIRE debugger, because it have the most potential for arduino users

 

Very nifty, but I have to wonder why the PCB designers made this so difficult ?!

Other vendors make it very easy and simple to isolate their STK debug block, and  use it with an external device.

 

Did you look at the new mEDBG wiring in the new Ardunio ?

https://store.arduino.cc/usa/ard...

Is that easier to adapt to an external MCU ?

Last Edited: Tue. Jul 24, 2018 - 02:43 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Who-me wrote:
Very nifty, but I have to wonder why the PCB designers made this so difficult ?!
So they can continue to sell $99 Atmel-ICEs ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Who-me wrote:

Very nifty, but I have to wonder why the PCB designers made this so difficult ?!

clawson wrote:
So they can continue to sell $99 Atmel-ICEs ? 

Cynical - but really hard to see any other justification!

 

frown

 

As Who-me said,  other manufacturers don't do this!

 

Another useful tip if the on-board debugger seems "locked" to the specific target: https://community.atmel.com/comm...

 

EDIT - that tip is actually mentioned in #1.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Jul 24, 2018 - 08:56 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gripennn wrote:
mEDBG needs (sic?) to clock target application with its own clock

Is that true?

 

It can - but does it actually need to?

 

Pretty sure on the SAMD boards you can run from other clocks ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The  ATmega328P Xplained Mini schematic is available on the Product Page: https://www.microchip.com/DevelopmentTools/ProductDetails/ATMEGA328P-XMINI

 

It's in the 'Design Documentation' ZIP file: http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega328P-Xplained-Mini_Design-Documentation.zip

 

It shows that there are resistor links on the Debug & ISP connections from the mEDBG to the ATmega Target:

 

 

Similarly the UART:

 

So it may not actually be necessary to cut any tracks?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It looks that target application realy need clock from mEDBG.  I've made simple tests with these results:
1. I was not able to enable DebugWIRE at chip clocked from generator (at same frequency like mEDBG).
2. After enabling DebugWIRE (with clock from mEDBG) i can debug target chip clocked from generator (even with lower frequency than mEDBG)

Its mystery for me how mEDBG can recognize that clock comes from generator (only phase can differ ?). I hope that my test are wrong :) and somebody proove that. Other interfaces like UPDI or SWD (SAM interface ?) dont suffer from this problem (probably they have separated clock source ?).
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

The  ATmega328P Xplained Mini schematic is available on the Product Page: https://www.microchip.com/DevelopmentTools/ProductDetails/ATMEGA328P-XMINI

 

It's in the 'Design Documentation' ZIP file: http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega328P-Xplained-Mini_Design-Documentation.zip

 

It shows that there are resistor links on the Debug & ISP connections from the mEDBG to the ATmega Target:

 

 

Similarly the UART:

 

So it may not actually be necessary to cut any tracks?

 

These resistor are connected between mEDBG and rest of board. Removing them, discconect not only target chip (m328), but also ISP header. Its question if they are placed there intentionally or by "mistake" ... Resistors at uart lines are placed correctly and disconnecting them, release uart from target chip (like mentioned in tutorial above).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gripennn wrote:
Removing them, discconect not only target chip (m328), but also ISP header

So it does:

 

 

sad

 

Note that the SAMD20 XPlained-Pro board does have a debug-out connection:

 

http://www.microchip.com/developmenttools/ProductDetails/ATSAMD20-XPRO

 

Not sure if that's limited to SWD only (ie, ARM only), though?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nice research and modyes

 

Maybe you will be interested in some additional information available here at AVRFreaks.

Building your own mEDBG programmer/debugger has been discussed before, see this post and onwards: https://www.avrfreaks.net/commen...

 

Instead of modding a xplained board, it was discussed building the device from a standalone mega32U4. I presume you could use an Arduino Leonardo clone or something like that to host mEDBG.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

El Tangas wrote:

 

Maybe you will be interested in some additional information available here at AVRFreaks.

Building your own mEDBG programmer/debugger has been discussed before, see this post and onwards: https://www.avrfreaks.net/commen...

 

Instead of modding a xplained board, it was discussed building the device from a standalone mega32U4. I presume you could use an Arduino Leonardo clone or something like that to host mEDBG.

Thanks for tip.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Story continues ....
1. Arduino UNO and Nano kits can be debugged with minimal modification. You mustl remove capacitor from reset pin, and connect clock from Xplained ... and after debugging don't forgot write fuses to 16MHz Xtal clock.
2. Xplained nano kits are much better and dont need any hacks. You have to simply remove few jumpers and stand alone programmer debugger is ready. Xplained104 can be converted to TPI programmer (succefuly tested with Attiny10) and Xplained416 can be converted to UPDI debugger (tested with Tiny1616). 
 
Xplained nano 416 - remove jumpers and disconned target chip and you have stand alone debugger.


Xplained nano 104 - disconnect target chip from interface and you have stand alone programmer.
Dont forgot that TPI interface needs power target chip with 5V.


Arduino UNO and Nano can be debugged from modified Xplained328. you have to remove capacitor from reset and connect clock from Xplained.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cool, keep us updated on your experimentsyes

 

I have a question, did you ever try to replace the firmware of the mEDBG by the firmware for another target?

I ask this because there are 4 different versions of mEDBG, each specific for one type of target: https://www.avrfreaks.net/commen...