Recent

Author Topic: Why SubArchs at AVR  (Read 1675 times)

Mathias

  • Jr. Member
  • **
  • Posts: 88
Why SubArchs at AVR
« on: February 21, 2020, 04:31:53 pm »
First of all, thank you to the developers that you can create projects with Lazarus AVR.

But what is quite tedious, you have to build a separate Lazarus for each SubArch.
Wouldn't it be possible to build FPC to support all SubArch?

What I found, "Project / Project Settings / Configuration and Goals / Target Processor (-Cp)" has no effect.
The -Cp could be used for the AVR type, e.g. for the ATtiny2313a. For that you could leave out the -Wpattiny2313a.

What is the reason that you have to make such a detour?


If I build an AVR25 cross compiler and want to program an Atmega328p, I get the following error:

If I choose the wrong SubArch for the first time, I get the following error.


Code: [Select]
Compile project, OS: embedded, CPU: avr, target: /home/tux/fpcupdeluxe_test/projects/Project1.elf: Exit code 1, error: 1
Fatal: Can't find unit ATMEGA328P used by Project1

If I build an AVR5 compiler in the meantime, and then again an AVR25, I get the following error:


Code: [Select]
Compile project, OS: embedded, CPU: avr, target: /home/tux/fpcupdeluxe_test/projects/Project1.elf: Exit code 1, error: 5
Error: / home / tux / fpcupdeluxe_test / cross / bin / avr-embedded / avr-ld: incompatible /home/tux/fpcupdeluxe_test/fpc/units/avr-embedded/rtl/system.o is searched for / home / tux / fpcupdeluxe_test / fpc / units / avr-embedded / rtl / system.o skipped
Error: / home / tux / fpcupdeluxe_test / cross / bin / avr-embedded / avr-ld: /home/tux/fpcupdeluxe_test/fpc/units/avr-embedded/rtl/system.o could not be found
Error: / home / tux / fpcupdeluxe_test / cross / bin / avr-embedded / avr-ld: incompatible /home/tux/fpcupdeluxe_test/fpc/units/avr-embedded/rtl/objpas.o is searched for / home / tux / fpcupdeluxe_test / fpc / units / avr-embedded / rtl / objpas.o skipped
Error: / home / tux / fpcupdeluxe_test / cross / bin / avr-embedded / avr-ld: /home/tux/fpcupdeluxe_test/fpc/units/avr-embedded/rtl/objpas.o could not be found
Assembling project1
Linking /home/tux/fpcupdeluxe_test/projects/Project1.elf


Project1.pas (13.4) Error: Error while linking

As I see it, it is ligating to the files in the "fpc / units / avr-embedded" folder.
Couldn't you make such folders:
"fpc / units / avr-embedded-avr25", "fpc / units / avr-embedded-avr5", etc.

Wouldn't it be possible to build different system.o and objpas.o.
With Linux / i386 or win32 / i386, there are also different target processors.
« Last Edit: February 21, 2020, 06:03:33 pm by Mathias »

ccrause

  • Hero Member
  • *****
  • Posts: 856
Re: Why SubArchs at AVR
« Reply #1 on: February 21, 2020, 08:23:07 pm »
Quote
What I found, "Project / Project Settings / Configuration and Goals / Target Processor (-Cp)" has no effect.
The -Cp could be used for the AVR type, e.g. for the ATtiny2313a. For that you could leave out the -Wpattiny2313a.
The compiler knows the subarch for each controller (see compiler/avr/cpuinfo.pas), so -Cp is indeed not really needed.  One could still override the subarch by passing -Cp after -Wp for special cases.

Controllers are grouped roughly according to supported instruction sets, for example the avr25 subarch only has a rjmp instruction with limited range (8 KiB) while the avr5 subarch also have a jmp instruction with a range of 8 MiB.  The RTL is compiled to take advantage of the most efficient available instructions per subarch.  This means that if one needs to compile for different controllers belonging to different sub architectures (I would imagine this is by far the most common case) then the RTL's for the different architectures need to be stored separately.

Currently the build and install mechanism of FPC doesn't cater for separate RTL folders per subarch, so the user needs to manage this unfortunately.  As background to this you can read this thread, although there have been more discussions over the years.

Note that only one cross compiler for AVR is required, just the RTL (and packages) is different per subarch.

Quote
Couldn't you make such folders:
"fpc / units / avr-embedded-avr25", "fpc / units / avr-embedded-avr5", etc.
Yes, and then you need to adjust your fpc.cfg to reflect the new folder structure, more or less as follows (but of course your specific folder structure will be slightly different):
Code: Bash  [Select][+][-]
  1. # searchpath for units and other system dependent things
  2. #ifdef cpuavr
  3. -Fu~/fpc/$fpcversion/rtl/units/$fpctarget-$fpcsubarch
  4. -Fu~/fpc/$fpcversion/packages/*/units/$fpctarget-$fpcsubarch/*
  5. #else
  6. -Fu~/fpc/$fpcversion/rtl/units/$fpctarget
  7. -Fu~/fpc/$fpcversion/packages/*/units/$fpctarget
  8. #endif
  9. #endif
  10.  
You seem to use Fpcupdeluxe to install FPC.  I'm not familiar with this tool so cannot give you more hints on tweaking its output into a new folder structure.

It is a bit easier when building from source using make, see for example this post, which shows how to specify an install folder containing the subarch as a parameter.

MiR

  • Sr. Member
  • ****
  • Posts: 250
Re: Why SubArchs at AVR
« Reply #2 on: February 21, 2020, 08:34:21 pm »
Using subarchs is quite easy, there are two changes needed:

a) edit your fpc.cfg and search for:

fpc/units/$fpctarget/rtl or fpc\utils\$fpctarget\rtl (windows)

in my case the line found is:

-Fu/Users/ring/fpcupdeluxe/fpc/units/$fpctarget/rtl

Now add another line (adjust the path to match your path used) which includes $fpcsubarch in UnitDir:

-Fu/Users/ring/fpcupdeluxe/fpc/units/$fpctarget/$fpcsubarch/rtl

With this line included fpc will extend the unit search to a subarch specific directory.

now build and install (for example) the avr5 compiler and move the content of your avr-embedded/rtl directory to the new directory avr-embedded/avr5/rtl

do the same for other subarchs.

You can alternatively add INSTALL_UNITDIR=<path to fpc>/units/avr-embedded/avr5/rtl to your make install commandline, this will automagically put libs in the correct directory.

After this change you will only need one lazarus install and switching rtls is done by specifying correct subarch.


There is a second method which requires a compiler patch, I have never used this method, perhaps Christo can decribe what needs to be done for the second method.

Michael



« Last Edit: February 22, 2020, 04:56:24 pm by MiR »

MiR

  • Sr. Member
  • ****
  • Posts: 250
Re: Why SubArchs at AVR
« Reply #3 on: February 21, 2020, 08:35:17 pm »
Hey Christo, you were faster than me ,-)

MiR

  • Sr. Member
  • ****
  • Posts: 250
Re: Why SubArchs at AVR
« Reply #4 on: February 21, 2020, 08:40:49 pm »
Here's my buildscript in the attachment, it takes care of using the correct directories and is fpcup-deluxe compatible....

you will need to have pv (piveview) installed

 

TinyPortal © 2005-2018