Recent

Author Topic: Trouble compiling fpc for mipsel-embedded  (Read 1293 times)

ermok

  • New Member
  • *
  • Posts: 10
Trouble compiling fpc for mipsel-embedded
« on: June 03, 2025, 12:43:57 pm »
Hello. I have hard time with fpc target mipsel embedded for microchip pic32 mcus on windows machine.
I have tried several things, building from trunk, using fpcupdeluxe and even some random sources from github. Tried many different binutils but so far no luck.
I'm completly aware there is no mcu specific files or startup asm and thats totally okey, i can write them by mself, actually i prefer low level bare metal programming anyway where i can manipulate registers my own way. For years i've been using mikroe compilers but they do not longer update pascal compilers and i really dont want to go back to C hell. So im hoping FPC is my savior.

Ermo.

ccrause

  • Hero Member
  • *****
  • Posts: 1029
Re: Trouble compiling fpc for mipsel-embedded
« Reply #1 on: June 03, 2025, 02:49:27 pm »
What errors do you get?

A quick look at cpuinfo.pas and embedded/MakeFile suggest that controller units are expected, but I cannot find the corresponding units. I would expect building the rtl for mipsel-embedded should fail, but perhaps someone more knowledgeable than me knows how to build this target...

ccrause

  • Hero Member
  • *****
  • Posts: 1029
Re: Trouble compiling fpc for mipsel-embedded
« Reply #2 on: June 03, 2025, 08:03:46 pm »
According to the latest trunk test results mipsel-embedded does indeed fail to build due to a missing file: /rtl/embedded/mipsel/startup.s

It would appear as if there was no follow-up to this partial commit, which would explain the missing startup and cpu files.

Here is a bug report describing this issue. Apparently there was a licensing incompatibility with the startup code.  Perhaps you can help by providing a patch for the startup code  ;)

ermok

  • New Member
  • *
  • Posts: 10
Re: Trouble compiling fpc for mipsel-embedded
« Reply #3 on: June 04, 2025, 09:20:08 am »
Alright, now I understand the problem.
Yes, I can provide startup code, and I really prefer Pascal-style startup code (a separate startup.pas or startup.inc file), and ideally, an easy way to override it from userland.
But to do that, I need a working compiler so I can write, test, and debug it. I'm not sure I can write this blindly.

ccrause

  • Hero Member
  • *****
  • Posts: 1029
Re: Trouble compiling fpc for mipsel-embedded
« Reply #4 on: June 04, 2025, 11:27:05 pm »
I tried to get something working by following the wiki instructions, but I had trouble finding a suitable binutils suite that followed the conventions of the compiler generated assembler script.  The ChipKit link was empty, building from the mentioned git project gave errors (even if I went back to the suggested 2013 version. Then I installed Microchip's XC32 compiler, but the binutils as tool did not support the -mabi option! I then build the latest binutils release (2.44) for mipsel and adapted some of the compiler settings (changed subarch from pic32mx to m4k, since vanilla binutils does not understand -mpic32mx) and so forth.

Download binutils from https://sourceware.org/pub/binutils/releases/binutils-2.44.tar.xz, then ../configure --target=mipsel-none-elf --disable-multilib --disable-werror --disable-nls --prefix=/opt/mips

Not sure what toolchain you are using, I hope it is compatible with the tweaks I made.  If not, please advise which toolchain you use, if it is open source I can test it.

The patched FPC is here: https://gitlab.com/ccrause/fpc-source/-/tree/mipsel-embedded?ref_type=heads

You are welcome to look at the basically empty startup and controller units in rtl/embedded/mipsel/ folder.  I assume a bit of assembler code is required to configure the interrupts.  I don't know mipsel controllers, so couldn't come up with even a most basic startup routine.  Look at the other architectures for examples of how one can structure the startup code.

Finally we need the controller units, I can ask Michael Ring for his units, it would save a bit of effort.

ermok

  • New Member
  • *
  • Posts: 10
Re: Trouble compiling fpc for mipsel-embedded
« Reply #5 on: June 23, 2025, 09:22:20 am »
Ohh sorry! The last few weeks have been kinda crazy, didn’t even get around to checking in here.

But now im gonna check it again. Downloading fpc, and lets see where it gets me.

ccrause

  • Hero Member
  • *****
  • Posts: 1029
Re: Trouble compiling fpc for mipsel-embedded
« Reply #6 on: June 24, 2025, 07:32:32 am »
Just to temper your expectations: the rtl builds but linking of an empty program fails with linker errors.

ermok

  • New Member
  • *
  • Posts: 10
Re: Trouble compiling fpc for mipsel-embedded
« Reply #7 on: July 07, 2025, 08:17:48 pm »
Okey,
patched source is compiled, ppcrossmipsel compiler ready. But when i try to compile sample program compiler throws error: Illegal parameter: -Wppic32mx795f512h
i have multiple binutils aviable - one is microchip binutils, other is from codetyphon.
Also i checked some linker logic, seems that linker needs specific linker script, .ld file maybe? Where is defined at least minimal variables with ram and flash sizes, startup vector and so on


ccrause

  • Hero Member
  • *****
  • Posts: 1029
Re: Trouble compiling fpc for mipsel-embedded
« Reply #8 on: July 08, 2025, 04:10:41 pm »
Okey,
patched source is compiled, ppcrossmipsel compiler ready. But when i try to compile sample program compiler throws error: Illegal parameter: -Wppic32mx795f512h
i have multiple binutils aviable - one is microchip binutils, other is from codetyphon.
In the latest version of the patched source I reverted back to specifying pic32mx as the subarch.  This means that you have to build the RTL by specifying SUBARCH=pic32mx (if using the standard makefile).

My apologies, I should have mentioned it.  The reason I reverted this is because standard GNU binutils do not understand the pic32mx controller type, leading to linker errors.  I then switched to the latest Microchip XC32 compiler toolchain, this seem to work, but the startup code is not included in the final binary. There is obviously a linking problem somewhere, but it is not obvious to me whether it is the linker script or an incorrectly marked section in startup.o.

Quote
Also i checked some linker logic, seems that linker needs specific linker script, .ld file maybe? Where is defined at least minimal variables with ram and flash sizes, startup vector and so on
This is the start of the code that generates the linker script for mipsel embedded.  When compiling an example project you can specify -sh which would then create a build script and a linkxxx.res file.  The linkxxx.res file will contain the list of files passed to the linker, together with the generated linker script.

ermok

  • New Member
  • *
  • Posts: 10
Re: Trouble compiling fpc for mipsel-embedded
« Reply #9 on: July 08, 2025, 06:21:06 pm »
i compiled embedded compiler using wiki: make clean buildbase installbase CROSSINSTALL=1 OS_TARGET=embedded CPU_TARGET=mipsel SUBARCH=pic32mx BINUTILSPREFIX=pic32-
only binutils prefix is different.




 

TinyPortal © 2005-2018