Recent

Author Topic: Yet another FPC/embedded ARM question  (Read 2051 times)

DavidL

  • New Member
  • *
  • Posts: 13
Yet another FPC/embedded ARM question
« on: March 31, 2023, 06:38:45 pm »
Greetings all,

I'd like to build a Linux-hosted FPC binary to generate code for an embedded ARM device (STM32), albeit with an existing binutils package.  From the TARGET_embedded wiki page I believe part of the magic incantation is:

$ cd <directory containing the FPC source cloned from gitlab>
$ make clean buildbase installbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=arm SUBARCH=armv7em

However, I'm unclear on a few things:

 - how to tell the FPC make to find and use the existing binutils (which are installed in /opt/ARM/gcc-arm-none-eabi-6-2017-q2-update/),

 - how to tell FPC to use the "arm-none-eabi-" prefix to reference the ARM binutils tools,

 - how to tell the FPC make to install the FPC compiler, RTL, etc. at a specific place (e.g., /opt/ARM/fpc).

Thanks very much for any assistance!

Dave

ccrause

  • Hero Member
  • *****
  • Posts: 970
Re: Yet another FPC/embedded ARM question
« Reply #1 on: April 01, 2023, 01:08:45 pm »
- how to tell the FPC make to find and use the existing binutils (which are installed in /opt/ARM/gcc-arm-none-eabi-6-2017-q2-update/),
You can use -FD/opt/ARM/gcc-arm-none-eabi-6-2017-q2-update to tell fpc where to look for utilities.

Quote
- how to tell FPC to use the "arm-none-eabi-" prefix to reference the ARM binutils tools,
Specify the bintools prefix with the -XParm-none-eabi- command line option. When building the cross compiler, you can pass BINUTILSPREFIX=arm-none-eabi- to make, which will then pass it to the compiler.

Quote
- how to tell the FPC make to install the FPC compiler, RTL, etc. at a specific place (e.g., /opt/ARM/fpc).
Pass INSTALL_PREFIX=/opt/ARM/fpc to make.

Example (untested):
Code: Bash  [Select][+][-]
  1. $ make clean buildbase installbase OS_TARGET=embedded CPU_TARGET=arm SUBARCH=armv7em INSTALL_PREFIX=/opt/ARM/fpc BINUTILSPREFIX=arm-none-eabi- CROSSOPT="-FD/opt/ARM/gcc-arm-none-eabi-6-2017-q2-update"

DavidL

  • New Member
  • *
  • Posts: 13
Re: Yet another FPC/embedded ARM question
« Reply #2 on: April 01, 2023, 03:06:34 pm »
Excellent!  Thank you very much!  I'll give this a run next week and report back.
« Last Edit: April 04, 2023, 03:09:57 pm by DavidL »

DavidL

  • New Member
  • *
  • Posts: 13
Re: Yet another FPC/embedded ARM question
« Reply #3 on: April 03, 2023, 08:44:31 pm »
...

Example (untested):
Code: Bash  [Select][+][-]
  1. $ make clean buildbase installbase OS_TARGET=embedded CPU_TARGET=arm SUBARCH=armv7em INSTALL_PREFIX=/opt/ARM/fpc BINUTILSPREFIX=arm-none-eabi- CROSSOPT="-FD/opt/ARM/gcc-arm-none-eabi-6-2017-q2-update"

Apparently the "-FD" requires a full path to find the binutils executables (i.e., a "/bin" must be appended to the path).  Adding the "/bin" appeared to allow the make to complete but I noticed the /opt/ARM/fpc/bin directory is empty.  Shouldn't there be an fpc executable there?  (There is a /opt/ARM/fpc/lib/fpc/3.3.1/ppcrossarm and the RTL bits appear in /opt/ARM/fpc/lib/fpc/3.3.1/units/arm-embedded/rtl/.)

Does this define success or it it not quite there yet?


Thanks again,
Dave

ccrause

  • Hero Member
  • *****
  • Posts: 970
Re: Yet another FPC/embedded ARM question
« Reply #4 on: April 03, 2023, 10:26:48 pm »
Apparently the "-FD" requires a full path to find the binutils executables (i.e., a "/bin" must be appended to the path).  Adding the "/bin" appeared to allow the make to complete but I noticed the /opt/ARM/fpc/bin directory is empty.  Shouldn't there be an fpc executable there?  (There is a /opt/ARM/fpc/lib/fpc/3.3.1/ppcrossarm and the RTL bits appear in /opt/ARM/fpc/lib/fpc/3.3.1/units/arm-embedded/rtl/.)

Does this define success or it it not quite there yet?
My suspicion is that make buildbase produces only the cross compiler and cross RTL.  Usually I start with make all ... which then builds the full native FPC compiler, RTL and packages, and various utilities.  make install then installs the compiler utilities (including fpc) in $INSTALL_PREFIX/bin and the rest of the compiler, RTL and packages in $INSTALL_PREFIX/lib/fpc/$FPCVERSION/.

So you probably have a working cross compiler setup, but with none of the native compiler utilities (fpc, fpcres, h2pas etc.).  You should be able to cross compile a simple embedded program this way by directly invoking the cross compiler binary - provided you have a fpc.cfg that points to the installed RTL for the cross target.

DavidL

  • New Member
  • *
  • Posts: 13
Re: Yet another FPC/embedded ARM question
« Reply #5 on: April 05, 2023, 03:26:22 pm »
Thanks very much for all your help.

For reference, the following produced part of the puzzle with a standard (i.e., properly triplet-named) binutils package installed in /opt/ARM/gcc-arm-none-eabi-6-2017-q2-update:

$ cd </path/to/fpc/source/tree/cloned/from/gitlab>
$ sudo make clean buildbase installbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=arm SUBARCH=armv7em INSTALL_PREFIX=/opt/ARM/fpc BINUTILSPREFIX=arm-none-eabi- CROSSOPT="-FD/opt/ARM/gcc-arm-none-eabi-6-2017-q2-update/bin"

(It's not clear that the "CROSSINSTALL=1" actually does anything at all (tried with and without) but it's on the TARGET_Embedded page, so...)


After lots of mucking around with ppcrossarm options, I was finally able to get a target app (the STM32F756XG is close enough for now) compiled into a .s that appears reasonable via:

APP=./helloworld; /opt/ARM/fpc/lib/fpc/3.3.1/ppcrossarm -v0wn -Ct -Sg -Sa -Sy -n -al -sh -XParm-none-eabi- -Xm -Tembedded -Cparmv7em -WpSTM32F756XG -Fu/opt/ARM/fpc/lib/fpc/3.3.1/units/arm-embedded/rtl $APP

The app assembled and linked using the generated ppas.sh script.  In pawing through the output files it looks like it would run.


For the remainder of the puzzle, I'm not clear on how to get an fpc in /opt/ARM/fpc/bin that'll use the ppccrossarm that was dropped in /opt/ARM/fpc/lib/fpc/3.3.1/.  (I'm kinda wondering what the fpc portion actually does...)  Of course, there's already a native fpc installed on the system (3.2.2+dfsg-9ubuntu1) and I don't want to mess that up in trying to build a native from the gitlab tree or jacking around with the native config file(s).

Any ideas, anyone?

ccrause

  • Hero Member
  • *****
  • Posts: 970
Re: Yet another FPC/embedded ARM question
« Reply #6 on: April 06, 2023, 08:52:22 am »
(It's not clear that the "CROSSINSTALL=1" actually does anything at all (tried with and without) but it's on the TARGET_Embedded page, so...)
The CROSSINSTALL variable is set automatically if the target is different from the source compiler, so hasn't been necessary to specify this for quite a while.

Quote
For the remainder of the puzzle, I'm not clear on how to get an fpc in /opt/ARM/fpc/bin that'll use the ppccrossarm that was dropped in /opt/ARM/fpc/lib/fpc/3.3.1/.  (I'm kinda wondering what the fpc portion actually does...)
I see fpc as a tool that locates and calls the appropriate cross compiler binary based on the -P parameter. One can also call the cross compiler directly, instead of calling fpc.

Quote
Of course, there's already a native fpc installed on the system (3.2.2+dfsg-9ubuntu1) and I don't want to mess that up in trying to build a native from the gitlab tree or jacking around with the native config file(s).
It gets a bit tricky to use compilers installed in separate locations.  Also fpc in one install path is unlikely to locate a cross compiler located in another path. If you can build and install a cross compiler, you can also do the same for a native compiler.  A further complication is that sometimes one needs features only available in the development branch - for this reason I chose to install both a native and a few cross compilers for a specific fpc version in my home folder.  Others probably have different strategies.

 

TinyPortal © 2005-2018