USB read error under linux

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

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Zero
 
Posts: 30
Joined: Thu Jul 12, 2007 3:47 am

USB read error under linux

Post by Zero »

I just built the board, and after getting missing libusb errors I found a solution to that in another thread here. After adding the libusb compile flags I cleaned, rebuilt, and installed only to get things like:

Code: Select all

avrdude -c usbtiny -p t2313 -F

USB read error: expected 8, got -1
USB read error: expected 8, got -1
avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions

Reading |                                                    | 0% 0.00sUSB read error: expected 8, got -1
USB read error: expected 8, got -1
Reading | #################                                  | 33% 0.00sUSB read error: expected 8, got -1
Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
avrdude: Expected signature for ATtiny2313 is 1E 91 0A
USB read error: expected 8, got -1
USB read error: expected 8, got -1
USB read error: expected 8, got -1
USB read error: expected 8, got -1
USB read error: expected 8, got -1
USB read error: expected 8, got -1
USB read error: expected 8, got -1
USB read error: expected 8, got -1
USB read error: expected 8, got -1
USB read error: expected 128, got -1
avrdude: WARNING: can't read memory for cycle count, rc=-1

USB read error: expected 8, got -1
USB read error: expected 8, got -1
USB read error: expected 8, got -1
USB read error: expected 8, got -1
USB read error: expected 8, got -1
USB read error: expected 8, got -1
USB read error: expected 8, got -1
USB read error: expected 8, got -1
USB read error: expected 8, got -1
avrdude: safemode: Fuses OK

avrdude done.  Thank you.
Same errors regardless of what target board I have hooked up. I always get invalid device signatures and USB read errors. So I rebooted into windows, installed, and tested, and had no errors. I programmed an ATTiny13 and a Mega8 with no problems to speak of. So would anybody have any ideas as to why I get these errors only under Linux (Debian Etch AMD64)?

Any help would be very much appreciated.

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

Post by adafruit »

well for starters you shouldnt really use -F as it is risky and could end up mis-programming a chip.

when this happens try unplugging it and re-plugging it. (to reset it) and try again.

also, try upgrading to the latest version of libusb
http://libusb.sourceforge.net/
and let me know if that helps

Zero
 
Posts: 30
Joined: Thu Jul 12, 2007 3:47 am

Post by Zero »

ladyada wrote:well for starters you shouldnt really use -F as it is risky and could end up mis-programming a chip.

when this happens try unplugging it and re-plugging it. (to reset it) and try again.

also, try upgrading to the latest version of libusb
http://libusb.sourceforge.net/
and let me know if that helps
I don't usually use -F, I just did this time to see if it would get read errors at all phases and perhaps if the read errors were due to the initial inability to confirm the target chip etc. I found the final "Fuses OK" comment in that series rather perplexing, but I'm guessing that's just because it didn't actually set any fuses in the first place.

I'll play with it a bit more today, but I can tell you I already have the latest (stable, V 0.1.12) version of LibUSB and after adding the compile flags I haven't gotten any immediately apparent errors pertaining to it.

Your comment about unplugging it and plugging it back in interested me, as I was simply unplugging the target board and plugging that back in. I'm the type who powers down my STK500 before I take out or insert a chip out of simple paranoia leaving the board warm during insertion or removal could screw something up. I was under the impression it was safe to remove and insert the target board warm on most JTAG programmers, is this a misconception? Should I physically remove the USB connection when switching target boards?

EDIT: With target board remaining plugged into the 6-pin JTAG in same configuration I was able to program in windows, I tried unplugging and plugging back in the USB connection several times, each time running the same check. The result was always:

Code: Select all

avrdude -c usbtiny -p m8

USB read error: expected 8, got -1
USB read error: expected 8, got -1
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

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

Post by adafruit »

Zero wrote:
ladyada wrote: I'll play with it a bit more today, but I can tell you I already have the latest (stable, V 0.1.12) version of LibUSB and after adding the compile flags I haven't gotten any immediately apparent errors pertaining to it.
OK thanks for the info. I havent tested this under linux, just mac and windows ("This is documentation for a simple open-source USB AVR programmer and SPI interface. It is low cost, easy to make, works great with avrdude, is AVRStudio-compatible and tested under Windows and MacOS X. " from http://www.ladyada.net/make/usbtinyisp/) so fyi i cant guarantee it'll work--although there is absolutely no reason why not

i am going to download an ubuntu cd and see if i can get it installed on an extra laptop since i'm curious why this isnt working. it seems to be a libusb thing...but again its really hard to figure out without being in front of said machine!

Zero
 
Posts: 30
Joined: Thu Jul 12, 2007 3:47 am

Post by Zero »

I wouldn't want you to go to too much trouble just for this. It sounds like other Linux users are having success with it, so it may just be me and this particular setup. I'll play around more and inform you if I have any success. Though I do wonder: by the latest version of libusb, did you mean Beta 1.0.0? Or did you mean the stable version (that I have now)?

Anyway, I know the dongle works, and works very well in windows. I've used libusb before in some of my own code, and use a small variety of things that employ it, so I know the current version on my system is functional. But the beta version is apparently entirely different, so if you were using the beta version I'll bet that would explain why it isn't working right there.

Sorry for the trouble, I don't want to take up your time for an issue that may be totally isolated. I guess I was hoping someone would know what I was doing incorrectly right off the bat.

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

Post by adafruit »

yeah it is interesting because well, libusb is -supposed- to just work. and other linux users have had no problem.

only thing i can think of is that when you build avrdude you link against one version of libusb and when you run it its referencing another. the problems you are experiencing happened to me when i accidentally built with one DLL under windows and then ran it with another (due to library path stuff)
the version i have installed is 1.12.1 -but- it shouldnt matter as long as you link/run under the same version....

Zero
 
Posts: 30
Joined: Thu Jul 12, 2007 3:47 am

Post by Zero »

ladyada wrote:...
the version i have installed is 1.12.1 -but- it shouldnt matter as long as you link/run under the same version....
I'm sorry, you must mean 0.1.12. The beta branch is 1.0.x. I'll go ahead and recompile and reinstall from source, then rebuild your patched avrdude and give it another shot. I'm pretty sure I don't have any other versions installed, but perhaps the libraries were built funny or got corrupted at some point.

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

Post by adafruit »

yeah thats probably right, i just looked at the dll version maybe it cant deal with versions less than 0

Zero
 
Posts: 30
Joined: Thu Jul 12, 2007 3:47 am

Post by Zero »

Just tried rebuilding and reinstalling libusb and rebuilding your avrdude. Same result. I doubt you were using the beta, so I'm going to poke around some and see what I can do.

kms
 
Posts: 1
Joined: Fri Jul 13, 2007 11:58 am

Post by kms »

I experienced the "-1" when I didn't have permission to access the USB device file. You might try changing permissions or running avrdude as root. I'm still getting some other errors, but will hopefully figure it out soon. Strace and dmesg are pretty good for debugging, BTW.

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

Post by adafruit »

! that is a good point, i completely forgot that there may be weird permission stuff....

Zero
 
Posts: 30
Joined: Thu Jul 12, 2007 3:47 am

Post by Zero »

Code: Select all

sudo ./avrdude -c usbtiny -p m8
Password:

USB read error: expected 8, got 4
USB read error: expected 8, got 4
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.
... 4! 4 is not -1! That's definitely different, but still not working. Changing permissions now.

Edit: The dongle is showing up as usbdev(P).(I)_ep00, with (P) being the port and (I) being the instance, changing every time I plug it in. So unless it's being mapped to something I'm not aware of, I'm not sure how I could change permissions just for this.

Using strace gives me quite a bit of information, some more interesting tidbits:

From when it grabs the dongle until the end seems to be the most revealing:

Code: Select all

open("/dev/bus/usb/001/002", O_RDWR)    = 3
ioctl(3, USBDEVFS_IOCTL, 0x7fff4cd246c0) = -1 ENOTTY (Inappropriate ioctl for device)
close(3)                                = 0
open("/dev/bus/usb/001/001", O_RDWR)    = 3
ioctl(3, USBDEVFS_IOCTL, 0x7fff4cd246c0) = 4
close(3)                                = 0
open("/dev/bus/usb/001/002", O_RDWR)    = 3
write(2, "\n", 1
)                       = 1
ioctl(3, USBDEVFS_CONTROL, 0x7fff4cd246f0) = 0
nanosleep({0, 50000000}, NULL)          = 0
ioctl(3, USBDEVFS_CONTROL, 0x7fff4cd24680) = 4
write(2, "USB read error: expected 8, got "..., 34USB read error: expected 8, got 4
) = 34
ioctl(3, USBDEVFS_CONTROL, 0x7fff4cd246f0) = 0
ioctl(3, USBDEVFS_CONTROL, 0x7fff4cd246f0) = 0
nanosleep({0, 20000000}, NULL)          = 0
ioctl(3, USBDEVFS_CONTROL, 0x7fff4cd24680) = 4
write(2, "USB read error: expected 8, got "..., 34USB read error: expected 8, got 4
) = 34
write(2, "avrdude: initialization failed, "..., 38avrdude: initialization failed, rc=-1
) = 38
write(2, "         Double check connection"..., 93         Double check connections and try again, or use -F to override
         this check.

) = 93
ioctl(3, USBDEVFS_CONTROL, 0x7fff4cd24720) = 0
close(3)                                = 0
write(2, "\navrdude done.  Thank you.\n\n", 28
avrdude done.  Thank you.

) = 28
exit_group(1)                           = ?
I can provide a full output if needed. There were a few other lines with interesting looking output I wasn't sure about (a lot of ENOENT and ioctl errors).

At this point I'm sorry to say I'm actually quite lost.

Zero
 
Posts: 30
Joined: Thu Jul 12, 2007 3:47 am

Post by Zero »

So at this point I still don't have the programmer running. I've tried modifying the usbtiny avrdude sources to try and get a better idea of just what is going on, but this didn't actually reveal anything that isn't already known about the problem.

Then, looking back at the software page, I noticed an alternative version of the firmware. I grabbed it, and tried the main.hex prebuilt into a new ATTiny2313. I inserted it into the programmer, and got no light and couldn't get recognition of the programmer from the PC. When I cleaned and remade I got:

Code: Select all

 make
avr-gcc -Os -g -Wall -I. -I../usbtiny  -mmcu=attiny2313 -c ../usbtiny/crc.S
avr-gcc -Os -g -Wall -I. -I../usbtiny  -mmcu=attiny2313 -c ../usbtiny/int.S
avr-gcc -Os -g -Wall -I. -I../usbtiny  -mmcu=attiny2313 -c ../usbtiny/usb.c
avr-gcc -Os -g -Wall -I. -I../usbtiny  -mmcu=attiny2313 -c -o main.o main.c
avr-gcc -g -mmcu=attiny2313 -o main.elf crc.o int.o usb.o main.o
text: 2132, data: 2, bss: 60
ERROR: Flash size limit exceeded by 86 bytes.
make: *** [main.hex] Error 1
and of course this didn't work either. Figuring maybe the 1.04 version wasn't finished or something I grabbed 1.0, did the preincluded hex, then remade and got an error of exceeding flash size limits by 82 bytes, both times again no luck. What am I doing wrong?

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

Post by adafruit »

you're not using gcc 3.4.2, which has a better optimizer and is the default install with winavr

however, updating the firmware will guaranteed-not-help you with your problem. its completely unrelated and has to do with resetting during power spikes which is not whats going on with you

Zero
 
Posts: 30
Joined: Thu Jul 12, 2007 3:47 am

Post by Zero »

What about the included .hex file? Should that work? Because after writing it to the new tiny2313 and inserting it into the board, then plugging the board in I get no green light and no recognition from the PC. That's with the preincluded .hex files for both 1.0 and 1.04. Perhaps there's some particular way I should be writing it? Some specific avrdude arguments that need to be passed?

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

Return to “USBtinyISP”