Programmer for the 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 not very pleasant, so we were going to completely abandon their use, but the latter tendency pleased us a little, which is why this article was written.

The UPDI protocol can only be used by the happy owners of the Atmel ICE programmer, 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 little searching, I found on the project Githabe pyupdi (https://github.com/mraardvark/pyupdi) - UPDI protocol implementation in Python, and this implementation is based on a standard UART protocol, except that without a level converter, 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:

  • it requires the installation of Python and a whole group of packages (I remind you that we are talking about computers without access to the Internet), I had to download and manually install almost a dozen different packages that depended on each other. Yes, in principle, you can make an executable file on another computer from a Python script, this somehow solved the problem, but the list of problems did not end there.
  • there is almost no error checking in the script, any error ends with an interruption indicating heaps of files referring to each other, which is not very clear to ordinary personnel
  • it is impossible to read the contents of the memory of the controller, which makes it impossible to final test the recording
  • there is no way to read fyuzy
  • the speed of the script leaves much to be desired, 16 kb are written for almost a minute, this is due to the lack of any optimization in the transfer process, everything is built on tight timings
  • no indication of the recording process
  • The project does not support a number of processors that could support
  • the project is in a half-dead state and does not respond to requests

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

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

  • real unification of the periphery and address space in the range from 2 kb to 32 kb
  • convenient bootloader configuration (at the beginning of the memory!)
  • significant simplification of the ISP algorithm (In-System-Programming)
  • transition to von Neumann architecture
  • up to 32 kb of flash memory in a small package (3x3mm) with 24 terminals, of which up to 22 (!) can be used as IO
  • the presence of an internal oscillator at 16/20 MHz
  • less dependence on the configuration of fyuzov (eternal headache AVR)
  • excellent analog part for a small controller (ADC / DAC / comparators with the possibility of both internal and external switching of inputs / outputs)
  • single wire programming and debugging
  • extremely low price in retail (from 0.6 € for 16 kb)

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’s enough to connect two of its RX and TX pins, since they already have a 1.5k output resistor if the resistor is Your model of converter is missing, 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 necessary, it is possible to power the circuit with the controller and 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 with the CH340 chip is that it did not work in my Linux version of the program, since the parity bit in the programming protocol and the CH340 driver in my kernel version do not work with this bit. Perhaps the problem will be fixed 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 Gitkhab .

What has been implemented in this version of the program:

  • Added ability to read the contents of the controller's flash memory in a hex file
  • Added ability to read the status of all controller fusions
  • whenever possible, error handling with appropriate messages added
  • Added indication of the write / read process
  • significantly increased work speed (about 6 seconds to read 16 kb)
  • added support for all 1-Series microcontrollers

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

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

Also popular now: