bugAVR Downloader/UploaDEr - Bugs: bug #39526, Why mega 2560 did not work as an...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #39526: Why mega 2560 did not work as an ISP

Submitter:  Peter Saunderson <peteasa>
Submitted:  Fri 19 Jul 2013 01:36:49 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  None Privacy:  Public
Assigned to:  None Originator Name:  Peter Saunderson
Open/Closed:  Open Release:  None
Programmer hardware:  Device type: 

Fri 19 Jul 2013 01:36:49 PM UTC, original submission:  

I have tested out this fix for a number of weeks now and it is simple and seems to work.  I started a chat discussion at http://forum.arduino.cc/index.php?topic=174857.0 to get other peoples feedback and share the fix so that others can try it out.

OBSERVATION:
         Using Port                    : /dev/ttyACM0
         Using Programmer              : arduino
         Overriding Baud Rate          : 9600
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding

DISCUSSION:
The arduino code in avrdude adds a small bit to stk500 code.  The fix is in arduino code and is sufficient to start the communications and then a small fix to mega-isp  http://code.google.com/p/mega-isp/ enables full operation.  The reason for the failure is that for example the mega2560 board resets when USB serial is established. avrdude does not wait but attempts to start communication whilst mega2560 is in reset so the communication is never established.  With the bug fix avrdude allows mega2560 time reboot but still because avrdude sends multiple start frames mega-isp tries to respond to all the start messages and again once the communication is established mega-isp now fails to send the correct responses to avrdude.  Best solution would be to modify stk500 code and mega-isp with the proper (three way) handshake to guarentee startup, however since stk500 obviously works the quick fix is to delay the start of avrdude:
  /* Set DTR and RTS back to high */
  serial_set_dtr_rts(&pgm->fd, 1);

  /* Sleep to allow the Arduino board to reset */
  usleep(1000*1000);

  /*
   * drain any extraneous input
   */

The fix required in mega-isp is to discard all inbound messages and only respond to one of the three signon attempts:

  uint8_t ch = getch();
  switch (ch) {
  case '0': // signon
    error = 0;
    if (getch() == CRC_EOP) {
      // empty the input stream
      while (0<Serial.available()) getch();
      Serial.print((char)STK_INSYNC);
      Serial.print((char)STK_OK);
    } else {
        error++;
        Serial.print((char)STK_NOSYNC);
    }
    break;

With these two fixes in place I have been able to use the mega2560 board without any modifications as an in circuit programmer for ATmega644PA chip.

Patch files are attached
Command line used was
avrdude -b 9600 -c arduino -p m644p -t -vvvv -P /dev/ttyACM0


Peter Saunderson <peteasa>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #28614:  arduino.c.patch added by peteasa (400B - text/x-patch - patches that fix the communication issue)
file #28615:  ArduinoISP.ino.patch added by peteasa (548B - text/x-patch - patches that fix the communication issue)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by peteasa (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-07-19 peteasa Attached File- Added arduino.c.patch, #28614
        Attached File- Added ArduinoISP.ino.patch, #28615

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code