avrdudes / avrdude

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

[patch #7896] DFU FLIPv2 programming support #665

Closed avrs-admin closed 2 years ago

avrs-admin commented 2 years ago

Sat 01 Dec 2012 09:01:31 AM UTC

The attached patch adds FLIPv2 (AVR4023) suppport, allowing EEPROM and Application Flash to be programmed on USB-capable XMEGA parts that have a pre-installed bootloader.

Tested with XMEGA128A3U and XMEGA128A4U.

file #27009: flip2.patch

This issue was migrated from https://savannah.nongnu.org/patch/?7896

avrs-admin commented 2 years ago

Joerg Wunsch Tue 12 Mar 2013 07:33:17 AM UTC

Thanks for the patch, Kirill!  I just tried it, using an ATmega32U2.

Here are some remarks.  First, if I don't have the target plugged in, I get:

% ./avrdude -C avrdude.conf -c flip2 -p m32u2 -t

avrdude: Error: No matching USB device found
avrdude: AVR device initialized and ready to accept instructions

Reading |                                                    | 0% 0.00savrdude: error reading signature data for part "ATmega32U2", rc=-1
avrdude: error reading signature data, rc=-1

avrdude done.  Thank you.

I think it should bail out there before proceeding to read the signature.

Second, after plugging in the controller, I get (on FreeBSD):

% ./avrdude -C avrdude.conf -c flip2 -p m32u2 -t

avrdude: Warning: USB bDeviceClass = 255 (expected 0)
avrdude: Warning: USB bDeviceSubClass = 1 (expected 0)
avrdude: Warning: USB bInterfaceClass = 0 (expected 255)
avrdude: Error: DFU_DNLOAD failed: Unknown error
avrdude: Error: DFU status ERR_WRITE
avrdude: Error: Failed to read 0x0004 bytes at 0x0000
avrdude: AVR device initialized and ready to accept instructions

Reading |                                                    | 0% 0.00savrdude: error reading signature data for part "ATmega32U2", rc=-1
avrdude: error reading signature data, rc=-1

avrdude done.  Thank you.

So, at least for the USB megaAVR devices, something's still wrong.

(Yes, I did add the USB PID of the ATmega32U2 to avrdude.conf before.)

I think, all new files should get your copyright, with the current year, not anybody else's.

For reference, here are the descriptors I can read out from the device:

bLength = 0x0012
bDescriptorType = 0x0001
bcdUSB = 0x0200
bDeviceClass = 0x00ff
bDeviceSubClass = 0x0001
bDeviceProtocol = 0x0000
bMaxPacketSize0 = 0x0020
idVendor = 0x03eb
idProduct = 0x2ff0
bcdDevice = 0x0000
iManufacturer = 0x0001  <ATMEL>
iProduct = 0x0002  <ATmega32U2 DFU>
iSerialNumber = 0x0000  <no string>
bNumConfigurations = 0x0001

Configuration index 0

bLength = 0x0009
bDescriptorType = 0x0002
wTotalLength = 0x0012
bNumInterfaces = 0x0001
bConfigurationValue = 0x0001
iConfiguration = 0x0000  <no string>
bmAttributes = 0x0080
bMaxPower = 0x0032

Interface 0
bLength = 0x0009
bDescriptorType = 0x0004
bInterfaceNumber = 0x0000
bAlternateSetting = 0x0000
bNumEndpoints = 0x0000
bInterfaceClass = 0x0000
bInterfaceSubClass = 0x0000
bInterfaceProtocol = 0x0000
iInterface = 0x0000  <no string>
avrs-admin commented 2 years ago

Joerg Wunsch Tue 12 Mar 2013 10:58:14 AM UTC

I just tested it under Linux.  Result:

% sudo ./avrdude -C avrdude.conf -c flip2 -p atmega32u2 -v

avrdude: Version 5.11svn, compiled on Mar 12 2013 at 11:34:51
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch

...
Programmer Type : flip2
Description     : FLIPv2 USB DFU protocol (AVR4023)

avrdude: Found VID=0x03eb PID=0x2ff0 at 003:003

At that point, it just exits.

I guess it needs a bit of further debugging before we can commit it.

avrs-admin commented 2 years ago

Joerg Wunsch Tue 12 Mar 2013 01:58:19 PM UTC

It stops at that point under Linux since it segfaults.  This is because there are zero endpoint descriptors present, so

found->config->interface->altsetting->endpoint

equals 0 here:

memcpy(&dfu->endp_desc, found->config->interface->altsetting->endpoint,
sizeof(dfu->endp_desc));

If I conditionalize that memcpy() on ...->endpoint being != 0, the Linux behaviour resembles the one under FreeBSD:

avrdude: Warning: USB bDeviceClass = 255 (expected 0)
avrdude: Warning: USB bDeviceSubClass = 1 (expected 0)
avrdude: Warning: USB bInterfaceClass = 0 (expected 255)
avrdude: Warning: Failed to read USB device string 1: error sending control message: Broken pipe
avrdude: Warning: Failed to read USB device string 2: error sending control message: Broken pipe
avrdude: Error: DFU_DNLOAD failed: error sending control message: Broken pipe
avrdude: Error: Failed to get DFU status: error sending control message: Broken pipe
avrdude: Error: Failed to set memory unit 0x05 (signature)
avrdude: AVR device initialized and ready to accept instructions

Reading |                                                    | 0% 0.00savrdude: error reading signature data for part "ATmega32U2", rc=-1
avrdude: error reading signature data, rc=-1

avrdude done.  Thank you.
avrs-admin commented 2 years ago

Joerg Wunsch Fri 17 Jan 2014 04:57:27 PM UTC

Done (with a few minor changes), thanks!

I also took this occasion to clone the FLIPv2 implementation into a FLIPv1 one (for AT90USB and ATmegaU* devices), so we cover all FLIP/DFU-capable AVR devices now.