📜 ⬆️ ⬇️

Programmer for the new tinyAVR family based on the cheap Chinese CH340 converter

Unified Program and Debug Interface (UPDI) is a single-wire interface for programming / debugging new Atmel 8-bit microcontrollers, replacing the two-wire PDI interface used for programming AVR XMEGA microcontrollers.

image

So, the regiment of Atmelov's protocols arrived - ISP, JTAG, debugWIRE, TPI, aWire, PDI, now here is UPDI. At the same time, the situation with the AVR ecosystem is still very poor, so we were going to completely abandon their use, but the latter tendency pleased us a little, which is why this article was written.

Only the happy owners of the Atmel ICE programmer can use the UPDI protocol, which is not very convenient to use due to the rather strange choice of the connector, and it is not that cheap to afford to purchase it on an industrial scale. In addition, it requires the installation of Atmel Studio, which periodically refuses to work with it, because according to the policy of our company, most computers do not have access to the Internet, and the studio periodically climbs there for drivers, then for some libraries, as a result moments when the programmer was visible in the system, that is, the drivers were installed correctly, but it was not noticed by the studio itself until it got access to the network and was not updated forcibly.
')
Therefore, immediately after we began to use the new and quite convenient ATTiny1616 microcontroller (about its merits later) in our developments, there was a need for a tool that we could use to write to the primary loader controller in production. Of course, without SMS and registration of access to the Internet.

After a bit of searching, I discovered the pyupdi project (https://github.com/mraardvark/pyupdi) on Github - the implementation of the UPDI protocol on Python, and this implementation is based on the usual UART protocol, except without level converters, which, in fact, even more convenient, because it allows the use of standard chip converters from FTDI or their Chinese counterparts CH340 / 341.

The project was downloaded and tested, it went quite cheerfully. But after a couple of days it became clear that he still didn’t really fit us. The reasons:


Problems were solved within the framework of Python for some time, but after any fixation I had to reassemble the project, test it, so that there was a desire to rewrite the script on something more familiar and faster, that is, on C. We are embeds, after all!

Now briefly about the merits of the tinyAVR 1-Series new family:


As an iron part of the programmer, we took the already existing USB-UART TTL converter based on the Chinese CH340 chip, like this:

image

For programming, it is enough to connect two of its RX and TX pins, since they are already equipped with a 1.5k output resistor, if there is no resistor in your converter model, then you need to add it. The combined output is connected to the UPDI pin on a programmable chip; the transmitter ground must also be connected to the controller ground. If there is an external power supply, you need to pay attention only to whether it corresponds to the power supply that the converter uses (3.3V or 5V). If there is a need, it is possible to power the circuit with the controller from the converter itself, which can be very convenient for primary programming.

image

Attention! The resistor is optional, it needs to be soldered only if your converter does not have any protective resistors at the output.

The only problem that is associated with the CH340 chip is that it did not work in my Linux version of the program, because the parity bit in the programming protocol and the CH340 driver in my kernel version do not work correctly with this bit. Perhaps the problem will be resolved soon, so far I have not had the patience to do this.

As a result of the work and experiments in IDE Code :: Blocks, the updiprog program was written and debugged, the source codes of which are laid out on GitHub .

What has been implemented in this version of the program:


The initial size of the program is about 25 kb in comparison with 5 kopecks MB for the compiled source Python script.

I hope that the work done will be useful to someone. I will be glad to feedback and suggestions.

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


All Articles