avrdudes / avrdude

AVRDUDE is a utility to program AVR microcontrollers
GNU General Public License v2.0
667 stars 131 forks source link

[bug #34767] Avrdude to enable AVR Dragon to program AVR32 parts #239

Closed avrs-admin closed 2 years ago

avrs-admin commented 2 years ago

Julien Aube Mon 07 Nov 2011 08:49:21 AM UTC

Attached is a patch to let the AVR-Dragon program the avr32 parts.

The AVR-Dragon uses the same protocol than the jtagmkII probe, so the patch apply the same code for the Dragon.

It enable a new probe : dragon_avr32 which enable AVR32-specific calls, like the jtagmkII probe does.

This patch modifies the jtagmkII.c/.h files as well as the lex/yacc files, and the configuration example.

file #24317: dragon_avr32.patch file #24319: dragon_avr32_v2.patch

This issue was migrated from https://savannah.nongnu.org/bugs/?34767

avrs-admin commented 2 years ago

Julien Aube Mon 07 Nov 2011 09:31:22 AM UTC

Added dragon_avr32_v2.patch which:

The consequence of this bug was a malloc(0) on jtagmkII.c:2948, and then any read/write on the page was crashing.

Now the command works on a UC3A1256.

(file #24319)

mcuee commented 2 years ago

I only have one UC3 device which is UC3A3256 (UC3-XPlained board from Microchip/Atmel). Avr Dragon works fine under Microchip Studio.

Not so sure if the above patch works for my device or not. I will try this patch later.

mcuee commented 2 years ago

AVR32 has been de-focused by Microchip/Atmel long ago. So we will close this issue.

mcuee commented 1 year ago

Patch file:

Index: jtagmkII.c
===================================================================
--- jtagmkII.c  (révision 1018)
+++ jtagmkII.c  (copie de travail)
@@ -166,6 +166,9 @@
                                  unsigned int page_size,
                                  unsigned int addr, unsigned int n_bytes);

+static int jtagmkII_dragon_open32(PROGRAMMER * pgm, char * port);
+
+
 void jtagmkII_setup(PROGRAMMER * pgm)
 {
   if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
@@ -1676,7 +1679,81 @@
   return 0;
 }

+static int jtagmkII_dragon_open32(PROGRAMMER * pgm, char * port)
+{
+  int status;
+  unsigned char buf[6], *resp;
+  long baud;

+  if (verbose >= 2)
+    fprintf(stderr, "%s: jtagmkII_dragon_open()\n", progname);
+
+  /*
+   * The JTAG ICE mkII always starts with a baud rate of 19200 Bd upon
+   * attaching.  If the config file or command-line parameters specify
+   * a higher baud rate, we switch to it later on, after establishing
+   * the connection with the ICE.
+   */
+  baud = 19200;
+
+  /*
+   * If the port name starts with "usb", divert the serial routines
+   * to the USB ones.  The serial_open() function for USB overrides
+   * the meaning of the "baud" parameter to be the USB device ID to
+   * search for.
+   */
+  if (strncmp(port, "usb", 3) == 0) {
+#if defined(HAVE_LIBUSB)
+    serdev = &usb_serdev;
+    baud = USB_DEVICE_AVRDRAGON;
+#else
+    fprintf(stderr, "avrdude was compiled without usb support.\n");
+    return -1;
+#endif
+  }
+
+  strcpy(pgm->port, port);
+  if (serial_open(port, baud, &pgm->fd)==-1) {
+    return -1;
+  }
+
+  /*
+   * drain any extraneous input
+   */
+  jtagmkII_drain(pgm, 0);
+
+  if (jtagmkII_getsync(pgm, EMULATOR_MODE_JTAG) < 0)
+    return -1;
+
+  // AVR32 "special"
+  buf[0] = CMND_SET_PARAMETER;
+  buf[1] = 0x2D;
+  buf[2] = 0x03;
+  jtagmkII_send(pgm, buf, 3);
+  status = jtagmkII_recv(pgm, &resp);
+  if(status < 0 || resp[0] != RSP_OK)
+    return -1;
+  free(resp);
+
+  buf[1] = 0x03;
+  buf[2] = 0x02;
+  jtagmkII_send(pgm, buf, 3);
+  status = jtagmkII_recv(pgm, &resp);
+  if(status < 0 || resp[0] != RSP_OK)
+    return -1;
+  free(resp);
+
+  buf[1] = 0x03;
+  buf[2] = 0x04;
+  jtagmkII_send(pgm, buf, 3);
+  status = jtagmkII_recv(pgm, &resp);
+  if(status < 0 || resp[0] != RSP_OK)
+    return -1;
+  free(resp);
+
+  return 0;
+}
+
 void jtagmkII_close(PROGRAMMER * pgm)
 {
   int status;
@@ -2864,6 +2941,8 @@
     return -1;
   }

+  jtagmkII_set_devdescr(pgm, p);
+
   free(PDATA(pgm)->flash_pagecache);
   free(PDATA(pgm)->eeprom_pagecache);
   if ((PDATA(pgm)->flash_pagecache = malloc(PDATA(pgm)->flash_pagesize)) == NULL) {
@@ -3734,6 +3813,38 @@
   pgm->flag           = PGM_FL_IS_DW;
 }

+void jtagmkII_dragon_avr32_initpgm(PROGRAMMER * pgm)
+{
+  strcpy(pgm->type, "DRAGON_AVR32");
+
+  /*
+   * mandatory functions
+   */
+  pgm->initialize     = jtagmkII_initialize32;
+  pgm->display        = jtagmkII_display;
+  pgm->enable         = jtagmkII_enable;
+  pgm->disable        = jtagmkII_disable;
+  pgm->program_enable = jtagmkII_program_enable_dummy;
+  pgm->chip_erase     = jtagmkII_chip_erase32;
+  pgm->open           = jtagmkII_dragon_open32;
+  pgm->close          = jtagmkII_close32;
+  pgm->read_byte      = jtagmkII_read_byte;
+  pgm->write_byte     = jtagmkII_write_byte;
+
+  /*
+   * optional functions
+   */
+  pgm->paged_write    = jtagmkII_paged_write32;
+  pgm->paged_load     = jtagmkII_paged_load32;
+  pgm->print_parms    = jtagmkII_print_parms;
+  pgm->set_sck_period = jtagmkII_set_sck_period;
+  pgm->parseextparams = jtagmkII_parseextparms;
+  pgm->setup          = jtagmkII_setup;
+  pgm->teardown       = jtagmkII_teardown;
+  pgm->page_size      = 256;
+  pgm->flag           = PGM_FL_IS_JTAG;
+}
+
 void jtagmkII_avr32_initpgm(PROGRAMMER * pgm)
 {
   strcpy(pgm->type, "JTAGMKII_AVR32");
Index: jtagmkII.h
===================================================================
--- jtagmkII.h  (révision 1018)
+++ jtagmkII.h  (copie de travail)
@@ -40,6 +40,7 @@
 void jtagmkII_dragon_initpgm (PROGRAMMER * pgm);
 void jtagmkII_dragon_dw_initpgm (PROGRAMMER * pgm);
 void jtagmkII_dragon_pdi_initpgm (PROGRAMMER * pgm);
+void jtagmkII_dragon_avr32_initpgm(PROGRAMMER * pgm);

 /*
  * These functions are referenced from stk500v2.c for JTAG ICE mkII
Index: config_gram.y
===================================================================
--- config_gram.y   (révision 1018)
+++ config_gram.y   (copie de travail)
@@ -103,6 +103,7 @@
 %token K_DRAGON_JTAG
 %token K_DRAGON_PDI
 %token K_DRAGON_PP
+%token K_DRAGON_AVR32
 %token K_STK500_DEVCODE
 %token K_AVR910_DEVCODE
 %token K_EEPROM
@@ -532,6 +533,11 @@
       jtagmkII_avr32_initpgm(current_prog);
     }
   } |
+  K_TYPE TKN_EQUAL K_DRAGON_AVR32 {
+    {
+      jtagmkII_dragon_avr32_initpgm(current_prog);
+    }
+  } |

   K_TYPE TKN_EQUAL K_JTAG_MKII_DW {
     {
Index: ChangeLog
===================================================================
--- ChangeLog   (révision 1018)
+++ ChangeLog   (copie de travail)
@@ -1,3 +1,9 @@
+2011-11-06  Julien Aube  <julien.aube@openwide.fr>
+
+   * jtakmkII.c: Added a new programmer type "dragon_avr32", to 
+   let an AVR dragon program AVR32 parts.
+   * avrdude.conf: 32UC3A1256 part to config file.
+
 2011-10-19  Joerg Wunsch <j.gnu@uriah.heep.sax.de>

    * configure.ac: Replace "cvs" in version number by "svn".
Index: avrdude.conf.in
===================================================================
--- avrdude.conf.in (révision 1018)
+++ avrdude.conf.in (copie de travail)
@@ -707,7 +707,15 @@
   type  = dragon_pdi;
 ;

+# AVR Dragon in AVR32 mode
 programmer
+  id    = "dragon_avr32";
+  desc  = "Atmel AVR Dragon in AVR32 mode";
+  baudrate = 115200;
+  type  = dragon_avr32;
+;
+
+programmer
   id    = "pavr";
   desc  = "Jason Kyle's pAVR Serial Programmer";
   type  = avr910;
Index: lexer.l
===================================================================
--- lexer.l (révision 1018)
+++ lexer.l (copie de travail)
@@ -144,6 +144,7 @@
 dragon_jtag      { yylval=NULL; return K_DRAGON_JTAG; }
 dragon_pdi       { yylval=NULL; return K_DRAGON_PDI; }
 dragon_pp        { yylval=NULL; return K_DRAGON_PP; }
+dragon_avr32     { yylval=NULL; return K_DRAGON_AVR32; }
 eecr             { yylval=NULL; return K_EECR; }
 eeprom           { yylval=NULL; return K_EEPROM; }
 enablepageprogramming { yylval=NULL; return K_ENABLEPAGEPROGRAMMING; }