AVR-mUPI  v1.2
A unified application programming interface for megaAVR devices.
Setting up the development environment

What do you need to use AVR-mUPI?

To use AVR-mUPI in your application, you need to do only the following two things:

  1. Include the AVR-mUPI header file mupi.h in all the application files using it.
  2. Configure your development environment in order to define the variables needed by AVR-mUPI and the path to reach the header and library files during compilation and linking.

AVR-mUPI depends on the definition of the following variables:

  • AVR device identifier (MCU): Identifier of the AVR device for which the application has to be built (see the list of AVR device identifiers for the supported devices). This variable will be used for including the right header files and for linking the appropriate library file.
  • Processor clock frequency (F_CPU): AVR-mUPI libraries are completely independent from the processor clock frequency. Those elements depending on this value are defined in the header files and they will be automatically calculated during the user application compilation and using the F_CPU value chosen by the user.

The following sections describe in detail all the necessary elements to be configured for the following development environments:

  • ATMEL Toolchain.
  • ATMEL Studio.

ATMEL Toolchain

When working directly with ATMEL Toolchain from a command line, you need to define the environment variable mUPI_INSTALL_DIR=<install_dir> (where <install_dir> corresponds to the AVR-mUPI installation directory) and provide a makefile defining your application build process. This makefile shall be configured with the following elements in order to use AVR-mUPI:

  • Define the MCU variable indicating the device target (e.g. atmega8):
    MCU = atmega8 
  • Use option -D to pass the MCU variable as argument to the compiler:
    -DMCU=$(MCU) 
  • Define the F_CPU variable indicating the processor clock frequency (e.g. 8MHz):
    F_CPU = 8000000 
  • Use option -D to pass the F_CPU variable as argument to the compiler:
    -DF_CPU=$(F_CPU) 
  • Use option -I to pass the path to the AVR-mUPI header files as argument to the compiler:
    -I$(mUPI_INSTALL_DIR)/inc 
  • Use option -L to pass the path to the AVR-mUPI library file as argument to the linker:
    -L$(mUPI_INSTALL_DIR)/lib/$(MCU) 
  • Use option -l to pass AVR-mUPI library name as argument to the linker:
    -lmupi 

ATMEL Studio

When working with ATMEL Studio, you may define the GCC project options and configuration parameters in two different ways:

  1. To use an external makefile.
  2. To define symbols and paths.
Using an external makefile.
In this case, ATMEL Studio will use an external makefile provided by the user to build the application. The following procedure describes how to configure ATMEL Studio in order to use an external makefile to build your application:
  • Open the Project->Properties->GCC Project Options and Configuration dialog.
  • Select the Build page.
  • Check the Use External Makefile box.
  • Enter the path and name of the makefile in Make file Name.
  • If the makefile does not define the MCU and F_CPU variables, then enter the following arguments in Build commandline: MCU=$(avrdevice) F_CPU=<f_cpu>, where <f_cpu> corresponds to the cpu clock frequency value in Hz (e.g. 8000000UL).
Note
The makefile shall respect the requirements imposed by ATMEL Studio.
Defining symbols and paths.
In this case, ATMEL Studio will build the application using the symbols and paths defined in the project. The follwing procedure describes how to configure the ATMEL Studio project:
  • Open the Project->Properties->GCC Project Options and Configuration dialog.
  • Select the Toolchain page.
  • Select AVR/GNU C Compiler->Symbols and add the MCU and F_CPU symbols:
    • MCU=<mcu>, where <mcu> is the mcu device identifier (e.g. atmega8).
    • F_CPU=<f_cpu>, where <f_cpu> corresponds to the cpu clock frequency value in Hz (e.g. 8000000UL).
  • Select AVR/GNU C Compiler->Directories and add the following path:
    • <install_dir>/inc, where <install_dir> corresponds to the AVR-mUPI installation directory.
  • Select AVR/GNU Linker->Libraries and add the name of the AVR-mUPI library:
    • mupi
  • Select AVR/GNU Linker->Library search path and add the following path:
    • <install_dir>/lib/<mcu>, where <install_dir> corresponds to the AVR-mUPI installation directory and <mcu> is the mcu device identifier (e.g. atmega8).