3
\$\begingroup\$

I know that some Arduinos have built-in USB functionality which means they can act as USB devices as well as being programmed directly.

I also know that most Arduinos use an additional microcontroller to convert USB to serial.

Why is this needed?

Is this a limitation of the microcontroller that does not support USB?

Can some only be programmed using serial?

I am particularly interested in the difference between the Arduino UNO which uses an additional microcontroller (ATMega16U2) for USB conversion and Arduino Leonardo which does not have some middle layer controller.

\$\endgroup\$
7
  • \$\begingroup\$ Can you actually list the Arduinos where this applies, and also the microcontrollers used on them? Like this, each of us potential answerers have to open wikipedia, look at that table, figure out which devices use a separate USB-to-serial adapter although having a USB-capable MCU, and then write these down in a list of our owns, to answer this. You'll increase the likelihood of getting an answer greatly by doing that footwork yourself instead of us letting do that. \$\endgroup\$ – Marcus Müller May 7 '20 at 10:15
  • \$\begingroup\$ (and the one example you have, the arduino UNO, is based on the ATMega328P, microcontroller that doesn't have USB, so obviously you'll need an external component to talk USB) \$\endgroup\$ – Marcus Müller May 7 '20 at 10:16
  • \$\begingroup\$ The USB stack is probably too large (program memory wise) to use it in the Bootloader. And even if this isn't the limiting factor, its often desirable to keep the Bootloader code clean and simple (and thus make it less error prone). \$\endgroup\$ – Rev May 7 '20 at 10:17
  • \$\begingroup\$ @Rev1.0 I'd agree, but a lot of microcontrollers come with an integrated USB bootloader, so: hm. Not the greatest argument. Plus, upgrading to a microcontroller with more flash is almost certainly cheaper than adding a supplemental external USB interface.) \$\endgroup\$ – Marcus Müller May 7 '20 at 10:18
  • 1
    \$\begingroup\$ @MarcusMüller I updated with the only microcontrollers I care about. \$\endgroup\$ – Startec May 7 '20 at 19:15
2
\$\begingroup\$

I am particularly interested in the difference between the Arduino UNO which uses an additional microcontroller (ATMega16U2) for USB conversion and Arduino Leonardo which does not have some middle layer controller.

The ATMega16U is really an odd microcontroller. Although it has a USB PHY on chip, it still comes with only:

  • 16 KB of program memory
  • 512 B of RAM (! that's bytes, not kilobytes)
  • 32 pads

Whereas the ATMEga32U4 used in the Arduino Leonardo (isn't great, but) has:

  • 32 KB of program memory
  • 2.5 kB of RAM
  • 44 pads

So, the reasons to not do it on the Atmega16U itself are:

  • little program memory (as the USB interface/USB bootloader simply takes up serious amounts of the only 16 kB you have)
  • little fun in doing so: if all you have are 512 B of RAM, you can't implement much stack – so calling functions from handlers from handlers gets problematic quickly; you can't keep anything of your bootloader in RAM when you hand over to the application if your RAM is that rare
  • Problematic GPIO situation: with much fewer pads, it's harder to select a sensible set of IO pins if you can't assign the USB functions to just any pins (that's not a concern in this case, both the ATMega16U and ATMega32U have fixed USB pins, you can't select to which pins USB should be routed)

So, I think the strongest argument is probably really that implementing USB on the ATMega16U is hard and problematic, since the resources of that IC are so severely limited.

Personal note: I never understood why Arduino went for the 8 bit microcontrollers in an era when there was mature 32 bit microcontrollers with much richer resources available, and where they were in a position to hide the complexity of these from their users, anyway. We shall never know – maybe they had a deal with Microchip, because for me as low-volume buyer, these Atmega328 (1.90€), Atmega16U2 (2.30€) and Atmega32U4 (3.70€) are way more expensive than a capable ARM Cortex-M running at multiples of these device's clock rate, having upwards of 32 kB program memory and typically several kB of RAM.

\$\endgroup\$
2
  • \$\begingroup\$ Arduino project was for school student. Now they have 32-bit Arduino and recently released an industrial-grade Arduino. \$\endgroup\$ – Sadat Rafi May 8 '20 at 15:23
  • \$\begingroup\$ @SadatRafi that really doesn't explain anything about the choice of MCU. \$\endgroup\$ – Marcus Müller May 8 '20 at 15:55
3
\$\begingroup\$

in order to program via usb would involve a USB bootloader, some boards such as the arduino Due can actually be programmed via USB, however they still leave the serial option,

To answer why they take this method, lets say you actually want to control that USB port with your arduino program, you do not want the device to behave as another USB device long enough to to possibly be programmed with it.

The Due gets around this by only working when the program flash on the device has already been erased, however you likely do not want to have to press an erase button on the device each time your upload either

So the main reason for the serial programming is convenience, if your controlling that USB peripheral, you want to be able to just press upload and have it work every time, equally its a nice secondary diagnostic path to use when your trying to work out what is not working if say the USB interface stops responding.

\$\endgroup\$
1
  • \$\begingroup\$ Yup. In addition to being convenient for debugging, You also get a nice micro controller "programmer" too for socketed ICs \$\endgroup\$ – nabulator May 15 '20 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.