Calendar

October 2018
M T W T F S S
« Sep    
1234567
891011121314
15161718192021
22232425262728
293031  

Categories

Active supporter of WikiPedia
Support Wikipedia

Geocaching

Profile for uwezi

Hacking an AVR programmer

(see also my recent appendix to this topic: Hacking an AVR programmer II – especially if you have an ATmega88-based programmer!)

On eBay I recently purchased a set of cute small USB AVR programmers which I intend to use in the course 1TE663 Microcontroller Programming at Uppsala University.

MK-USBISP-V3.00 programmer in an aluminum shell on eBay.


After waiting for one month for the delivery from China the package finally arrived today. Unlike other programmers which I purchased before, these come with a sturdy aluminum shell and in happy colors.

However, connecting the first programmer to my PC brought me quickly back to earth – it was not recognized as an USBasp. OK, it would not be the first delivery from China with broken or counterfeit electronics, so I tested the second one…

At that time I got a bit confused, because the programmer registered as an HID unit on the USB with vid=0x03EB & pid=0xc8b4. Not as an USBasp with vid=0x16c0 & pid=0x05dc.

This is the point where I usually ask Google. So I did and I found some threads discussing the same issue and pointing out, that these programmers needed a different software and were not at all compatible with avrdude. BAD!

But of course, one should be able to reprogram the programmer using another programmer. At my home this is not a henn and egg problem, since I have accumulated several AVR programmers.

Ok, I downloaded the USBasp firmware from Thomas Fischl, flashed the programmer after inserting the self-programming jumper:

Self-programming jumper on the MK-USBISP-V3.00 AVR programmer.

Since the original firmware is protected by the lock-bit fuses, I had to fully erase the chip first, then set the fuses correctly to HFUSE=0xc9 LFUSE=0xef and then flash the .hex file. I tried first the 2009-firmware from Thomas Fischl and the first observation was that instead of the red LED which was on previously, now the programmer showed a blue light.

But: Windows would not at all recognize this device as any USB device. Nothing showed up. I got confused. I tried both WinXP and Win7 – to no avail. Well, perhaps this programmer was not hardware compatible to the USBasp? Let’s have a look…

AVR programmer MK-USBISP-V3.00: component side.


AVR programmer MK-USBISP-V3.00: solder side.

There are some tiny, yet important, differences to the original USBasp programmer: in the USBasp USB-D- is connected to pin PB0, USB-D+ to PB1 and PD2/INT0. Here also USB-D- was connected to a pin on port D: PD3/INT1. Well, this should not really make a difference, and I continued my search for differences. OK, for some reason, also the LEDs are connected in parallel to 2 port pins each – so what…

In despair I decided to look into the source code of the USBasp firmware. The header files: OK – pin assignments were as expected, nothing special here. But let’s wait, where is the definition of the utilization of port D? Well, it was in the main.c file:

int main(void) {
  uchar i, j;

  /* no pullups on USB and ISP pins */
  PORTD = 0;
  PORTB = 0;
  /* all outputs except PD2 = INT0 */
  DDRD = ~(1 << 2);

hey – wait a second? All pins of port D are defined as output, except for PD2/INT0? I always tell my students to only define pins as output, which are really used as output… And what happens here?

Since the modified design also connected USB-D- to PD3/INT1, the rather aggressive definition of output pins leads to a unsolvable conflict, when suddenly PD2 is driving against the USB signals from the host!

Changing this little piece of code solved the problem. Rather conservative I set all pins of port D as input (none of them is currently used as output!):

int main(void) {
  uchar i, j;

  /* no pullups on USB and ISP pins */
  PORTD = 0;
  PORTB = 0;
  /* all PDx input */
  /* MK-USBISP v3.0 */
  DDRD = 0x00;

I compiled the code, flashed it onto the AVR programmer using another AVR programmer
…and behold: it works!

I will contact Thomas Fischl and tell him about this observation – perhaps the modification will be implemented in the distributed firmware on his homepage.

Here is a .zip-archive of the modified firmware. The .hex file for use with an ATmega8 is found in the default subdirectory.
Download ZIP archive: 20130212_mega8_usbisp

154 comments to Hacking an AVR programmer

  • […] статью, а так же переработанный исходник в Atmel Studio 4. Hacking AVR programmer, судя по всему была проблема с этим программатором в […]

  • […] GreenPhotons: Hacking an AVR programmer […]

  • […] This is a follow-up of my most popular post, Hacking an AVR programmer. […]

  • uwezi

    IMPORTANT NOTE

    For everyone who has problems with programmers which are using the ATmega88 instead of an ATmega8(L/P/…):

    I just bricked (it seems) an USB programmer of my own design, where I used an ATmega88. It is completely unresponsive after flashing the Fischl firmware from 2011, even though it uses Thomas Fischl’s exact board layout.

    I am not yet sure why or even how this could happen – the chip should always be responding to the serial programming commands unless you disable serial programming with the corresponding fuse. However, I only uploaded the .hex file with the flash code without touching the fuses.

    I hope that this will help me diagnosing the ATmega88-related problems reported here in the comments, but first I will replace the ATmega88 with an ATmega8 and try again…

    Uwe.

  • Roman

    i got v4.0 dongle – it uses atmega88, i used the updated firmware and fuses, but still can’t make it to work

  • […] Most of the time I design and debug my AVR projects on solderless breadboards nowadays. And for that I have been using some different types of programmers by now: starting with the good old STK500, to different versions of USBasp clones from Chinese sellers on eBay. […]

  • Toygar

    Hi there i have v3.02 and i try orginal usbasp firmware , your modified firmware and Atmega88 modified firmware. Your firmware and Atmega88 got bluelight but my pc says (win 8.1 ) this device not recgonized may be it corrupted. What can i do ?

    and Lfuse : EF
    HFuse C9
    E Fuse 01
    LB 3f it is correct ?

    i don’t set LB and E fuse. Only L and H.

    Thanks for article.

    • Toygar

      Hi there i used Fernando’s Hex File and LFuse FF HFuse DF

      it is OK ! USBasp detecting by my pc.

      Thanks for all things and this article.

      Thank you very much 🙂

  • Shyam

    I have USBISP programmer for 89S52 and AVR which has 12MHz operating Atmega8 chip and 6 pin header for ISP programming, for which I do not have source code. I will like to get source code in HEX and C. I want to program in another Atmega8 to replace the chip and perhaps do some code modifications also.

    This is student project work and I want them to try this.

    Thanks.

    Shyam

    • uwezi

      You should check the exact layout of your programmer and see if it matches the Fischl AVR-asp. In that case you can find the source code and the .hex file on Fischl’s homepage which I have linked in my post.

  • Eric Jorgensen

    I recently purchased one of these usbisp dongles w/ aluminum shell from an aliexpress vendor for about $2.50 shipped, and of course it shows up as a HID device out of the box.

    I’m new to this avr stuff but not entirely new to embedded systems. I bought this because i have an adafruit clock that i want to upgrade the firmware on, and figured it would be handy going forward – for $2.50 right? That way i don’t have to figure out how to use an arduino as an avr programmer.

    So I’ve messed with this long enough that i not only have a $1.80 arduino nano clone in a breadboard set up with the ArduinoISP sketch that comes with the Arduino IDE these days, I even made a cable to go from the breadboard to the usbisp without having to remember which arduino pin goes to which usbisp pin.

    board is marked mx-usbisp-v3.02 and has a mega88 chip.

    Despite coming across warnings that the avrdude that comes with the arduino ide doesn’t work well, it turns out to be the one that actually works on this system without some kind of libusb0 conflict.

    Along the way i discovered “avrdude gui” and discovered that it doesn’t work for poop.

    The command line i landed on that seems to have worked:

    "C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avrdude.exe" -p m88 -c arduino -C "C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf" -P com7 -U flash:w:"C:\Users\Eric\Downloads\ATmega88b.hex":a -e -v -v -b 19200

    Of course, I made the mistake of changing the fuses to HFUSE=0xc9 LFUSE=0xef which disabled my device. Setting them back to HFUSE=0xDF and LFUSE=FF seems to have it going.

    I used Fernando’s hex file. Which was 2kb bigger the 2nd time i downloaded it.

    So yeah it’s been an interesting journey. And, thanks.

    • Zol

      how cool! mine is also that v3.02 version with Mega88, and the modified .hex + fuse bits worked! many thanks!

    • uwezi

      I have very good experience with AVRDUDESS as a gui to avrdude.

      • Eric Jorgensen

        Oh it looks great. But for whatever reason i am having issues resolving libusb0 dependencies. Prior to getting this chinese dongle, the only libusb app i had installed was the arduino ide, which comes with some version of it which was unable to please the avrdude binary i downloaded, or avrdudess.

        • uwezi

          Hi Eric,

          I have seen this issue two days ago on a computer in on of our student labs. The reason was that the USB drivers for the Fischl USBasp programmer had not been installed at all.

          You need to install these drivers, which you will find at Fischl’s homepage: http://www.fischl.de/usbasp/.

          Oh yes and by the way: Windows 8 will of course complain that it is an unsigned driver and currently I don’t know how to work around this “safety” feature, but I know that it’s possible.

          • Eric Jorgensen

            Initially, yes, i didn’t have the usbasp drivers installed. I never previously had any device that would work with that driver.

            So I configured an arduino as an avr programmer so i could get the chinese dongle reprogrammed.

            And that was when i ran into libusb0 issues. avrdude and avrdudess both complained about no libusb. I tried installing libusb0 from the main repository which resulted in a different error status that probably means something about conflicting versions of the same library (but gave only a “could not start, 0x????????” sort of error).

            I was able to get the dongle flashed using the copy of avrdude that gets delivered with the arduino ide, and then after removing my previous hackneyed attempts at fixing libusb0 and installing the USBasp drivers, I was able to use the chinese dongle to re-flash the arduino boot loader on an arduino nano with a bricked fake ftdi chip.

            I guess at this point i should try avrdudess again – perhaps the way the USBasp drivers installs libusb0 has fixed the issue?

          • uwezi

            I would give it a try!

            When I saw the libusb error message recently AVRdudess was still starting – perhaps you could then configure it to use the working avrdude which came with the Arduino framework?

  • Thank you for the firmware update. I had corrupted my Baite USBasp_H6 and after uploading your firmware the LED lit and I knew it was recovered.

    Thank you.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>