IDE 1.5.2 back-to-back avrdude commands fail with AVRISPmkII

Burning bootloader with IDE 1.5.2 fails with AVRISPmkII programmers. It will burn bootloader fine with other programmers. This is with a Windows XP platform.

The first avrdude command to erase the flash and set the fuses succeed correctly.
But the second avrdude command to write the flash with the booloader hex file fails with:

avrdude: usb_open(): cannot read serial number "usb_control_msg: sending control message failed, win error: The device is not connected."
avrdude: usb_open(): cannot read product name "usb_control_msg: sending control message failed, win error: The device does not recognize the command."
avrdude: usbdev_open(): USB device has no configuration
avrdude: usbdev_open(): did not find any USB device "usb"

This can be duplicated via commandline with back-to-back avrdude commands. Note that you must copy and paste two avrdude commands.

avrdude -patmega328p -cstk500v2 -Pusb
avrdude -patmega328p -cstk500v2 -Pusb

Results:

C:\Documents and Settings\~\My Documents\Downloads\Arduino\arduino-1.5.2\hardware\tools\avr\etc>..\bin\avrdude -patmega328p -cstk500v2 -Pusb

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e950f

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

C:\Documents and Settings\~\My Documents\Downloads\Arduino\arduino-1.5.2\hardware\tools\avr\etc>..\bin\avrdude -patmega328p -cstk500v2 -Pusb
avrdude: usb_open(): cannot read serial number "usb_control_msg: sending control message failed, win error: The device is not connected."
avrdude: usb_open(): cannot read product name "usb_control_msg: sending control message failed, win error: The device does not recognize the command."
avrdude: usbdev_open(): USB device has no configuration
avrdude: usbdev_open(): did not find any USB device "usb"

This appears to be some limitation with the AVRISPmkII not being able to take two commands too quickly. If you insert a delay between the commands then it succeeds correctly on both commands.
Notice a sleep command was entered before the second command.

C:\Documents and Settings\~\My Documents\Downloads\Arduino\arduino-1.5.2\hardware\tools\avr\etc>..\bin\avrdude -patmega328p -cstk500v2 -Pusb

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e950f

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


C:\Documents and Settings\~\My Documents\Downloads\Arduino\arduino-1.5.2\hardware\tools\avr\etc>sleep 1 & ..\bin\avrdude -patmega328p -cstk500v2 -Pusb

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e950f

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

The IDE 1.5.2 does not have enough of a delay between issuing the two commands during burning bootloader. Previous IDE versions 1.0.5 and below are okay with burning bootloader with AVRISPmkII programmers.

It appears this has been a known issue with avrdude since 2011. It has to do with how avrdude is closing the USB for stk500v2 protocol and the device has to re-enumerate again before the next command.

http://lists.gnu.org/archive/html/avrdude-dev/2011-12/msg00003.html

There is a USB retry patch, but it doesn't look like it was implemented.

The possible workaround is to have the IDE 1.5.2 wait between issuing the avrdude commands.