📜 ⬆️ ⬇️

How to make Chinese USB programmer for $ 5 work in Linux



This post will be useful primarily to those who are just starting familiarity with microcontrollers or moving from Arduino directly to AVR.

Small introduction


So, probably, you already know that after the device is designed, the printed circuit board is made and the controller is placed in its rightful place, it will need to be programmed. Most microcontroller families have some kind of interface for in-circuit programming — the ISP , which is usually output to a separate connector on the board. In the case of AVR, programming takes place over five communication lines: MOSI, MISO, SCK, RESET and GND.
')


How is it done in arduino


Most Arduino boards allow you to upload a program via USB, and probably the novice user of the mentioned board did not hear much about ISP and programmers. Arduino, however, uses a slightly different way to load the program: a so-called bootloader (bootloader) is flashed in the controller’s memory - a small program that runs when the controller starts. The loader is able to put the controller into programming mode depending on any conditions - the state of the pins, variables in the memory, etc. In the case of the Arduino, the loader is used in combination with either the USB-TTL converter on the FT232 (on earlier versions of Arduino boards) or with ATMega8u2 controller. These microcircuits play the role of a programmer and at the right moments transfer the main controller to the desired mode.

How to do it without Arduino


Due to the fact that the finished device does not require a permanent connection to the programmer, the programming connector mentioned earlier is used. In addition, you will need a programmer. A cursory inspection of the available range of programmers can be disheartening - a proprietary programmer costs some 2300 3,900 rubles . So, we have enough and incomplete. The Internet is replete with programmer circuits - the simplest one consists of resistors, a DB-25 connector and is connected to an LPT port. It remains to find the LPT port.

In my case, the criterion of choice was the price, so almost all the self-assembled options on the FT232, ATTiny, ATMega were not accepted due to the high cost and lack of the necessary components in the shops of my city - a quartz resonator and then not found. And if you order on the Internet, then why not buy a programmer right away?

Thus, such a programmer was acquired for $ 5. It is searched on ebay for the request "usbisp", "usbasp" or "avr programmer". There are many of them, there are cases, there are no, but, as I understand it, they are all structurally the same.

After receiving the programmer by mail, there was a problem - it is seen in the system not as a virtual COM port, but as a HID device. It is possible that it will work with AVR Studio, but I needed to work with avrdude on Linux, which did not want to work with the programmer.

Search by VID = 0x03EB and PID = 0xc8b4 led here on this page . In principle, this entire post could consist only of this link; but it may be easier for many beginners to read the same in Russian and in a slightly more detailed form.

All operations on the programmer are intended to make it compatible with USBASP, a popular programmer for which the circuit diagram and source code of the firmware are available. To do this, you need to fill in the programmer with the USBASP firmware, which is slightly modified.

So, the operations are in order.

Setting the jumper self-programming


Image from www.sciencetronics.com

There are jumper contacts on the board, marked as “UP”. If you solder the jumper there, you can pour the firmware into the microcontroller used in the programmer (most likely, this is reset and ground).

Firmware

Yes, sadly, but you need a second programmer. In addition to the mentioned LPT-port, it is easy to make the programmer from Arduino: it is enough to compile and flash the ArduinoISP sketch from the examples folder. At the same time, the connection of the programming connector can be viewed here , and the pinout of the connector itself can be viewed by Google on the request of “ISP 10 pin”. For my own case, I built something like a shield from the connectors and one capacitor.



The file for the firmware and the source code can be downloaded here .

So, the victim programmer is connected to the main programmer (in my case, the Arduino). The firmware can be uploaded via avrdude with the following command:

avrdude -c avrisp -P /dev/ttyACM0 -b 19200 -p m8 -U flash:w:20130212_mega8_usbisp.hex:a -U lfuse:w:0xef:m -U hfuse:w:0xc9



After that, the device can be turned off and the jumper soldered. After watering the jumper, the programmer will be pleased with new VID = 0x16c0 and PID = 0x5dc, which correspond to USBASP. Now you can work with him like this:

avrdude -c usbisp

That's all. One can only guess for what purpose the Chinese are pouring firmware into the programmers, which is not clear how to use, and how the HID device can act as a programmer. If you mimic under USBASP, using this word in the name of the product - you can copy the firmware.

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


All Articles