Quantcast

Dragon DW->ISP USB reset question

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Dragon DW->ISP USB reset question

John McCorquodale
Guys,

Just got my atmega328p on my spankin' new Dragon in debugWire mode and notice
what appears to be an old, well-understood situation:

  $ avrdude -c dragon_isp -P usb ...
  ISP connection fails cause DWEN fuse is set
  DW protocol to leave ISP ready occurs
  avrdude exits (*)

When avrdude exits and the libusb connection to the dragon closes, the dragon
resets, power cycling the atmega along with it, right back into DW mode.  Then
the subsequent avrdude call doesn't do the right thing, because the chip is
back in DW.

The answer is to supply an external power supply to keep the atmega up while
the dragon resets under it.

Sure, but here's my mindset: this clipping and unclipping of a wire in the
compile-load-debug cycle is distasteful.  (I have the atmega on a ZIF in the
dragon prototype area, not actually in-system.)

Here's my question (twofold):

  (1) Is it really that hard to get avrdude to restart the transaction without
      exitting and closing the libusb, causing the dragon to reset?
  (2) If I were to go through the hassle of patching avrdude to not need this
      spurious exit, would it be a dead-end because the dragon needs the reset
      in order to get itself back from DW into ISP?

Thanks for the info!  (avrdude rocks)

-mcq

P.S. The (*) above is to mention that the call to free() in jtagmkII_teardown()
     dumps code for me in both 5.10 and SVN head, right as avrdude exits.

_______________________________________________
avrdude-dev mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/avrdude-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Dragon DW->ISP USB reset question

Joerg Wunsch
As John McCorquodale wrote:

>   (2) If I were to go through the hassle of patching avrdude to not need this
>       spurious exit, would it be a dead-end because the dragon needs the reset
>       in order to get itself back from DW into ISP?

That's what I think is the case.  I cannot remember though, I think
this is not written down anywhere in an official Atmel document but
I've been explained that upon a request to Atmel many years ago.
That's why I implemented it the way it is now.

> P.S. The (*) above is to mention that the call to free() in jtagmkII_teardown()
>      dumps code for me in both 5.10 and SVN head, right as avrdude exits.

That's bad.  I thought I've been fixing all those pointer confusions.
Please file a bug report for it (of course, if you've got a fix, I'd
be even more thankful as I cannot spend too much time into AVRDUDE
right now due to personal shortage of sparetime).
--
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)

_______________________________________________
avrdude-dev mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/avrdude-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Dragon DW->ISP USB reset question

John McCorquodale
> That's what I think is the case.  I cannot remember though, I think
> this is not written down anywhere in an official Atmel document but
> I've been explained that upon a request to Atmel many years ago.
> That's why I implemented it the way it is now.

For what it's worth, I made a simple change to get avrdude to restart without
closing down after doing the DW->ISP protocol and things now work beautifully!
This may be a Dragon-only thing, but it does let you use dragon_isp without
thinking and without any special double-invocations even when DWEN is set,
without an external PS.  So it's useful when you have your atmel in the
Dragon's prototype area rather than in-system.

> That's bad.  I thought I've been fixing all those pointer confusions.
> Please file a bug report for it (of course, if you've got a fix, I'd

With this patch, the core dump goes away.  Looks like the problem was
cloberage or something being unitialized on the exit path right after the
"goto retry" below.

This gives me the avrdude I really want for my situation, but more subtlety
is probably called for in order to take the idea into the mainline.  If you
care to clue me in on what the issues are, I can see about getting a patch
together.

For reference here's the fix around jtagmkII.c:822:

  retry:
    /* Turn the ICE into JTAG or ISP mode as requested. */
    buf[0] = mode;
    if (jtagmkII_setparm(pgm, PAR_EMULATOR_MODE, buf) < 0) {
      if (mode == EMULATOR_MODE_SPI) {
        fprintf(stderr,
                "%s: jtagmkII_getsync(): "
                "ISP activation failed, trying debugWire\n",
                progname);
        buf[0] = EMULATOR_MODE_DEBUGWIRE;
        if (jtagmkII_setparm(pgm, PAR_EMULATOR_MODE, buf) < 0)
          return -1;
        else {
          /*
           * We are supposed to send a CMND_RESET with the
           * MONCOM_DISABLE flag set right now, and then
           * restart from scratch.
           *
           * As this will make the ICE sign off from USB, so
           * we risk losing our USB connection, it's easier
           * to instruct the user to restart AVRDUDE rather
           * than trying to cope with all this inside the
           * program.
           */
          (void)jtagmkII_reset(pgm, 0x04);
          fprintf(stderr,
                  "%s: Target prepared for ISP, signed off.\n",
                  progname);
  goto retry;
          jtagmkII_close(pgm);
          fprintf(stderr,
                  "%s: Target prepared for ISP, signed off.\n"
                  "%s: Please restart %s without power-cycling the target.\n",
                  progname, progname, progname);
          exit(0);
        }
      } else {
        return -1;
      }
    }

I'm stoked it was that simple and I get everything I want!  Again, avrdude
is my buddy.  I totally owe you a beer or twelve!
 
Cheers,

-mcq

_______________________________________________
avrdude-dev mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/avrdude-dev
Loading...