📜 ⬆️ ⬇️

Chinese HID USBISP Programmer (USBASP) in Linux. Preprogramming

Microcontroller programming and robotics are very promising areas of activity. This is already being discussed at the state level. And it all starts with the fact that beginners collect their first programmer or order it from the online store. The most affordable are Chinese crafts. They are not always ready to immediately please their new owners. However, usually, they are quite efficient after revision and / or flashing.



The situation is complicated by the fact that there are many similar models and different versions of Chinese-made printed circuit boards. I got programmers with a printed circuit board that is incompatible with the firmware on the network. Trite, does not match the purpose of the conclusions of the microcontroller on the board and in the program. Next, I will describe the process of treating a small batch of these programmers and some tricks for beginners.
')
I hope someone this article will be useful, since it is specifically for this version of the programmers information on the Internet, apparently, no.

For those who want a quick solution, at the end of the article there is a link to the archive with the USBASP from Thomas Fischl, which I modified, and a list of changes in the git diff format.

Purchase


I decided to buy a set of programmers and microcontrollers for classes in robotics in our Center for Children's Computer Creativity . The choice fell on Aliexpress. Cheap and angry.
I ordered a pack of Attiny13A, a couple of pads for them, several Atmega32 on the training boards, mockups, and, of course, a dozen USBASP programmers. Earlier, I ordered a couple of similar programmers - one of them even worked.



As it turned out, the delivered programmers turned out to be inoperable in Ubuntu Linux. One of them corresponded to the advertising picture, the other 9 were slightly longer and not packed in anti-static bags. At the same time, all 10 had USBISP on the case and were proudly defined as a HID device.

Description of the programmer USBASP USBISP with aliexpress (by the way, not a word about Linux):
The USBASP USBISP AVR / 51 Series Programmer Download Aluminum Shell 64K Limit Support WIN7 64

Description:

Perfectly support WIN7

1, support USB1.1 or USB2.0 communication.
2, support WIN98, WINME, WIN2K, WINXP operation system.
3. USB ports Power supply
4, download not finish influence the operation of the target board.
5, support S51 and AVR chips record, ISP speed, faster than parallel, more stable; The best choice.
6, The latest version of the firmware upgrade, download speed jump line
7, using standard IDC10 interface


Sly Chinese, wanting to simplify the lives of users of the default OS, wrote a firmware that does not require drivers. One minus - only one Chinese program with the interface in the Chinese language and only in one OS can work with these programmers. This option absolutely did not suit me.

Finding a solution


A web search led me to the Hacking an AVR programmer page.
There everything is fine and well described. I was delighted and began to disassemble the programmers. It turned out to be easy. They struck the original design solutions in the form of an insulator of double-sided tape.





I was happy early. On this page, the process of flashing was described for another version of the programmer (v3.0), which is otherwise divorced. I had an unidentified version of the programmer in my hands.



The result of studying the board is the picture below. Everything that could have been divorced differently than in the already familiar third version with a blue card. This did not prevent the finalization of the firmware, in which the output numbers had to be changed, their initialization (see the article Hacking an AVR programmer ) and the LED control algorithm.



In the original usbasp firmware for USB and LEDs correspond legs 12,13 and 23,24. On the board, the outputs of 1.32 and 9.10 were divorced. In this case, the LEDs were connected in parallel, which was subsequently taken into account in the program.

There were no jumpers for programming here. Therefore, I had to slightly alter the cable, releasing the “Reset” posting at will. I temporarily soldered this wire to the “Reset” input for programming the victim.





An illustrative picture that helped me in matching the controller's legs (ATmega8):



It is good that there was already a working programmer. Just version v3.0, but with a working firmware.



Flashing


The first two programmers were stitched successfully. The third protested. It turned out that it was exactly the 29th leg of the “Reset” that was not soldered.



Eliminating this cant, I continued to work.



On the fifth programmer, I was tired of soldering entries to the reset, and I applied a less reliable but faster method. Helped daughter's hair tie.



The victim programmer is plugged into a USB hub (blue) only to be more stable - the hub is not connected anywhere.
Sometimes I received messages from avrdude that the controller is not responding. It was saved by lowering the voltage with a three-meter USB extension cable and reducing the programming speed (the -B switch in the “avrdude -c usbasp -p m8 -B 50” line).

The most important snack


Archive with original firmware: www.fischl.de/usbasp/usbasp 2011-05-28.tar.gz
We look in the Readme.txt section "BUILDING AND INSTALLING FROM SOURCE CODE"
Extract the folder from the archive /usbasp.2011-05-28/firmware/
We are updating the firmware to taste.
In the console, go to the firmware folder and run make to get help on the available commands.
We compile the firmware and upload it into the programmer (through another working programmer).

Git diff for this project (my changes)
diff --git a/main.cb/main.c index a225432..64755ca 100755 --- a/main.c +++ b/main.c @@ -306,11 +306,16 @@ int main(void) { /* no pullups on USB and ISP pins */ PORTD = 0; PORTB = 0; + PORTC = 0; /* PORTC not connected */ /* all outputs except PD2 = INT0 */ - DDRD = ~(1 << 2); + //DDRD = ~(1 << 2); /* output SE0 for USB reset */ - DDRB = ~0; + // DDRB = ~0; + //DDRD = ~0; + DDRD = 0b01100000; // 1 = output (PD6+PD5 LEDS, PD3+PD2 USB) + ledRedOff(); + j = 0; /* USB Reset by device only required on Watchdog Reset */ while (--j) { @@ -322,10 +327,9 @@ int main(void) { /* all USB and ISP pins inputs */ DDRB = 0; - /* all inputs except PC0, PC1 */ - DDRC = 0x03; - PORTC = 0xfe; - + /* PORTC not connected -> all inputs*/ + DDRC = 0; + /* init timer */ clockInit(); diff --git a/usbasp.hb/usbasp.h index b60bd04..9c12652 100644 --- a/usbasp.h +++ b/usbasp.h @@ -62,9 +62,9 @@ #define USBASP_ISP_SCK_1500 12 /* 1.5 MHz */ /* macros for gpio functions */ -#define ledRedOn() PORTC &= ~(1 << PC1) -#define ledRedOff() PORTC |= (1 << PC1) -#define ledGreenOn() PORTC &= ~(1 << PC0) -#define ledGreenOff() PORTC |= (1 << PC0) +#define ledRedOn() PORTD |= (1 << PD5); PORTD &= ~(1 << PD6) +#define ledRedOff() PORTD &= ~(1 << PD5); PORTD |= (1 << PD6) +//#define ledGreenOn() PORTD &= ~(1 << PD5) +//#define ledGreenOff() PORTD |= (1 << PD5) #endif /* USBASP_H_ */ diff --git a/usbconfig.hb/usbconfig.h index 203239e..9fe7375 100755 --- a/usbconfig.h +++ b/usbconfig.h @@ -22,15 +22,15 @@ the newest features and options. /* ---------------------------- Hardware Config ---------------------------- */ -#define USB_CFG_IOPORTNAME B +#define USB_CFG_IOPORTNAME D /* This is the port where the USB bus is connected. When you configure it to * "B", the registers PORTB, PINB and DDRB will be used. */ -#define USB_CFG_DMINUS_BIT 0 +#define USB_CFG_DMINUS_BIT 3 /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected. * This may be any bit in the port. */ -#define USB_CFG_DPLUS_BIT 1 +#define USB_CFG_DPLUS_BIT 2 /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. * This may be any bit in the port. Please note that D+ must also be connected * to interrupt pin INT0! 



Bonus photos
What could be done from the pads for tinkeys (it turned out - very convenient).



Control LED between outputs PB3-PB4.





Links


Archive with modified firmware (source + compiled firmware main.hex): app.box.com/s/xz4neeubv663rvcem12pbctq91hutpp2
Original firmware (USBasp firmware from Thomas Fischl): www.fischl.de/usbasp
Hacking an AVR programmer: www.sciencetronics.com/greenphotons/?p=938
An article on Habré on the same topic: "How to make a Chinese USB programmer for $ 5 work in Linux"

Source: https://habr.com/ru/post/252061/


All Articles