This repo serves as a starter template for building Arduino Uno projects. This project is a "bare metal" project in that it manipulates the ATmega328p microcontroller registers directly, without leveraging the Arduino SDK.
For reference, the ATmega328p microcontroller datasheet can be found here.
- Prerequisites
- General Directory Structure
- Build Instructions
- Example of Transferring Executable to Arduiono UNO
-
AVR-C++ compiler
Install command
-
Debian / Ubuntu:
sudo apt-get install avr-libc avrdude binutils-avr gcc-avr gdb-avr
-
MacOS:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew tap osx-cross/avr brew install avr-libc brew install avrdude --with-usb
-
-
Install Command
-
Debian / Ubuntu:
sudo apt-get install cmake
-
MacOS:
brew install cmake
Alternatively, Download
- download and install from source
-
-
Install Command
-
Debian / Ubuntu:
sudo wget -qO /usr/local/bin/ninja.gz https://github.com/ninja-build/ninja/releases/latest/download/ninja-linux.zip sudo gunzip /usr/local/bin/ninja.gz sudo chmod a+x /usr/local/bin/ninja ninja --version
-
MacOS:
brew install ninja
-
[toc]
Arduino-Uno-Cmake-Starter-Template
├── cmake
│ ├── Arduino-EXE.cmake
│ └── Arduino-toolchain.cmake
├── src
│ └── CMakeLists.txt
├── .gitignore
├── CMakeLists.txt
├── CMakePresets.json
└── README.md
To review each directory and file provided in the directory structure in detail, review the following Details.
This is the parent directory for the project.
In addition to the directories described below, the Arduino-Uno-Cmake-Starter-Template
directory contains a .gitignore
file, the main (driver) CMakeLists.txt
file, a CMakePresets.json
file (which contains the path to the Arduiono toolchain, compiler settings, build presets, etc.), and a README.md
file that contains build instructions (i.e. this file).
The cmake
directory contains the CMake Arduino toolchain file and include file to convert the project binary to format suitable for use on the ATmega328p microcontroller.
The src
directory is where all of the project source code is provided:
- *.hpp for C++ header files
- *.cpp for C++ source files
The src
directory contains a CMakeLists.txt
file which handles compiling and linking the source code.
[toc]
-
Debian / Ubuntu / MacOS: Open a terminal and navigate to the
Arduino-Uno-Cmake-Starter-Template
directory (referred to in the following as the parent directory).From the parent directory:
cmake --preset=<preset>
where <preset> is one of the configuration presets listed by the command
cmake --list-presets
for example,
cmake --preset=arduino-uno-examples
Upon generating the preset configuration, an
out
directory will be created which will hold thebuild
andinstall
subdirectories for the configutation. Navigate into theout/build/<config>
directory. This directory will now contain abuild.ninja
file.Build the code with:
ninja
[toc]
-
Debian / Ubuntu:
sudo avrdude -F -V -c arduino -p ATMEGA328P -P /dev/ttyACM0 -b 115200 -U flash:w:leds.hex
[toc]