Close

Arduino's ATmega16u2 Firmware

A project log for ESP8266 with True USB

Make it act as a USB disk and just copy files on it.

dehipudeʃhipu 02/24/2018 at 00:441 Comment

The first thing I want to make is a USB to serial converter, so why not look at something that does it already. The ATmega16u2 chip on Arduino UNO is programmed as just such a device. A quick search, and we have the source code for its firmware. As I expected, it uses LUFA to do the USB work, and hardware serial to do the UART work. Pretty straightforward stuff, two ring buffers are used to keep the data before it is sent on its way, one for each direction.

What I'm disappointed about, though, is that the baud rate of the physical UART is hardwired as 9600 in that code. I was hoping for some AT code parsing and setting the speed. This is much more primitive.

Why? Because to program ESP8266 you need to talk several speeds. At least I think you do. The default serial speed after boot is some weird value like 74880, and then, I think, esptool changes that to whatever you have configured. And that means that the operating system drivers need to know how to change speeds, and that is usually done with AT commands, since USB to serial converters usually emulate a modem device.

There is a chance that it will work if I set 74880 hardwired, and tell esptool to use that speed for everything. It might just work, who knows. More testing required.

Discussions

Matti Zemack wrote 04/17/2020 at 06:41 point

Thanks for great starting point for me to begin checking out the LUFA firmware on the Arduino and the ATmega16u2.

This is just a note that arduinos Github is reworked and link to firmware can be found here: https://github.com/arduino/ArduinoCore-avr/blob/master/firmwares/atmegaxxu2/arduino-usbserial/Arduino-usbserial.c

  Are you sure? yes | no