debugWire question - Page 1
Forum section: electronics / general

author: Dan Moos
author_rank: Frequent Contributor
timestamp: September 19, 2016, 02:01:58 am
content: Using debugWire with an AVR Dragon, an atmega328P, and AVR Studio 7.Here's a dumb question. When debugging with debugWire, in the register window, am I seeing what the actual hardware registers are doing, or just what the code should make them. I assume its the first, and that its an actual peek inside the mcu, but I just want to be sure. In circuit debugging wouldn't make much sense to me if it were any other way, but I been wrong about such simple things before.

author: ataradov
author_rank: Super Contributor
timestamp: September 19, 2016, 03:50:30 am
content: You see the actual register contents.

author: Dan Moos
author_rank: Frequent Contributor
timestamp: September 19, 2016, 03:52:58 am
content: Thanks. It seemed silly that it would be otherwise.

author: rx8pilot
author_rank: Super Contributor
timestamp: September 19, 2016, 05:13:19 am
content: FWIW, I wondered the same thing. Although it is logical that it would report the actual register/variable values - I was not sure the system had access to them.Thanks for asking. Do you have any suggestions for setting up and using debugWire? I am wasting a lot of time by not using it.

author: ataradov
author_rank: Super Contributor
timestamp: September 19, 2016, 05:15:31 am
content: Quote from: rx8pilot on September 19, 2016, 05:13:19 amThere is not much to set up. Just enable DWEN fuse bit and select debugWire as a debug/programming interface.

author: rx8pilot
author_rank: Super Contributor
timestamp: September 19, 2016, 05:18:39 am
content: Uses the SPI interface?Does it work in realtime or do I need to set breakpoints? My first hope would be to see what everything looks like if the MCU locks up - stuck in a loop, overrun an array, whatever bad things I do.

author: ataradov
author_rank: Super Contributor
timestamp: September 19, 2016, 05:22:15 am
content: Quote from: rx8pilot on September 19, 2016, 05:18:39 amNo, it actually uses RESET pin in a really weird way, and you have to stop debug session by properly exiting it. If you disconnect the target, then reset pin will be stuck in that mode, and you will have to do some dancing to get it back.Quote from: rx8pilot on September 19, 2016, 05:18:39 amIt works like any other debugger. You can run, pause execution, do single stepping, etc.Here is some text about thathttp://www.atmel.com/webdoc/avrdragon/avrdragon.dw_description.htmlAnd I guess you don't need to set it manually:QuoteJust select debugWire and hit Debug.

author: rx8pilot
author_rank: Super Contributor
timestamp: September 19, 2016, 05:35:03 am
content: Quote from: ataradov on September 19, 2016, 05:22:15 amI have not used a debugger before, so this is all juicy info. Thank you. I guess one should ensure the target is attached reliably to not brick the chip or create a challenge to get it back to normal. I have an STK500 that I think can do high-voltage - would that be suitable to get back to normal if the debug wire session gets terminated improperly?

author: ataradov
author_rank: Super Contributor
timestamp: September 19, 2016, 05:40:03 am
content: Quote from: rx8pilot on September 19, 2016, 05:35:03 amdW is not the best debug protocol, so don't base your opinion on debuggers based on this.Quote from: rx8pilot on September 19, 2016, 05:35:03 amI think there is a way to recover even with low voltage. If I'm not mistaken, you can't program though dW, so you need ISP for that. And if you stuck in dW mode, you lose ISP. To recover, you just need to start a new debug session without uploading the program, and exit this session right away, which will recover the fuse.

author: 2N3055
author_rank: Super Contributor
timestamp: September 19, 2016, 05:53:20 am
content: Quote from: ataradov on September 19, 2016, 05:40:03 amThat is correct..I agree it's a bit clunky, and slow, but it can be helpful at the times...I would suggest that this topic really needs a good look in the documentation... There are many details.. From how you implement the connection to other details..

author: rx8pilot
author_rank: Super Contributor
timestamp: September 19, 2016, 06:06:02 am
content: If all the JTAG pins are used in the circuit, debugWire seems like the only option. Time to figure this out......Sent from my horrible mobile....

author: ajb
author_rank: Super Contributor
timestamp: September 20, 2016, 05:47:03 pm
content: Quote from: ataradov on September 19, 2016, 05:22:15 amYou should be able to leave parts in dW mode and come back to them later without (much) trouble. I've been doing this these past couple of days with a couple of little gadgets where I only wanted to bring out a 3-pin programming connection.Quote from: rx8pilot on September 19, 2016, 05:18:39 amYou can set breakpoints, or if the chip seems to have locked up you can do Debug->Break All which will show you exactly where the chip is in the program. Just be aware that after optimization the actual program flow will be rather different from what the source code shows, and when stepping through the program may seem to jump around wildly. Sometimes you may need to look at the assembly (which will reflect actual program flow) to understand what's going on.PDI (used on AVR XMEGA parts) and SWD (ARM) are generally more robust and faster without taking up too many pins, but debugWire will certainly get the job done.