Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2026-08

Setting up FPC to cross compile for the AVR, MSP430 and native mode.

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Stephen Holland

I would like to cross compile Pascal to the AVR microcontroller series. My specific target is the AVR64DU32, but would want to be able to compile to other AVR architectures as well as to Texas Instruments MSP430 series. I understand that the processors even in a family have significant differences. I have cloned the FPC source with

https://gitlab.com/freepascal.org/fpc/source.git

and I have a nice set of files in ~/src/source. There I find a Makefile and a Makefile.fpc. I understand the Makefile is created by running fpcmake from the directory with the Makefile.fpc file. If I do that, how do I set it up for building a compiler that can do all of AVR, MSP430, and my desktop programs? I have found in the makefile that I should probably do something like

fpcmake CROSSCOMPILE=1 CPU_TARGET=avr

to get the AVR architecture, but does that build an FPC that is specific to the AVR architecture only or will the compiler work for more than one target architecture? I also found that for the GCC compiler I need the option -mmcu=x, where X is specific the the MCU. There I see -mmcu=avrxmega2 refers to the AVR64DU32. I also see the FPC doesn't handle all the specifier and AI tells me to use SUBARCH=avr25, but whether I put that into the fpcmake or make isn't clear. Is it possible to have one FPC compiler that will compile to my native desktop architecture (Mac) and also compile to AVR or MSP430 with a command line option? To check if all has gone well, what directories are the files and support files supposed to go?

Thanks,
Steve

Christo Crause
to Stephen Holland

On Sun, Aug 30, 2026 at 12:21 PM Stephen Holland via fpc-pascal <

Show quoted text 45 lines
wrote: I would like to cross compile Pascal to the AVR microcontroller series. My specific target is the AVR64DU32, but would want to be able to compile to other AVR architectures as well as to Texas Instruments MSP430 series. I understand that the processors even in a family have significant differences. I have cloned the FPC source with https://gitlab.com/freepascal.org/fpc/source.git and I have a nice set of files in ~/src/source. There I find a Makefile and a Makefile.fpc. I understand the Makefile is created by running fpcmake from the directory with the Makefile.fpc file. If I do that, how do I set it up for building a compiler that can do all of AVR, MSP430, and my desktop programs? I have found in the makefile that I should probably do something like fpcmake CROSSCOMPILE=1 CPU_TARGET=avr to get the AVR architecture, but does that build an FPC that is specific to the AVR architecture only or will the compiler work for more than one target architecture? I also found that for the GCC compiler I need the option -mmcu=x, where X is specific the the MCU. There I see -mmcu=avrxmega2 refers to the AVR64DU32. I also see the FPC doesn't handle all the specifier and AI tells me to use SUBARCH=avr25, but whether I put that into the fpcmake or make isn't clear. Is it possible to have one FPC compiler that will compile to my native desktop architecture (Mac) and also compile to AVR or MSP430 with a command line option? To check if all has gone well, what directories are the files and support files supposed to go?

A good starting point: https://wiki.freepascal.org/AVR Typically you need to use make and ensure you have the cross binutils for the target system available already. If you want to compile for avr64du32 then specify SUBARCH=avrxmega2 as part of the make parameters. Note that the makefile only builds one subarch at a time and by default put the compiled units in folders without a subarch differentiator.

Maybe the easiest option if you are new to fpc and cross compiling is to use the fpcupdeluxe tool to help configure and maintain lazarus and/or fpc for various different targets (especially if one isn't familiar with fiddling with the compiler's configuration file):
https://github.com/LongDirtyAnimAlf/fpcupdeluxe. There is a very long help thread for fpcupdeluxe here:
https://forum.lazarus.freepascal.org/index.php/topic,34645.0.html

In general you need a cross compiler per CPU target, so you need a native compiler for the host and then a cross compiler for say AVR. MSP430 is not supported by fpc.

Once the cross compiler is installed correctly, compile as follows (minimum command line options, assumes that binutils and RTL are in known to the compiler locations).:
$ fpc -Tembedded -Pavr -Wpavr64du32 hello.pas

Please ask if you run into issues (this is almost guaranteed if it is your first time trying to build a cross compiler from fpc's development branch). Good luck!

Christo Crause

The specific paths are configurable, so it depends on how you install the new compiler. See
https://wiki.freepascal.org/Cross_compiling#From_macOS_(Darwin) for typical folder structure on a Mac.

Show quoted text 47 lines
Thank you for the reply. I gather that since I will specify architecture that as a result of this process I will have a compiler that targets my OS on the desktop and I have the additional AVR target available with just the compiler directives. Is there documentation on where the subdirectories go so I can check on the install having gone well? I’ll try the install, check the -i option on fpc to see if it thinks it did the install and report back. Steve On Aug 30, 2026, at 10:12 AM, Christo Crause wrote: A good starting point: https://wiki.freepascal.org/AVR Typically you need to use make and ensure you have the cross binutils for the target system available already. If you want to compile for avr64du32 then specify SUBARCH=avrxmega2 as part of the make parameters. Note that the makefile only builds one subarch at a time and by default put the compiled units in folders without a subarch differentiator. Maybe the easiest option if you are new to fpc and cross compiling is to use the fpcupdeluxe tool to help configure and maintain lazarus and/or fpc for various different targets (especially if one isn't familiar with fiddling with the compiler's configuration file): https://github.com/LongDirtyAnimAlf/fpcupdeluxe. There is a very long help thread for fpcupdeluxe here: https://forum.lazarus.freepascal.org/index.php/topic,34645.0.html In general you need a cross compiler per CPU target, so you need a native compiler for the host and then a cross compiler for say AVR. MSP430 is not supported by fpc. Once the cross compiler is installed correctly, compile as follows (minimum command line options, assumes that binutils and RTL are in known to the compiler locations).: $ fpc -Tembedded -Pavr -Wpavr64du32 hello.pas Please ask if you run into issues (this is almost guaranteed if it is your first time trying to build a cross compiler from fpc's development branch). Good luck!