On Sun, Aug 30, 2026 at 12:21 PM Stephen Holland via fpc-pascal <
[email protected]> 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!
_______________________________________________
fpc-pascal maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to