DEV Community

Sarvesh Sant
Sarvesh Sant

Posted on

From Arduino IDE to AVR GCC | AVR Bare Metal #1

Introduction

It has been a while since I started playing around with microcontrollers. My journey began with the Arduino UNO and programming it using the Arduino IDE. Later, I spent some time learning how to program PIC microcontrollers for my coursework, and that was my first real exposure to bare metal programming.

At that time, though, I was more focused on completing coursework than truly understanding what I was being exposed to. The Arduino ecosystem abstracts a lot of things away, and for almost everything there is already a library available. Compared to that, bare metal programming felt painful reading datasheets, finding register addresses, and doing all that work just to blink an LED did not seem exciting back then.

But something changed recently.

Now I actually want to avoid those high-level Arduino functions and understand what is happening underneath them. Somehow, bare metal programming now feels much cooler than simply calling prebuilt functions.

So I scrapped all the project ideas I had planned earlier and decided to start bare metal programming using the Arduino UNO.

Why Arduino UNO?

Because when I looked at the STM32 datasheet, I was completely overwhelmed. By this point, I had already watched a few videos from channels like Etalvis and experimented a bit with AVR registers inside the Arduino IDE itself. I had already managed to blink an LED using direct register manipulation, which gave me some confidence in navigating the AVR datasheet.

Compared to STM32, the AVR datasheet felt much more approachable for learning low-level concepts.

Why Move Beyond Arduino IDE

Then I thought:
why stop at avoiding Arduino functions?

Why not avoid the Arduino IDE itself as well?

The Arduino IDE handles compilation and flashing automatically behind the scenes. I thought it would be fun to manually explore that workflow too PS: it was fun.

This way I can have complete control over:

  • compilation

  • firmware generation

  • flashing

  • and understand what actually happens underneath the Arduino IDE.

Understanding the AVR Toolchain

To completely move away from the Arduino IDE workflow, a few tools are needed for compiling and flashing AVR programs.

Tool Purpose
AVR GCC Compiles AVR C source code and generates the ELF file
AVR Libc Provides AVR-specific libraries, macros, and definitions for registers and peripherals. But we will using pointers and create our own macros, expect for ISRs
AVR Objcopy Converts the generated ELF file into a HEX file that can be flashed onto the microcontroller
AVRDUDE Uploads the firmware to the microcontroller
Make Automates the build process instead of manually typing every command

While reading about build systems, I initially came across CMake. But most sources suggested learning Make first because it helps in understanding the basic fundamentals and build process more directly.

Installing the Toolchain on Linux

These were the packages I needed to install on my Linux desktop.

sudo apt update
sudo apt install avr-gcc avr-libc avrdude make
Enter fullscreen mode Exit fullscreen mode

From what I read, avr-objcopy comes from the binutils-avr package. When installing avr-gcc, the package manager automatically installs binutils-avr as a dependency.

Verifying the Installation

Once installed, I verified everything using the following commands:

avr-gcc --version
avrdude -?
make --version
Enter fullscreen mode Exit fullscreen mode

You should see outputs similar to this:

With this, the AVR toolchain setup on Linux is complete.

Why Linux?

One question people might ask is:

why Linux?

Personally, I found setting up embedded development tools much easier on Linux compared to Windows. Most bare metal development tools and workflows seem far more comfortable in a Unix/Linux environment, especially when working from the terminal.

It also makes automation and build systems feel much more natural.

What’s Next?

In the next article, I will write and flash my first bare metal AVR program to blink the onboard LED on the Arduino UNO without using the Arduino IDE or helper functions like digitalWrite().

Top comments (0)