CMake toolchain for AVR microcontroller
You can use this toolchain by some ways:
This repository depends on arduino-cli, and need to install arduino:avr
core before you use it:
arduino-cli core install arduino:avr
If you always want to use AVR toolchain, please insert following lines into CMakeLists.txt
.
NOTE: Please insert them before project()
statement!
# fetch and enable AVR toolchain
include(FetchContent)
FetchContent_Declare(
avr_toolchain
GIT_REPOSITORY https://github.com/Enchan1207/cmake-avr
GIT_TAG v0.2.0
)
FetchContent_Populate(avr_toolchain)
set(CMAKE_TOOLCHAIN_FILE "${avr_toolchain_SOURCE_DIR}/cmake/avr_toolchain.cmake")
If your project is developed as cross-platform software, add --toolchain=
options to cmake when configure.
cmake .. --toolchain=/path/to/avr_toolchain.cmake
It can be able to build your project for AVR without making any changes to CMakeLists.txt
.
This toolchain provides custom macros named target_configure_for_avr()
. It can use like this:
add_executable(main)
target_sources(main PRIVATE
main.cpp
)
# If your project is not only for AVR,
# please check if BUILD_FOR_AVR is defined and its value is `true`
if(${BUILD_FOR_AVR})
target_configure_for_avr(main)
endif()
This macro adds the following custom targets and commands to your target:
flash-{target_name}
for flashing.
If you execute this target, built programms will be flashed to microcontroller by avrdude
.avr-objdump
is displayed to console.You can specify some options to cmake-avr. These can be checked and edited using ccmake, cmake-gui or command-line options.
ARDUINOCLI_ROOT
: Root path of arduino-cli. If you installed arduino-cli to custom directory, you need to set this.AVR_MCU
: The identifier of target microcontroller. atmega328p
is used by default.AVR_FCPU
: The clock frequency of target microcontroller. 16000000
is used by default.AVRDUDE_PORT
: Port to which the programmer is connected. *NIX might be /dev/the_name_of_device
, Windows might be COM#
.AVRDUDE_BAUDRATE
: The communication baudrate between PC and programmer, 19200
is used by default.AVRDUDE_PROGRAMMER
: The identifier of programmer. avrisp
is used by default.Sorry, currently this toolchain not supports Arduino headers, libraries or programms(.ino
).
This repository is published under MIT License.