AVR bootloaders and cores

After spending years in the Raspberry Pi/Arduino world, I recently entered the ATtiny world and even after several days I still can't grasp certain facts. This is what I have learned so far: hydrogen water maker

  1. One can upload (assembler) code directly to a AVR microprocessor via a certain protocol. However, to do this one needs GPIOs, which the ordinary PC lacks - usually this is solved by connecting PC via the USB port to Arduino Uno (basically also AVR microprocessors) and sending code via the GPIOs of the Arduino.
  2. One can also upload code via bootloader. This is small code that starts on the power-up of the microprocessor and connects to PC. The most common bootloaders for AVR processors are Optiboot (via serial communication) and Micronucleus (via USB communication).
  • In the case of Optiboot, one also needs a USB-serial chip between the microprocessor and the PC USB port. Optiboot is usually pre-installed on Arduino Uno and Arduino Nano, so these two platforms ship with a USB-to-serial chip on the board.
  • In the case of Micronucleus, communication is established directly through D+ and D- USB pins. Micronucleus is usually pre-installed on Digistump boards (unless one buys a Digistump board without a microcontroller).

If you just buy the bare AVR microcontroller, you can't do anything with it from your PC. You need either another AVR microcontroller with bootloader already uploaded, i.e. Arduino Uno/Nano, or Raspberry Pi, to upload code or bootloader. In the first case you can just use Arduino IDE or avrdude, while in the second case you can just use avrdude.

Can you confirm that I have understood everything correctly so far?

Now my questions:

  1. One can use D.A. Mellis ATtiny library to load code via Arduino Uno/Nano using Arduino IDE. However, one has to burn the bootloader first. Does this mean that this library does not burn a bootloader, but actually only changes the fuses (basic settings of the microcontroller)?
  2. According to the instructions on the internet, the Micronucleus bootloader can only be uploaded with avrdude. Why is it not possible to upload the Micronucleus bootloader from Arduino IDE with Tools/Burn_bootloader?
  3. What the heck is ATTinyCore or Arduino core in general?
  4. In my experience, not all sketches work with all bootloaders, especially Micronucleus. I suspect the problem is that Micronucleus runs at 16.5 Mhz, while most sketches for ATtiny expect 8 MHz. Is that right?

Thank you very much for your help with my questions.

Best regards

That's correct. If you enable "verbose output during upload" in the Arduino IDE's preferences, do a "Burn Bootloader", then check the contents of the black console pane at the bottom of the IDE window, you can see the AVRDUDE commands that are run. They only set the fuses. No bootloader file is flashed to the ATtiny.

I'd guess it would only be because the author of the boards platform you're using didn't implement that capability. In the case of Digistump, they might have preferred that people buy their boards with micronucleus pre-installed.

I see that ATTinyCore now has support for installing Micronucleus via "Burn Bootloader":
Way cool!

It is a 3rd party project that provides Arduino support for a large selection of ATtiny microcontrollers.

The term "core" is somewhat confusing. The most specific use of the term is for the library that implements the standard Arduino API such as digitalWrite(). Even though the Arduino API is consistent from one board to another, there can be dramatic differences in the low level code that is under the hood. For this reason, a different library must be created for each distinct family of boards.

You can see the core library for the Arduino AVR Boards (e.g., Uno, Leonardo, Mega) here:

If you were to look at the one for ESP8266, it is very different:

Unfortunately, the term "core" is also used to refer to the entire collection of code and configuration files that provide Arduino support for a family of boards. For example, the Arduino AVR Boards project has multiple important components:

It has always been confusing to me that, under this terminology, a "core" has a "core". Even more confusing, some "cores" don't even have a "core". An example of this is damellis/attiny. That "core" does not need a "core" because it uses the "core" from Arduino AVR Boards!

It turns out that the correct term for the collection of these components is actually "platform", as explained by one of the primary architects of the system here:

In order to clearly differentiate the two things, I use the terms "boards platform" and "core library", and never use the ambiguous term "core" on its own.

You can learn all about Arduino boards platforms here:

1 Like

ATTinyCore core is my favorite core for programming the ATTiny processors. A core has all of the functions to interface the Arduino IDE to the processor that you want to program. The core is the bridge between the processor and the IDE. A core has all the code for the Arduino functions (digitalRead, digitalWrite, analogRead, and so on). The ATTinyCore core gives you the choice to burn a full bootloader or to just burn fuses. I use tiny85 processors at 1MHz, 8MHz and 16MHz, internal, PLL and external crystal oscillators.

I know nothing of the Micronucleus and used the D.A. Mellis ATtiny only breifly before I discovered the ATTinyCore core. I find the ATTinyCore has the best features.

1 Like

damellis/attiny is a nice demo of how the Arduino boards platform system's referencing capabilities allow you do do interesting things with a minimum of code duplication by leveraging components from existing boards platforms (Arduino AVR Boards in this case).

It also has historical value as one of the early 3rd party boards platforms.

However, for actual use I would always prefer ATtinyCore. "DrAzzy" has done an amazing job at providing support for the ATtiny chips and has also been amazingly dedicated to maintaining and supporting the project over the course of years now.

By contrast, damellis/attiny has had zero maintenance for the last 5 years. The fact that it still works just as well as always demonstrates another benefit of the referencing approach. Having very little code in the project means having very little code to maintain!

This is close, but not quite correct. To load code onto an AVR without a bootloader, you need something called a "device programmer." This implements some vendor-specified protocol for loading the AVR's flash memory. You can think of it as being VERY similar to the creation of an SD card for your RPi - your computer has to have a special device that allows it to write SD cards. (ok, so those are built in to most modern PCs...) The Arduino environment permits you to use an existing running Arduino for that purpose, which is ... significantly cheaper that vendor-provided device programmers. (well, cheaper than they USED to be. Manufacturers are catching on to the idea that a cheap and easy device programmer attracts users...)
Also - not "Assembler code" - you have to "burn" binary instructions to the AVR, but you could have generated that binary from any number of other languages...

Right. You need something that behaves like a Device Programmer. An Arduino or a Pi can do that, along with a bunch of other pieces of equipment that you could buy.

Digistumps are a bit odd; the ATtiny chips used don't actually support USB in their hardware; instead they "bit bang" some general purpose IO pins and BARELY manage to implement something that some PCs manage to think is a low-speed USB device. Word is that some newer PCs (with different USB controllers) have troubles with them.
Unless you're REALLY set on using the ATtiny85, I'd look at one of the newer boards (maybe non-AVR) that do a lot more in about the same space.

And I Nth the recommendation of DrAzzy's ATTinyCore over the damellis core...

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.