Sign in Join
Wiki copytemporary

Revision 2 of 3, by WikiArchive on 11-4-2026. The page as it is now.

AVR

Warning-icon.png

Warning: The FPC-AVR port is experimental and might be broken from time to time. If this is the case, please fill a bug report

FPC-AVR is the Free Pascal Compiler port for the AVR microcontroller. It uses the GCC AVR tool chain and will be compatible with GCC regarding calling conventions etc.

For instructions on how to program AVR's with Free Pascal, see the article AVR Programming.

Contents

Implementation details

FPC considers AVR to be a 16 bit CPU. So the type TRegister actually describes a register pair with the second register implicitly named.

Building cross-compiler

There are some requirements, you should know about:

Download using the appropriate link for your operating system]

Then you can build your cross compiler. Please choose SUBARCH according to your Arduino board / AVR microcontroller.

pascal
make buildbase installbase CPU_TARGET=avr OS_TARGET=embedded SUBARCH=avr5 CROSSINSTALL=1 INSTALL_PREFIX=~/fpc NOGDB=1 PP=/usr/bin/fpc CROSSBINDIR=/usr/avr/bin

You may also set the binutils prefix for this (equivalent to the -XP switch)

pascal
make buildbase installbase CPU_TARGET=avr OS_TARGET=embedded SUBARCH=avr5 CROSSINSTALL=1 INSTALL_PREFIX=~/fpc NOGDB=1 PP=/usr/bin/fpc CROSSBINDIR=/usr/avr/bin  BINUTILSPREFIX=avr-

The instructions above is good if only one subarchitecture is required. To install several subarchitectures, a unique unit install prefix needs to be specified for each subarchitecture using INSTALL_UNITPREFIX :

pascal
make buildbase installbase CPU_TARGET=avr OS_TARGET=embedded CROSSINSTALL=1 NOGDB=1 FPC=/usr/bin/fpc CROSSBINDIR=/usr/avr/bin  BINUTILSPREFIX=avr- INSTALL_PREFIX=~/fpc INSTALL_UNITPREFIX=~/fpc/lib/fpc/3.2.2/units/avr-embedded/avr5 SUBARCH=avr5

Remember to change both SUBARCH and INSTALL_UNITPREFIX when building a different subarchitecture.

Together with this change, the fpc.cfg file paths needs to be updated to find units in this new structure. Below is an example of updating the unit specific search paths in fpc.cfg:

pascal
# searchpath for units and other system dependent things
    #IFDEF EMBEDDED
    -Fu~/fpc/lib/fpc/$fpcversion/units/$fpctarget/$fpcsubarch
    -Fu~/fpc/lib/fpc/$fpcversion/units/$fpctarget/$fpcsubarch/*
    -Fu~/fpc/lib/fpc/$fpcversion/units/$fpctarget/$fpcsubarch/rtl
    #ELSE
    -Fu~/fpc/lib/fpc/$fpcversion/units/$fpctarget/*
    -Fu~/fpc/lib/fpc/$fpcversion/units/$fpctarget/rtl
    #ENDIF

Adapt paths as required.

Subarchitecture

The operating system target embedded requires that you specify a subarchitectures when building a cross compiler. The subarchitectures are compatible with the ones used by GCC.

Resources


From the Free Pascal wiki, page "AVR", as the Internet Archive kept it on 2022-12-31. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.