-
Notifications
You must be signed in to change notification settings - Fork 1
How to build
To build, HAL needs couple of available tools:
- shell console
- make
- avr-g++ + avr-libs
For programming:
- avrdude For testing (lint and unit tests):
- wget
- python
- unzip
One of the ways to have required tools (and tested by now) it to use cygwin. Download and install Cygwin console. According to your system - 32 or 64 bits. Install required packages from repository:
- wget
- make
Apart from 'default' way of installing packages the apt-cyg is possible:
wget rawgit.com/transcode-open/apt-cyg/master/apt-cyg
install apt-cyg /bin
apt-cyg install wget make
To get a toolchain one may use Atmel Studio provided one, but to ease setup the pre-build package was created. It consists of toolchain and avrdude programmer. Download and uzip toolchain package whereever you want ("C:\toolchain" for example).
Then, add the tools to system PATH variable: Run Cygwin and call (if the toolchain package was unziped to "C:\toolchain", otherwise modify):
export PATH="/cygdrive/c/toolchain/bin:$PATH"
At the begginng it is recommended to compile all available examples. Just invoke 'make' in 'examples' folder of the repository. If the build succeeded it means that the working envirnoment is proper.
Let's take a look at example for blinking a LED on arduino 328P. Go to: "examples/ArduinoNano328P/DigitalIO". To compile invoke just 'make'.
To program the board invoke 'make flash_default COM=COMn'. Specify to which COM port your board is connected. It will invoke default programmer for the board specified (to be found in HAL/boards/xxx/programmers.make). The LED should blink at 1 Hz frequency. (If your board have 8 MHz crystal than wait for a second).
Example program: #include <util/delay.h> #include "DigitalIO.h" #include "boards.h"
int main() {
constexpr hal::DigitalIO pin(hal::bsp::pins::LED);
pin.init(hal::DigitalIO::OUTPUT);
pin.reset();
while (true) {
pin.toggle();
_delay_ms(500);
}
}
By default, build process includes all HAL files in include search path (all subdirs of HAL folder).
BSPs (board support package) are provided for boards - to be found in particular folder for a board.
Makefile for this example:
HAL_PATH = ../../../HAL
APP_NAME = DigitalIO
INCLUDES = \
-I .
BOARD = ARDUINONANO328P_16MHZ
SRCS = \
DigitalIO.cpp
include $(HAL_PATH)/build.make
It is important for all applications to be similar to this. The requirements are:
- HAL_PATH should point to the HAL folder in repository,
- APP_NAME is a "application name" - that is how output file will be named,
- INCLUDES - additional include path. In this example this is not necessary, but it was left for clearance,
- BOARD - specifies target board,
- SRCS - all sources to be compiled (.cpp/.c),
- include - this line includes all needed HAL magic to build your app!
At this time following BOARDs are supported:
- ARDUINONANO328P_8MHZ
- ARDUINONANO328P_16MHZ
- ARDUINOMEGA2560
- EASYAVR128
To specify explicitly which programmer should be used one can use 'make flash' command. It requires to specify PROGRAMMER variable - the name of programmer passed to avrdude. List of possible can be accessed by 'avrdude -cdummy'
Also, to programmers like arduino and wiring to additional variables are normally needed:
- BAUD (=57600) - baudrate (-b option in avrdude)
- COM (=COM8) - comport (-P option in avrdude)
For example: "make flash PROGRAMMER=usbasp" "make flash PROGRAMMER=arduino COM=COM8 BAUD=115200"
Protip: After specifying PROGRAMMER and/or COM value build system saves that information (in particular application folder) and one can just invoke 'make flash' to re-flash firmware.