Created by: gwideman, Apr 13, 2015 5:14 pm
Revised by: gwideman, Apr 16, 2015 1:24 am (19 revisions)

Overview

This page concerns installing USB drivers on Windows 7-64 for the Atmel AVRISP mkII programmer device. These steps will be similar for other device programmers that rely on libusb to work with avrdude.
This task is more convoluted than it might be because:
  • libusb: Many tutorials suggest programming using avrdude software (possibly via the WinAVR suite), which needs to talk to USB via a libusb API, leading users to attempt to install a libusb-related driver.
    • There have been a number of libusb projects which diverged. merged, and generally left a confusing trail.
    • for some period in the past, libusb's libusb0.sys Windows driver was not able to run on Windows 7-64 (or later).
  • Atmel Studio installs drivers from Jungo, which don't automatically coexist with libusb-based drivers.
    • If Atmel Studio is installed first, the typical "how to install libusb" tutorial will disrupt Atmel's Jungo drivers.
    • If Atmel Studio is installed second, it will disrupt the previously installed libusb drivers.
In this article I take some notes as I step through the process of getting these drivers to coexist properly.

Summary

This article shows how to:
  • Install stand-alone libusb-win32 driver for AVRISP mkII
  • Use avrdude to exercise the driver
  • Install Atmel Studio and its Jungo drivers
    • ... which preempts the stand-alone libusb-win32 driver, and hence knocks out avrdude
  • Install libusb-win32 filter driver for AVRISP mkII
    • ... which cooperates with Jungo drivers.

End result

Both Atmel Studio and avrdude are able to talk to AVRISP mkII

A word about nomenclature

In the following article, and in many pages you can find via google, there is much talk about this or that driver. This is a complicated area in its full technical detail, but a couple of pointers can help in following the conversation.
  • In general, there are two main parts involved:
    • The "actual driver", which is a piece of code, typically a something.sys file, that Windows invokes when it sees that a particular kind of hardware device has been plugged in (or is recognized during start up). Most devices have some sort of id or other way of detecting them, which Windows knows to associate with a particular driver that contains functions to interact with that hardware. The driver runs as long as the device is plugged in, processing messages from the OS to manipulate the device, and responding to activities from the device. So far as applications are concerned, the driver, in combination with OS APIs, looks like an OS service that the application can talk to.
    • A "library" by which an application program can access the hardware (it provides an API). This is typically a file called something.dll. Some such APIs come with Windows, others are provided by a device manufacturer. In effect, an instance of the library becomes part of the application while the application is running, implementing functions that can communicate with the 'service' provided by the .sys driver.
  • "Installing a driver": what does an installer actually do?
    • The installer must first ascertain whether the necessary something.sys and something.dll files are present at specific locations under C:\Windows, and if not, copy them to the necessary locations
    • The installer must give Windows (ultimately, the registry) particular configuration information appropriate to this particular hardware device, including its Vendor Id and Product Id (so Windows can recognize it), and selects particular options that the driver offers to handle variations of hardware.
  • So, the phrase "installing a driver"
    • may or may not mean actually adding a .sys and/or .dll file to Windows system directories. Those files may be there already, if they are provided with Windows, or have been installed previously by a similar device installer.
    • always involves adding configuration information specifying to Windows what .sys and .dll files to use (with what settings) when a certain hardware device is connected.
  • In most cases, the effect of installation can be seen in the Device Manager, which is highly useful in determining current state of the system, and success or failure of an installation.

libusb landscape

Following the steps in this article there shouldn't be a lot of fumbling about with wrong files. However, in order to make some sense of the landscape, the following notes may be useful.
  • libusb refers to a number of projects that, over the years, have worked on providing an open-source and cross-platform USB apparatus. These projects have diverged and converged, which has left in its wake some confusion of conflicting and obsolete tutorials, forum postings etc.
  • libusb also refers to an API (and drivers/libraries to implement it) by which application programs (such as avrdude) can talk to a device via USB (such as a programmer device). (Actually two APIs, an older 0.1 API, and newer 1.0 API.)
    • With libusb being a cross-platform API, an application can be written so that it runs on multiple platforms so long as that API is installed on the platform. The application doesn't need separate versions to work with each OS's USB APIs.
  • The API that avrdude wants is libusb-0.1. This is implemented in components that have names libusb0.sys and libusb0.dll, the '0' (zero) indicating the 0.1 API. The project that implements this on Windows is called libusb-win32: http://sourceforge.net/p/libusb-win32/wiki/Home/ (So far as I am aware, 'libusb-win32' is only the project name; there are no actual components named 'libusb-win32').
  • Some confusion derives from there being multiple versions of these files in the wild, not distinguished by name. However, they do have version identifiers that can be seen in Explorer > [right-click on file] > Properties > Details. Current version of libusb0.sys and .dll is 1.2.6.
    • There are also separate versions of these files for 32-bit and 64-bit windows. Undistinguished so far as I can tell, except for file size. See table later in this article.

Starting point

With AVRISP mkII plugged in to a USB port, and no driver available, Device Manager should show the AVRISP under the "Other devices" category, marked with a yellow caution triangle:
dev-mgr-avrisp_no_driver.png
I am also going to assume that there's some sort of target board available, if only an AVR on a breadboard with an ISP connector and power source, and an LED or two to display go/no-go of a basic blink sketch.
avrisp-attiny85-01.jpg

AVRISP mkII indications

The online user guide is here: http://www.atmel.com/webdoc/avrispmkii/index.html, however it describes installation as "requiring Atmel Studio 4.12 or later", which is far out-of-date, and also misleading. However, much of the manual is useful, including details of LED indications, firmware upgrade and so on.
LED next to USB socket:
  • Indicates AVRISP plugged in and receiving power.
LED next to ISP cable:
LED
Description
Red
Idle, target disconnected or connected but no power
Red blink
Problem on target such as short circuit
Green
Idle, signals to/from target seem sensible
Orange
Busy programming
Orange blink
Plug to target wrong-way-round, or incorrect pull-up on reset line
Red-Orange blink
Firmware upgrade mode

libusb-win32 drivers

Get libusb-win32

Run inf-wizard.exe

Double-click ...\libusb-win32\libusb-win32-bin-1.2.6.0\bin\inf-wizard, follow instructions:
Step
Description
inf-wiz-01.png
Screen 1: Wizard says: Make sure device is plugged in. (Could verify in Device Manager that AVRISP mkII shows up, and has yellow triangle indication.)
Screen 2: wizard offers list of devices to choose from. AVRISP mkII appears, select it. (VendorId: 0x03EB, ProductId: 0x2104)
inf-wiz-02.png
Screen 3: Device Configuration info, probably no need to change.
inf-wiz-04.png
Screen 4: Choose directory in which to save generated inf file and copies of libusb0.dll and libusb0.sys, ready for install.
Screen 5: Wizard offers to "Install now". yes... give permission to install software from unknown source... done
inf-wiz-install-01.png
...... inf-wiz-install-02.png
dev-mgr-avrisp-libusb.png
Device Manager now shows a "libusb-win32 devices" category, with AVRISP mkII as it's only child. (And no error indication.)

Test using avrdude

  • avrdude is already installed by the Arduino environment, so I just used that one.
  • avrdude requires an argument telling where to find avrdude.conf. So I use avrdude.bat, which is simply:
    • avrdude -C[C:\path\to\avrdude.conf] %*
  • It would be good to have on hand some known-good hex files for your target processor. Simple "blink" code at a couple of different rates would allow verifying programming steps.
Step
Description
Plug AVRISP in to proto board
Board has ATTINY85, ISP connector, and also its own 4.5V power supply (3 x AA batteries).
AVRISP mkII has green LED inside case near USB indicating USB power.
LED near ISP cable:
  • With no target plugged in -- Red
  • With target plugged in and powered -- Green -- OK!
Try an avrdude "get info" command
avrdude.bat -v -p t85 -c avrispmkII -P usb -n
Result: informational output about target device.
NOTE: usb in lower case, otherwise you get a super helpful error message...
FAIL: "avrdude: ser_open(): can't open device "USB": The system cannot find the file specified."
Try avrdude programming command
avrdude.bat -v -p t85 -c avrispmkII -P usb -U flash:w:test.hex:i
Flicker of activity, some scrolling output... verifying... Works!

Uninstalling libusb-win32 driver

To uninstall the libusb-win32 driver, in Device Manager, select the AVRISP mkII item, right-click, and select Uninstall. Subsequent step offers the option of deleting the driver if you wish.

Installing Atmel Studio

In the following, I step through the installation of AVR Studio, having already installed a libusb driver.
  • I expect that Atmel Studio's Jungo drivers will preempt the libusb0 driver as the handler for AVRISP mkII.
    • Then I can show steps to recover from that situation
  • Of course, it's not necessary to install the libusb driver first, nor is it necessary to uninstall the libusb driver first

Starting Point

  • The libusb driver was installed (but this is not a requirement).
  • I unplugged the AVRISP, so that the existing libusb driver would not be active during the Atmel Studio install. Not sure if that's important.

Get Atmel Studio

  • http://www.atmel.com/microsite/atmel_studio6/
  • I got Atmel Studio 6.2 so2 build 1563, for what it's worth.
    • Plus Atmel USB Driver Installer 7.0.712 "The latest USB drivers from Atmel, containing fixes and updates that did not make it into Atmel Studio 6.2 Sp2 (build 1563)."
      • Which suggests drivers come with Atmel Studio, but should be skipped in preference for this installer package.
  • Run Atmel Studio installer
    • Takes a while, since it's based on MS Visual Studio
    • atmel-studio-install-01.png
    • If you change focus to other windows while waiting, check periodically for installer windows that may have appeared behind.
    • Visual Studio 2010 Shell Setup shows some windows with some info, and options to check, license agreement
      • Installer skipped installing some .NET framework stuff, as it was already in place.
      • No choice of setup location, so must have adequate space on C:
      • I chose "custom" install so I could see what features it was going to install -- and it only offered MS Visual Studio 2008 Shell. (That was a puzzle -- was this a mistaken label for 2010 Shell, or in addition to 2010 Shell?)
      • "Installing Components" phase took a couple of minutes
    • Atmel Studio installer didn't offer an option to not install Atmel USB Driver, so I let it install. (Actually, it did offer a choice of location, so I guess it could be cancelled at that stage.)
      • Prompts for trust Jungo
      • Prompts for trust Atmel Norway
    • FINALLY gets to installing Atmel Studio 6 (ie: extension to Visual Studio)
      • Prompts for location, I chose standard
      • Lists features it's going to install
        • Of course, installs another copy of AVRGCC toolchain, also ARM_GCC toolchain
      • Took 5 to 10 minutes
      • Offers to associate .c, .s, .asm, .h files with Atmel Studio. I deselected that, since i want those associated with desktop development instead.

Test AVRISP driver(s)

  • Plug in AVRISP
    • Tray notification that driver successfully installed.

Device manager:

Adds category 'Jungo Connectivity', with AVRISP mkII and WinDriver items.
dev-mgr-avrisp-jungo.png

Test avrdude connectivity

Command: avrdude.bat -v -p t85 -c avrispmkII -P usb -n
Response: usbdev_open(): did not find any USB device "usb"
As expected, Atmel Studio's installation of Jungo drivers configures Windows USB settings so that it's a Jungo driver that Windows loads for AVRISP, preempting libusb.
So... if avrdude is to be used in future, need to fix that -- in a later step.

Test Atmel Studio connectivity: Fails due to problem with install!

  • Open Atmel Studio
    • Waiting............. arg popup BEHIND the Atmel banner... "Only some of the MS VS 2010 products on this computer have been upgraded since SP1. None will work correctly until all have been upgraded. To upgrade, close all VS products and then install MS VS 2010 SP1, shich you can download here [link]. If Setup starts in Maintenance Mode, select Repair. Atmel Studio will now close." Grrrrrr.
      • Closing dialog doesn't actually get rid of ATMEL Studio installed banner. WTF? Went to Task Manager and killed AtmelSplash.exe.
    • VS10 SP1 link leads to a download for VS10sp1-KB983509.exe, which I already downloaded previously and presumably installed already (I do have regular VS2010 installed). So this suggests that it's Atmel Studio that hasn't been upgraded. Grrrrrr.
  • Run VS10sp1-KB983509.exe
    • Screen 1 options: Reapply MS VS 2010 SP1, or Remove same. Title says "Maintenance". Is this the "Maintenance Mode" that Atmel instructions say not to use?
      • There doesn't seem to be any option to "Repair"
      • I selected Reapply, and Next. Hourglass of Wait.
      • After couple of minutes (!) dialog changes to "Reapplication Progress".
        • Silverlight 4 SDK dialog appears: "the feature you are trying to use is on a network resource that is unavailable. Click OK to try again, or enter an alternate path to a folder containing the installation package silverlight_sdk.msi" in the box below." (And then the box below shows a path on C:, obviously not a "network resource". WTF?
          • After a couple of tries I hit cancel in hopes that it would just cancel. But instead the *&^%$ installer embarks on ROLLING BACK SP1. WTF!
          • And now it's stuck trying to rollback... with the progress bar going nowhere.
            • And now the UNINSTALL is throwing a dialog that it can't fine the network resource for DACFramework_enu.msi. What a heap of crap. I hit Cancel. Same for a bunch more components.
        • My hypothesis is that VS2010 SP1 installer is BROKEN with regards to understanding options that you elected not to install with the original install of VS 2010.
      • Despite having worked for 20 minutes to try to install SP1, and then roll it back, the final dialog says "SP1 installation completed".
      • Oh, and now it wants a restart. Thanks a bunch, Microsoft!
  • But before restarting, let's see if Atmel Studio now runs...
    • Yes it does! And the first message box is... "There are new updates...Atmel Software Framework". Sigh.

Fix botched Visual Studio 2010 SP1 install

  • I reran VS10sp1-KB983509.exe, in which "Reapply" again failed, looking for components. Rather than wait for it to roll back, I just hit the cancel button. Not knowing whether that would leave things in a hopeless state.
  • I noted various advice that said to uninstall SP1 to make a fresh start which might succeed. And then other advice that says uninstalling SP1 may so corrupt VS2010 that it would not be possible to reinstall SP1:
  • vs2010SP1-removal-warning.png
  • "The readme" is here": VS2010SP1_en-US.htm, (which weirdly wants to download rather than just open), which gives a procedure for downloading the entire file layout that the SP1 installer is looking for, which might allow the SP1 installer to complete.
    • cd to the directory containing VS10sp1-KB983509.exe
    • VS10sp1-KB983509.exe /createlayout "%CD%\VS2010SP1"
      • Note: the readme incorrectly displays this command as though the SP1 installer is called setup.exe.
    • This command downloads 1.5 Gbytes... so it takes a while.
  • Reran VS10sp1-KB983509.exe
    • Prompts m-a-n-y times for files that it needs. These are actually all in the downloaded file layout, but apparently the installer isn't smart enough to either find that, or remember the location when you tell it the first time. So you have to sit there manually entering the location for every required file.
  • The SP1 installer eventually finished and reported success.
Results:
  • The previously installed full Visual Studio 2010 at least opens successfully, and About shows it includes SP1. Haven't tried doing much with it yet.
  • Next: Test Atmel Studio...

Test Atmel Studio ability to connect to AVRISP and use it to program

  • Plug in AVRISP mkII, and attach it to test board with ATtiny85, and power on that board.
  • Atmel Studio
    • Tools > Device Programming
      • Tool: AVRISP mkII 00200202292 appears on dropdown, select
      • Device: I selected ATtiny85 (corresponding to my test board)
      • Interface: ISP
      • Apply button > Populates rest of Dialog's UI, and allows:
        • Device Information > Read
        • atmel-studio-dev-prog-dev-info01.png
        • Memories panel allows programming from a hex file:
        • atmel-studio-dev-prog-mems01.png
        • Program button > succeeds, ATtiny runs code. Yay!

Reinstating libusb (avrdude) access to AVRISP

The gist of the following procedure: the Jungo driver has taken over the duty of responding to an AVRISP being plugged in, and we want to leave that in place. To that apparatus we want to add a libusb-style filter driver which communicates with the AVRISP via the Jungo driver. In essence, this provides a libusb-0.1 API (that avrdude needs), while delegating the actual USB communication to Jungo.
So, this should be as simple as running the filter wizard that comes with the libusb-win32 driver package.But...
  • I've read advice that avrdude might latch on to some vestigial libusb dll library, instead of the filter driver that the filter driver installs.
    • I'm pretty sure that the main risk here is if avrdude came with an older libusb0.dll (because I'm fairly sure it doesn't come with the driver libusb0.sys file per se).
    • It's not clear to me if it's the DLL that we should worry about, or the .sys file
      • I'm pretty sure that the libusb0.sys file provides both full driver and also filter functions, and that the difference will be in how the installation tells Windows to associate the device (AVRISP mkII) with a driver stack which includes either the full driver functions, or the filter driver functions.
        • So as far as files are concerned, I don't believe that we're looking to replace any files, just make sure that a current libusb0.sys and libusb0.dll are at whatever location they need to be.
    • Can't just delete existing libusb-related .dll's and .sys's willy-nilly, as there may be other devices using them.

Starting state

First check what libusb-anything files are already in place. Info from Explorer > right-click > Properties > Details.
File
Folder
Version
Size
Descr


C:\Windows\




libusb0.dll
System32\DriverStore\FileRepository\avrisp_mkii.inf_amd64_neutral_853c1b62d99cca64\amd64\
1.2.6
76,384
libusb-win32 DLL

libusb0.dll
System32\
1.2.6
76,384
libusb-win32 DLL

libusb0.dll
SysWOW64\
1.2.6
67,680
libusb-win32 DLL

libusb0_x86.dll
System32\DriverStore\FileRepository\avrisp_mkii.inf_amd64_neutral_853c1b62d99cca64\x86\
1.2.6
67,680
libusb-win32 DLL







libusb0.sys
System32\drivers\
1.2.6
52,832
LibUSB-Win32 - Kernel Driver

libusb0.sys
SysWOW64\drivers\
1.2.6
42,592
LibUSB-Win32 - Kernel Driver

libusb0.sys
System32\DriverStore\FileRepository\avrisp_mkii.inf_amd64_neutral_853c1b62d99cca64\amd64\
1.2.6
52,832
LibUSB-Win32 - Kernel Driver








C:\Program Files (x86)\Arduino\




libusb0.dll
hardware\tools\avr\bin\
1.2.6
67,680
libusb-win32 DLL

libusb0.dll
.\
0.1.12.1
43,520
LibUSB-Win32 - DLL








C:\Program Files (x86)\Atmel\Atmel USB Drivers\libUSB0\




libusb0.dll
amd64\
1.2.6
76,384 bytes
libusb-win32 - DLL

libusb0.dll
x86\
1.2.6
67,680
libusb-win32 - DLL

libusb0.sys
amd64\
1.2.6
52,832
LibUSB-Win32 - Kernel Driver

libusb0.sys
x86\
1.2.6
42,592
LibUSB-Win32 - Kernel Driver


others for ia64




So the main oddities are:
  • Under C:\Windows\, both libusb0.dll and libusb0.sys have two "version 1.2.6" variants, of different sizes, possibly compiled for 32 vs 64 bit? Confirmed by the sizes of the same files within the Atmel directory, stored in folders by CPU or OS.
  • There's an odd libusb0.dll (version 0.1.12.1) in the Arduino home directory. Not sure what that's about.
    • http://sourceforge.net/p/libusb-win32/wiki/Home/ says: "Versions up until 0.1.12.2 have serious bugs related to the filter drivers under Vista and Windows 7 and some XP installations." Perhaps this oddball libusb.dll remains in the Arduino install from some earlier edition.
  • For avrdude, the most likely source of trouble would be from the libusb0.dll in the same folder as avrdude.exe. However, it's the same version as the ones in the Windows folder, and that we might install, so I think not a problem.
  • If Atmel includes libusb drivers, I suppose there's some possibility that Atmel includes a way to install them in a way compatible with its own Jungo drivers? Don't know how to pursue that.

Conclusion

I decided not to delete any of the libusb-related files that were already in place. I don't believe that a different version of either libusb0.dll or libusb0.sys is needed for filter operation as opposed to normal operation.

Run libusb filter wizard

Step
Descr
dev-mgr-avrisp-jungo.png
Make sure AVRISP is plugged in, and showing in device manager under Jungo.
filt-wiz-01.png
Launch ...\libusb-win32\libusb-win32-bin-1.2.6.0\bin\amd64\install-filter-win.exe.
Select install
filt-wiz-02.png
Select device to add filter driver for.
Click Install
filt-wiz-03.png

Test using libusb-supplied tests

  • Launch ...\libusb-win32\libusb-win32-bin-1.2.6.0\bin\amd64\testlibusb-win.exe
filt-wiz-04-test.png
... which looks plausible.

Result in Device Manager

No new item appears in the main Device Manager tree. I.e.: The filter installation does not reinstate the AVRISP mkII item under the libusb-win32 category. Instead, the filter driver appears as an additional driver file in the Driver Details for the Jungo driver item.
dev-mgr-jungo-plus-libusb0.png
The gist of this: Windows now knows that when an AVRISP mkII is plugged in, Windows should invoke Jungo's windrv6.sys to manage the AVRISP, and also invoke libusb0.sys which offers a bridge ('filter') by which libusb0.dll can talk to windrv6.sys and thus to the AVRISP.

Test using avrdude

  • Command: avrdude.bat -v -p t85 -c avrispmkII -P usb -U flash:w:test.hex:i
  • Result: Success
Yay!

Additional References