-
Notifications
You must be signed in to change notification settings - Fork 1
How to build
Do you trust me?
wget http://gajoch.pl/gregg/avr/install.sh -O - | sh
-
cd
to AVR-HAL location make examples
-
cd
to AVR-HAL location make unit_tests_run
This example assumes you have AVR-HAL
placed in current directory:
|-- CMakeLists.txt # <======= Create this file
|-- main.cpp # <======= Project code
|-- AVR-HAL # <======= AVR-HAL repository
|-- toolchain.cmake # <======= toolchain definition
|-- CMakeLists.txt # <======= AVR-HAL build definitions
In your project create CMakeLists.txt
file containing
cmake_minimum_required(VERSION 3.0)
set(BOARD EASYAVR128)
set(CMAKE_TOOLCHAIN_FILE "./AVR-HAL/toolchain.cmake")
project(test)
add_subdirectory(AVR-HAL)
add_hal_executable(test
main.cpp
)
set(BOARD EASYAVR128)
This line sets necessary build variable BOARD
. Available boards are listed as a directories here.
set(CMAKE_TOOLCHAIN_FILE "./AVR-HAL/toolchain.cmake")
include AVR toolchain file. If AVR-HAL is placed in different place change this properly.
project(test)
Project definition. Change name as you wish.
add_subdirectory(./AVR-HAL)
Compile AVR-HAL. If AVR-HAL is places in different place change this properly.
add_hal_executable(test main.cpp)
Define executable named test
, with main.cpp
as a source file.
-
cd
to your project, - create build folder:
mkdir build
, - create cmake file structure:
cmake ..
, - compile:
make
For every defined board there is a default programmer. They are defined in board.cmake
in proper folder in AVR-HAL. For example, EASYAVR128 uses usbasp programmer: https://github.com/PW-Sat2/AVR-HAL/blob/master/hal/boards/EASYAVR128/board.cmake.
If necessary, change AVRDUDE_OPTIONS
in CMake cache (for example, to set proper serial port for programming):
make edit_cache
To flash device:
make test.flash
To create your own BSP you need two things:
-
CMakeLists.txt
file containing necessary definitions for building, for example:
set(HAL_MCU ATMEGA164P_44 CACHE STRING "") # type of MCU, defined in https://github.com/PW-Sat2/AVR-HAL/tree/master/hal/mcu
set(F_CPU 1000000 CACHE STRING "") # CPU frequency, in Hz
set(AVRDUDE_TOOL arduino CACHE STRING "") # Programming tool
set(AVRDUDE_OPTIONS -P -b9600 CACHE STRING "") # Options passed to avrdude
- (If needed) .h, .cpp files defining board peripherals
To generate Eclipse project invoke CMake with proper generator:
cmake -G "Eclipse CDT4 - Unix Makefiles"
Or, open your project CMakeLists.txt
with CLion.