problems with enumeration on virtualbox virtual machines

USB AVR Programmer and SPI interface. Adafruit's USBtinyISP.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mightyohm
 
Posts: 19
Joined: Mon Sep 22, 2008 8:30 pm

problems with enumeration on virtualbox virtual machines

Post by mightyohm »

This is a problem that has been bothering me in various forms for the past year. I am hoping someone may have found a workaround for this issue, or at least can tell me I am not alone. :)

If I try to connect my USBTiny to an Ubuntu virtual machine running in Virtualbox on a Windows 7 64-bit host, the USBTiny locks up and is unavailable to both the client and host OS.

If I then try to select the USBTiny in virtualbox again (Devices -> USB Devices -> USBTiny), I get the attached error message.

I have seen this behavior with Virtualbox on both OSX and Windows hosts, running either Linux or Windows XP virtual machines.

The only combination that I have tried that DOES work is an Ubuntu host running a Windows 7 virtual machine.

I suspect there is a problem with the enumeration process, but I have not had a chance to dig into the USBTiny code or take USB logs, so I can't point to a specific problem yet.
Attachments
VirtualBox - Error 992010 65130 PM.jpg
VirtualBox - Error 992010 65130 PM.jpg (24.81 KiB) Viewed 5426 times

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: problems with enumeration on virtualbox virtual machines

Post by adafruit »

bitbanging/libusb type USB is not liked much by emulated OS's for reasons we dont understand. parallels also has issues.

User avatar
mightyohm
 
Posts: 19
Joined: Mon Sep 22, 2008 8:30 pm

Re: problems with enumeration on virtualbox virtual machines

Post by mightyohm »

Yes. VMware also has problems. The working Virtualbox Linux/Windows combo is definitely the exception, most combinations don't work!

User avatar
mightyohm
 
Posts: 19
Joined: Mon Sep 22, 2008 8:30 pm

Re: problems with enumeration on virtualbox virtual machines

Post by mightyohm »

Found a solution.

The usbtiny project page has a new version of the source (v1.5) that fixes some USB issues. (The USBTiny firmware on adafruit is based on v1.3 of the usbtiny source.)

The author (Dick Streefland) has even added the USBTinyISP to the source tree and has a hex file ready to burn!

The new files can be downloaded here: http://www.xs4all.nl/~dicks/avr/usbtiny/

I burned the main.hex file onto a new ATtiny2313 and sure enough, now the USBTinyISP works within VirtualBox 3.2.8 running Ubuntu 10.04 on a Windows 7 x64 host.
Last edited by mightyohm on Thu Sep 16, 2010 5:08 pm, edited 1 time in total.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: problems with enumeration on virtualbox virtual machines

Post by adafruit »

hey, he didnt tell us! ;) ok will go check it out...

johnybg
 
Posts: 8
Joined: Sat Sep 18, 2010 2:24 pm

Re: problems with enumeration on virtualbox virtual machines

Post by johnybg »

sorry if this a silly question but since my avr programmer is usbtiny how i am supposed to flash its firmware with usbtiny 1.5?

User avatar
mightyohm
 
Posts: 19
Joined: Mon Sep 22, 2008 8:30 pm

Re: problems with enumeration on virtualbox virtual machines

Post by mightyohm »

Buy or find another ATtiny2313 chip and use a breadboard to wire up a simple circuit with a ceramic resonator, 5V supply, and wiring to your USBTinyISP. Flash the 2nd ATtiny2313 and then swap it with the one installed in the usbtinyisp.

johnybg
 
Posts: 8
Joined: Sat Sep 18, 2010 2:24 pm

Re: problems with enumeration on virtualbox virtual machines

Post by johnybg »

thanks :)

AceJohnny
 
Posts: 3
Joined: Fri Sep 10, 2010 4:43 am

Re: problems with enumeration on virtualbox virtual machines

Post by AceJohnny »

I was having this same issue (VBox Ubuntu client on Win7 host). Following this thread, I expected the files on the ladyada.net page to be updated to the working version, but not so (version byte reported by the USB device is 104).

It wasn't entirely clear from the mightyohm post, but the latest usbtiny source (1.6 at time of writing) contains an up-to-date binary for usbtinyusp (in the usbtiny subdir). I recompiled it anyhow (avr-libc 1.7.1, gcc-avr 4.5.3), flashed that onto the chip, and it now works.

adafruit, could you update the ladyada.net page?

AceJohnny
 
Posts: 3
Joined: Fri Sep 10, 2010 4:43 am

Re: problems with enumeration on virtualbox virtual machines

Post by AceJohnny »

(I meant MightOhm's blog post, his post here is more explicit ^^;)

User avatar
ed2013
 
Posts: 7
Joined: Sun Jun 23, 2013 11:24 pm

Re: problems with enumeration on virtualbox virtual machines

Post by ed2013 »

I realize this thread is a couple of years old, but I thought I would add some additional information that might be useful for others that stumble upon it, as did I.

I am running Windows 7 Professional with VirtualBox 5.0.10, running a Virtual Machine with Windows XP, which in turn runs the Arduino Development Environment v1.6.5. I have a Trinket Pro powered via BAT+ from an external source. I have defined a VirtualBox USB filter for the AdaFruit USBtiny device as recommended by others. Uploading a sketch the first time when the USB cable is plugged in usually worked fine. But subsequent upload attempts would fail in various BANNED ways. Only unplugging and re-plugging the USB cable would prepare the Trinket Pro to receive another upload. I have finally determined the reason for this.

By design, the USB device emulation only runs while the bootloader is running. However, after loading the user sketch and the bootloader terminates, the Trinket Pro does not disconnect from the USB. It remains connected, but the host cannot communicate with it due to the bootloader having terminated. This device now connected but unable to communicate causes issues for Windows and VirtualBox. I suspect that this issue is the cause of many of the Trinket/Gemma/etc connectivity problems described in this forum and others, even when powered from only the USB. I see this as a flaw in the bootloader. It should do a usbDeviceDisconnect() just before jumping to the user sketch. The usbDeviceDisconnect() would set the USB D+ and D- lines to a logic zero, putting the bus into the SE0 state, which will disconnect the device if it remains in this state for more than 10ms. The Trinket Pro should remain in this state until the next time that the bootloader runs.

With the code to disconnect from the USB in place, I have had no more USB connectivity issues. When the Trinket Pro reset button is pressed, the USB connection is made, the device connects to the host, it is identified as AdaFruit USBtiny, and VirtualBox attaches the device to the VM. The IDE upload function can be performed. When the upload completes, the Trinket Pro disconnects from the bus, it is disconnected from the VM, and it is no longer visible to the host. No unknown device ever appears, no more intermittent VirtualBox crashes, and re-plugging the USB cable is no longer required. The USBtiny device exists on the USB only for the duration of the sketch upload. Nice and clean, as it should be.

Without a modified bootloader, a usbDeviceDisconnect() emulation could be performed in the setup() section of the sketch. This will solve subsequent connectivity problems once the initial sketch containing this code is uploaded.
      // Note: Pins 2 and 7 are for the Trinket Pro (see schematic)....
      pinMode(2, OUTPUT); digitalWrite(2, LOW);       // Set D+ to logical zero
      pinMode(7, OUTPUT); digitalWrite(7, LOW);       // Set D- to logical zero
      // USB is now in SE0 state, and Trinket Pro will now be disconnected from the USB

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: problems with enumeration on virtualbox virtual machines

Post by adafruit2 »

huh thats interesting . did you notice it made things any different on nonVirtualbox machines? e.g. native USB

User avatar
ed2013
 
Posts: 7
Joined: Sun Jun 23, 2013 11:24 pm

Re: problems with enumeration on virtualbox virtual machines

Post by ed2013 »

Short answer: Yes.   Longer answer....

I have not used the Arduino IDE natively, only under a VirtualBox VM. However, any time that the Trinket Pro is connected to the USB when the bootloader is not running will cause issues on any host to which it is attached. The (required) R3 pull-up resistor on the USB D- causes the device to be considered connected as long as the cable is plugged in. If the host attempts to communicate with the device when the bootloader is not running, it will not be able to do so, and it will result in USB communication errors. On Windows, a pop-up message will appear in the Task Bar Notification Area ("USB Device Not Recognized"), and an "Unknown Device" will appear in Device Manager. Depending on timing of USB events (eg, cable re-plugged, or Trinket Reset is pressed), communication errors will occur, and there might be further undesirable effects.

If the bootloader were to disconnect from the USB just before it terminates, these problems can be avoided. The preferred method of doing this would be to disconnect the R3 pull-up resistor when the USB connection is to be terminated (and reconnecting it when the USB connection is to be made). However, this would require a board spin and use up another Atmega328p pin, and would not help existing devices. The software method I suggested will also disconnect the device from the USB when the bootloader terminates. This solves most of the USB communications issues. I say most, because the R3 pull-up resistor is still connected, and as soon as the Reset button on the Trinket is pressed, the device is connected to the USB again (before the bootloader is running). Depending on how short or long the Reset button is held down, USB communications errors could occur, again causing the above-mentioned issues. Pressing the button for just the right amount of time can be tricky. Too short, and errors may occur. Too long, and errors will occur. I have resolved this issue by using the RST pin on the Trinket Pro with an external button and R/C to generate a fixed-length reset pulse of about 200ms.

With this modified Reset circuit, and the USB disconnect performed at bootloader termination, I have had no indications from Windows regarding USB communications issues. The Trinket is visible to the host only while the bootloader is running, and it seems to work with all USB 2.0 and 3.0 ports that I tried, as well as with a USB 1.0 hub.

Locked
Please be positive and constructive with your questions and comments.

Return to “USBtinyISP”