Author Topic: Cheap Atmega debugging interface?  (Read 7573 times)

0 Members and 1 Guest are viewing this topic.

Offline splinTopic starter

  • Frequent Contributor
  • **
  • Posts: 999
  • Country: gb
Cheap Atmega debugging interface?
« on: March 15, 2017, 01:52:14 pm »
I want to hack some electronic thermostatic radiator valves which use an atmega169P. I have a USBasp which I can use to program them but I can't find find any really low cost solution for debugging - other than printfs.

I can get dirt cheap interfaces, such as STLink, for debugging ARM chips so I'm a bit surprised that there doesn't seem to be anything obvious for AVRs given how long they have been around and their popularity. Is it because the debugging interface isn't fully documented and Atmel is/was trying to get revenue from selling tools? If so, it seems to be another good reason not to use AVRs.
 

Offline up8051

  • Frequent Contributor
  • **
  • Posts: 288
  • Country: pl
 

Offline splinTopic starter

  • Frequent Contributor
  • **
  • Posts: 999
  • Country: gb
Re: Cheap Atmega debugging interface?
« Reply #2 on: March 15, 2017, 04:35:51 pm »
AVR Dragon:
http://uk.farnell.com/atmel/atavrdragon/in-system-debugger-programmer/dp/1455088

At £50 including VAT it's hardly cheap - it's 5x the cost of the TRV I'd like to debug. I probably wouldn't have a use for it after this so I was looking for something really low cost.
 

Offline Bruce Abbott

  • Frequent Contributor
  • **
  • Posts: 627
  • Country: nz
    • Bruce Abbott's R/C Models and Electronics
Re: Cheap Atmega debugging interface?
« Reply #3 on: March 15, 2017, 08:16:54 pm »
How complex can your software be if it's only controlling a valve?

I don't use a hardware debugger because:-

1. Printf or toggling a pin will tell you 99% of what you want to know in real time.

2. AVR has a simulator that lets you step through code without any hardware.

3. If the your program isn't working properly then you should review the source. A hardware debugger is only required when the code is bug free but the device still doesn't work (ie. never!).
     
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6352
  • Country: ca
  • Non-expert
Re: Cheap Atmega debugging interface?
« Reply #4 on: March 15, 2017, 09:44:35 pm »
There are some AVR JTAG ICE clones on aliexpress for $4.

It looks like it will work for 169 with some limitations:
http://www.instructables.com/id/Getting-Started-With-AVR-JTAGICE-Clone/
http://www.electrodragon.com/w/AVR_USB_JTAG_ICE_Programmer
May need to use the old IDE.
Also you will have to bring out all JTAG pins as opposed to just the few needed for the ISP debugger.

Consider if that is worth ~$60 to you.

How complex can your software be if it's only controlling a valve?

I don't use a hardware debugger because:-
1. Printf or toggling a pin will tell you 99% of what you want to know in real time.
2. AVR has a simulator that lets you step through code without any hardware.
3. If the your program isn't working properly then you should review the source. A hardware debugger is only required when the code is bug free but the device still doesn't work (ie. never!).   

Sure, but I'd rather spend a few dollars on a hw debugger, see exactly whats going on, and save time debugging. Live display of multiple variables is possible (with some).
But I agree the simulator is useful, and you are free to use whatever method you like.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline splinTopic starter

  • Frequent Contributor
  • **
  • Posts: 999
  • Country: gb
Re: Cheap Atmega debugging interface?
« Reply #5 on: March 15, 2017, 10:04:11 pm »
How complex can your software be if it's only controlling a valve?

It's not my code - it is 100% assembler - about 5200 lines of it including blank lines and comments. It isn't particularly complex but it has to regulate temperature, manage user input from switches to set time and temperatures, drive an LCD etc.

Quote
I don't use a hardware debugger because:-

1. Printf or toggling a pin will tell you 99% of what you want to know in real time.

2. AVR has a simulator that lets you step through code without any hardware.

Fair enough, everyone has their own preferences. I like to use debuggers for some problems because it's usually much easier and faster than writing shed loads of printfs into the code, rebuilding, programming, testing, repeat ad nauseum. And spending two days tearing your hair out trying to work out why it doesn't work only to find it was one of your bits of test code that overflowed the stack or whatever.

The simulator may be a useful option however. Thanks for pointing that out.

Quote
3. If the your program isn't working properly then you should review the source. A hardware debugger is only required when the code is bug free but the device still doesn't work (ie. never!).

Sorry, but that is total rubbish - but apologies if it was a tongue in cheek comment. Sure review your code for the thousandth time and still you can't see what is wrong because you missed the small print in the footprint on page 1147 of the reference manual that says that flag xyz can be cleared by some unrelated peripheral in some obscure conditions. All your printfs and port twiddling didn't help because they changed the timing/memory layout/stack usage etc.

Or your processor simply runs off into the ether because you misconfigured one of the clock domains or failed to ramp the clock speed up sufficiently slowly to allow the PLL to track it.

Or you use inadvertantly use an uninitialised pointer in an interrupt routine which mangles the stack. Good luck finding that with printfs.

Or you get a hard fault (on an ARM Cortex) when you call an assembler function, supplied by ARM, with ".section text" instead of ".section .text" which causes the linker to fixup the call with a branch opcode which is invalid for that target type. Examining assembler output from GCCs compilation of your C code doesn't help because it was the linker that threw a wobbly. Examining the diassembled code in the debugger revealed the problem. No amount of printfs would help.

In all these cases your code is wrong but a good debugger can make your life very much easier.
 

Offline splinTopic starter

  • Frequent Contributor
  • **
  • Posts: 999
  • Country: gb
Re: Cheap Atmega debugging interface?
« Reply #6 on: March 15, 2017, 10:24:16 pm »
There are some AVR JTAG ICE clones on aliexpress for $4.

It looks like it will work for 169 with some limitations:
http://www.instructables.com/id/Getting-Started-With-AVR-JTAGICE-Clone/
http://www.electrodragon.com/w/AVR_USB_JTAG_ICE_Programmer
May need to use the old IDE.
Also you will have to bring out all JTAG pins as opposed to just the few needed for the ISP debugger.

Consider if that is worth ~$60 to you.

That looks very promising - exactly the sort of thing I was looking for - thanks. The jtag pins are already connected to test lands so not a problem.

I wonder why it doesn't work with later builds of Atmel Studio? Have they deliberately made sure that clone ICEs don't work because they think selling $60 ICEs is an important part of their revenue stream and more important than making AVR development as easy and acessible to as many developers as possible including hobbyists?
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 6352
  • Country: ca
  • Non-expert
Re: Cheap Atmega debugging interface?
« Reply #7 on: March 15, 2017, 10:45:32 pm »
That looks very promising - exactly the sort of thing I was looking for - thanks. The jtag pins are already connected to test lands so not a problem.

I wonder why it doesn't work with later builds of Atmel Studio? Have they deliberately made sure that clone ICEs don't work because they think selling $60 ICEs is an important part of their revenue stream and more important than making AVR development as easy and acessible to as many developers as possible including hobbyists?

They came out with the JTAG ICE Mk2 (there are clones of that available as well, but much more expensive). It supports the newer debugwire and other formats, and is supported in the latest IDE.
So they probably stopped supporting the MK1 after that came out.

List of supported debuggers for avr:
http://www.atmel.com/webdoc/atmelstudio/supported.devices.AVR.Mega.html
http://www.avrfreaks.net/forum/avr-studio-7-jtag-ice (mentions AS4.18 should work)

It is a shame they never came out with a low cost basic debugger like the stlink. I don't know how they decide this, part of it is complexity, the avr dragon is ridiculously complex compared to a stlink.
Profile -> Modify profile -> Look and Layout ->  Don't show users' signatures
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Cheap Atmega debugging interface?
« Reply #8 on: March 16, 2017, 12:24:05 am »
Quote
Quote
I wonder why it doesn't work with later builds of Atmel Studio?
They came out with the JTAG ICE Mk2
And the JTAG-ICE3, and (current product) the Atmel-ICE.
I believe that they don't support their own old JTAG-ICE either.
I think I have one.  I guess I could check...

The Atmel-ICE was recently on sale ($50 off, plus free shipping), but I think that ended 28-Feb.
The "bare" Atmel-ICE is comparable in price to the Dragon, and IS the "current product"...
 

Offline obiwanjacobi

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: Cheap Atmega debugging interface?
« Reply #9 on: March 16, 2017, 07:55:33 am »
Note that not all Atmel devices support debugWire.

I had bought an official Atmel ICE (~50,= iirc) only to find out my device didn't support debugWire but it does support Jtag.

I now have a adapter cable coming that allows conversion of the 50mil connector to the standard 100mil/0.1".
And I can rewire my prototype board to use Jtag instead of ISP.

[2c]
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline cyberfish

  • Regular Contributor
  • *
  • Posts: 240
  • Country: gb
Re: Cheap Atmega debugging interface?
« Reply #10 on: March 16, 2017, 01:06:02 pm »
Fair enough, everyone has their own preferences. I like to use debuggers for some problems because it's usually much easier and faster than writing shed loads of printfs into the code, rebuilding, programming, testing, repeat ad nauseum. And spending two days tearing your hair out trying to work out why it doesn't work only to find it was one of your bits of test code that overflowed the stack or whatever.

I find the value of debugging to be limited on AVRs (and microcontrollers in general).

Most embedded applications are real time, and stopping the CPU throws everything off (timing, interrupts, etc). Conditional printfs do also change timings, but probably not as much as stopping the CPU completely.

One thing I do love using a debugger for is to catch memory corruptions though. I just don't get much of that nowadays.
 

Offline Brutte

  • Frequent Contributor
  • **
  • Posts: 614
Re: Cheap Atmega debugging interface?
« Reply #11 on: March 24, 2017, 07:16:57 pm »
I wonder why it doesn't work with later builds of Atmel Studio? Have they deliberately made sure that ...
That is/was their marketing-fu.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf