How attach to target use AVR Dragon for Atmega328 ?

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

I work in Atmel Studio 7 with Atmega328 and use AVR Dragon for debug Atmega328. I use DebugWire interface. I find in Atmel Studio item in Debug menu is "Attach to target", but when i connected Avr Dragon and target device with Atmega328, i see that this item is gray and i can't click "attach to target".

Can who help me about my questions. Can avr dragon attach to target by debugwire interface and supported this ability atmega328 ?

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

Welcome to AVR Freaks!

 

I have never used "Attach to target".

 

When the Dragon is connected to your computer and to the target,  simply choose "Start Debugging and Break".

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Tue. Feb 20, 2018 - 08:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, i usually choose "Start Debugging and Break" but sometimes my device have problems and this happens after several days of continuous work. Since the error in the firmware atmega328 does not appear regularly, but very rarely. I would like to, when there will be an error in atmega328, after that, already connect to atmega328 and see where the code is executing.

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

The only thing I can suggest is this line from Studio Help:

 

The ability to activate a debug session without resetting a target is architecture dependent. Not all architectures supports this feature

I am dubious that this works with standard AVR Tinys and Megas but it would be nice to be proven wrong! This is more like something I would expect from one of the SAM chips. As I think about it, I do not recall this ever being discussed here on Freaks. But, maybe that is just fading neurons.

 

One of the few on the forum who would know for sure (or could quickly find out) is morten (meolsen) from Microchip/Atmel. Hopefully he will  spot this and respond.

 

Jim 

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Tue. Feb 20, 2018 - 10:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AVR can do this, UC3 cannot, ARM can. (The button should disable itself if the project architecture doesn't support this).
.
As for debugWire... I wouldn't expect it to work (ie it's correctly disabled). JTAG, PDI and UPDI devices should work.

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

Last Edited: Wed. Feb 21, 2018 - 12:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

IIRC, to enter debugwire mode, one must cycle target power, so "attaching via DebugWire mode" to a powered target to examine running code will not work.

You will need to start in debug mode and wait for the error to happen.  However long that takes.

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

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

meolsen wrote:
As for debugWire... I wouldn't expect it to work (ie it's correctly disabled). JTAG, PDI and UPDI devices should work.

I correct understand you that me need try debug only JTAG or PDI interfaces and don't use debugWire ?

Atmega can "attach to target" only in JTAG and PDI and can't in DebugWire ?

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

ki0bk wrote:
You will need to start in debug mode and wait for the error to happen.

I switch atmega328 in atmel studio with avr dragon in debugwire mode. After this i get error and want attach but "attach to target" is gray in atmel studio. 

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

mixer821 wrote:
After this i get error and want attach but "attach to target" is gray in atmel studio.
An alternative to Atmel Studio's atbackend.exe is dwire-debug though there's a concern due to Morten's comment (https://www.avrfreaks.net/forum/how-attach-target-use-avr-dragon-atmega328#comment-2400786)

debugWIRE via USB UART

https://www.avrfreaks.net/forum/debugwire-usb-uart

 

"Dare to be naïve." - Buckminster Fuller

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

For that, why do you want to attach? I'm assuming that you actually want to Start Debugging instead (Start Debugging = Reset + Attach in very simplistic terms)... 

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

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

He or she wants to break and debug a running program without altering the states of the variables shortly after an infrequent error has occurred. The description of "Attach" in the Studio Help seems to provide that, with the exception that some architectures are not supported.

 

It would be a pain to tie up a computer for several days, waiting for the fault to occur. Assuming that Windows will operate continuously for that long.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Wed. Feb 21, 2018 - 08:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:
wants to break and debug a running program without altering the states of the variables shortly after an infrequent error has occurred.

Yes, you right.

ka7ehk wrote:
some architectures are not supported.

Atmega328 supported.

 

If i correct understand me need use only JTAG instead of DebugWire and item "Attach" will available.

 

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

mixer821 wrote:
If i correct understand me need use only JTAG instead of DebugWire and item "Attach" will available.

No 328 is DebugWire only device, no JTAG available!

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

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

ki0bk wrote:
No 328 is DebugWire only device

But why 328 don't want "attach" in DebugWire if atmega supported.

Last Edited: Thu. Feb 22, 2018 - 07:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mixer821 wrote:
But why 328 don't want "attach" in DebugWire if atmega supported.

To enter dwire mode, the IDE must set the DWIRE fuse and power cycle the 328 to enter (attach) using debugwire mode.  

Once that happens, you can run in debug mode, you can not enter (attach) while the 328 is actively running in normal mode.

To exit debugWire mode the IDE must restore the DWIRE fuse, and again the 328 resets.

 

DWIRE uses the reset pin as a single wire debug comm port, to change it from RESET to DWIRE requires the fuse change and power cycle to complete.

 

hope that helps explains why it can not be done on the fly.

Jim

 

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

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

ki0bk wrote:
To enter dwire mode, the IDE must set the DWIRE fuse and power cycle the 328 to enter (attach) using debugwire mode.  

 

Maybe I did not explain my experiment well.
I switch 328 to the dwire mode, launched a target outside the debugger, and wait for the error for several days. When an error occurs  target already in the dwire mode, and it no longer needs to be reset, in order to switch to this mode, it is already in this mode.

Last Edited: Thu. Feb 22, 2018 - 09:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mixer821 wrote:
launched a target outside the debugger,

I don't know what this means?  Your setting the DWIRE fuse your self and not using the IDE to "start debugging and break", followed by a debug run?

 

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

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

I set 5 volt on VCC and target work with DWIRE fuse without IDE. And when happen error in target i want attach in IDE and watch state of registers,stack.

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

But morten wrote:

 

As for debugWire... I wouldn't expect it to work (ie it's correctly disabled). JTAG, PDI and UPDI devices should work.

And M328P does NOT have JTAG.

 

Jim 

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

I found error in my program in atmega328. I see that sometimes register R1 stay not equal 0 and when in my code i try to assign  my variable in 0, I receive not 0.

How me find where register R1 stay not equal 0 ? I try data breakpoint on write but this don't work.

Can avr dragon hardware breakpoint on write ?

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

The GCC libraries will be very careful with R1. They will save and restore as necessary.
I suspect that you have a NULLPTR that you are writing to. Make sure that any pointer is not NULL before writing to it.
Nice CPUs like the M68000 would give you an exception. The AVR is not so clever.
.
David.

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

david.prentice wrote:
I suspect that you have a NULLPTR that you are writing to.

No, i write on C my program. I said that when program do instruction "counter=0", in fact i have counter not 0 because R1 not 0.

And i don't know why R1 not 0 stay.

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

mixer821 wrote:
No, i write on C my program.
We can't see your program, so post your code.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

After a MUL it may be the case that R1 != 0 but the compiler will have added code to restore it. So for any particular:

variable = 0;

the compiler should generate:

STS variable, R1

and at the point of execution R1 will have 0 in it.

 

The only exception to this are if your code contains any asm() or use of __attribute__((naked)). If you do either then it's very easy to screw things up and corrupt R1.

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

mixer821 wrote:
this item is gray and i can't click "attach to target".

I use AVR Dragon and Atmel ICE with XMEGA-s and the "Attach to target" button is active when ICE is selected and is inactive when Dragon is selected. It looks for me that "Attach to target" is just inavailable with Dragon.

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

There was a thread about this the other day in which Morten confirmed that dynamic attach to running target is not a possibility for debugWire.

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

It is a bit of a mystery why anyone would ever know about R1.    Unless you are writing an ASM program.

 

Zip up and attach your AS7 project.

 

This sort of "bug" is very difficult to find.    You could add a regular Timer interrupt and enter a Breakpoint.

I would search through your source code for "unsafe" use of R1.   And for any misuse of a NULL pointer.

 

David.