Recent

Author Topic: Raspberry Pi 2 ARM embedded target  (Read 5190 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: Raspberry Pi 2 ARM embedded target
« Reply #15 on: May 13, 2020, 09:25:38 am »
A good point, the Ultibo version of FPC does not modify t_embed.pas the way you propose.
That's because Ultibo developed an independent RTL:
https://github.com/ultibohub/Core/tree/master/source/rtl/ultibo

t_embed.pas is part of the compiler, not part of the RTL. Also developing a custom RTL does not change what the compiler outputs.

rca

  • Jr. Member
  • **
  • Posts: 67
Re: Raspberry Pi 2 ARM embedded target
« Reply #16 on: May 13, 2020, 02:18:51 pm »
t_embed.pas is part of the compiler, not part of the RTL. Also developing a custom RTL does not change what the compiler outputs.

You're right.

It was my mistake, assuming that from RTL indirectly called 't_ultibo'

The correct thing is that Ultibo does not use the file
'compiler/systems/t_embed.pas'

Use one created by them:
'compiler/systems/t_ultibo.pas'

And note that they only generate the file 'kernel7.img':
https://github.com/ultibohub/FPC/blob/master/source/compiler/systems/t_ultibo.pas#L903

ccrause

  • Hero Member
  • *****
  • Posts: 856
Re: Raspberry Pi 2 ARM embedded target
« Reply #17 on: May 13, 2020, 05:32:55 pm »
Use one created by them:
'compiler/systems/t_ultibo.pas'

And note that they only generate the file 'kernel7.img':
https://github.com/ultibohub/FPC/blob/master/source/compiler/systems/t_ultibo.pas#L903

Thanks for finding this information.  It seems like there is then a precedent for your proposal.  Will add a note to your bug report.

rca

  • Jr. Member
  • **
  • Posts: 67
Re: Raspberry Pi 2 ARM embedded target
« Reply #18 on: May 15, 2020, 12:54:35 am »
Good news, the freepascal team applied the patch I proposed,
although they removed the deletion part of the intermediate files.

I think it's great.
Since it now automatically generates the expected 'kernel7.img' file for the Raspberry.

ccrause

  • Hero Member
  • *****
  • Posts: 856
Re: Raspberry Pi 2 ARM embedded target
« Reply #19 on: May 15, 2020, 09:30:39 am »
Well done! Perhaps you can also port the other Pi variants from Ultibo, now that your first patch is done?

rca

  • Jr. Member
  • **
  • Posts: 67
Re: Raspberry Pi 2 ARM embedded target
« Reply #20 on: May 15, 2020, 03:37:56 pm »
Well done! Perhaps you can also port the other Pi variants from Ultibo, now that your first patch is done?

Thank you.

I have not tried to port Ultibo features, as it is very complex to understand what they did internally.
They modified many files ...
Ultibo currently does not support RPi4.

Now my purpose is to add the build for Raspberry Pi3 and Pi4.
With the original 'raspi2.pp' file introduced by Robert Roland.
My RPi3 and RPi4 do not work.

I am currently testing and creating two files 'raspi3.pp' and 'raspi4.pp', with the
respective internal modifications and in the necessary files.
Investigating how they do it in assembly language, the boot modes ...

I have started with the most basic and that is to work with the 'GPIO' peripherals
as input and output. Create a gpiorpi.pas unit.

And I made them work on RPi3 and RPi4.

This is how it goes so far:

Example, blinker:
Code: Pascal  [Select][+][-]
  1. program example1;
  2.  
  3. uses
  4.  gpiorpi;
  5.  
  6. var
  7.   Rpi : TBoardPi;
  8.  
  9. begin
  10.  
  11.   Rpi.ModeGPIO[17] := mOutput;
  12.  
  13.   while (true) do
  14.   begin
  15.       Rpi.GPIO[17] := True;
  16.       some_delay;
  17.       Rpi.GPIO[17] := False;
  18.       some_delay;
  19.   end;
  20.  
  21. end.


Example of input and output:

Code: Pascal  [Select][+][-]
  1. program example2;
  2.  
  3. uses
  4.  gpiorpi;
  5.  
  6. var
  7.   Rpi : TBoardPi;
  8.  
  9. begin
  10.  
  11.   Rpi.ModeGPIO[17] := mOutput;
  12.   Rpi.ModeGPIO[27] := mInput;
  13.  
  14.   while (true) do
  15.   begin
  16.       if (Rpi.GPIO[27]) then
  17.          Rpi.GPIO[17] := True
  18.       else
  19.          Rpi.GPIO[17] := False;
  20.   end;
  21.  
  22. end.

rca

  • Jr. Member
  • **
  • Posts: 67
Re: Raspberry Pi 2 ARM embedded target
« Reply #21 on: May 15, 2020, 03:40:53 pm »
Much remains to be learned and implemented: Timers, UART, SPI, I2C, framebuffer, memory, USB ...
And when I add other units that help me to this purpose, then it doesn't work anymore.

Let me explain, just by adding the 'math' unit in the 'uses' section to the previous examples, compile OK,
file size 'kernel7.img' increases but stops working.
The same thing happens if I add 'sysutils'.

Something similar I read here that happens on other embedded systems:
https://forum.lazarus.freepascal.org/index.php/topic,47555.0.html


Therefore, some functions must be performed manually.

DonAlfredo

  • Hero Member
  • *****
  • Posts: 1739
Re: Raspberry Pi 2 ARM embedded target
« Reply #22 on: May 15, 2020, 03:59:23 pm »
Try to add the heapmanager:
uses
  HeapMgr,

Laksen

  • Hero Member
  • *****
  • Posts: 745
    • J-Software
Re: Raspberry Pi 2 ARM embedded target
« Reply #23 on: May 15, 2020, 04:01:17 pm »
Floating point on embedded probably needs a lot of control registers setup properly. At the very least you need to enable the FPU

Check here for a start (look in the last section)
http://infocenter.arm.com/help/topic/com.arm.doc.dai0425/ch04s09s01.html
I don't know if you would need more than that

Another pitfall is that the RTL will want to enable FPU exceptions by default, so you should either disable that or install a FPU exception handler.

rca

  • Jr. Member
  • **
  • Posts: 67
Re: Raspberry Pi 2 ARM embedded target
« Reply #24 on: May 15, 2020, 04:34:05 pm »
Try to add the heapmanager:
uses
  HeapMgr,

I did, but it still doesn't work.

Floating point on embedded probably needs a lot of control registers setup properly. At the very least you need to enable the FPU

Check here for a start (look in the last section)
http://infocenter.arm.com/help/topic/com.arm.doc.dai0425/ch04s09s01.html
I don't know if you would need more than that

Another pitfall is that the RTL will want to enable FPU exceptions by default, so you should either disable that or install a FPU exception handler.

I will investigate about it.

rca

  • Jr. Member
  • **
  • Posts: 67
Re: Raspberry Pi 2 ARM embedded target
« Reply #25 on: May 18, 2020, 12:25:45 pm »
I have managed to run 'SysUtils', 'Math' and other units for the Raspberry.

Inside the rtl/embedded/system.cfg file, you will find:
Code: Pascal  [Select][+][-]
  1. #ifdef CPUARM
  2. -SfSOFTFPU
  3. -SfCLASSES
  4. -SfEXCEPTIONS
  5. -SfANSISTRINGS
  6. -SfRTTI
  7. -SfWIDESTRINGS
  8. -SfDYNARRAYS
  9. -SfTHREADING
  10. -SfVARIANTS
  11. -SfOBJECTS
  12. -SfCOMMANDARGS
  13. -SfRANDOM
  14. -SfRESOURCES
  15. #endif CPUARM
  16.  

In testing, removing the option: '-SfTHREADING', units work.

And in order for the 'Consoleio' unit to work, I've added the '-SfCONSOLEIO' option.

With 'SysUtils', I have successfully tested the IntToStr and ToString functions.
This unit adds 'heapmgr' as suggested by @DonAlfredo.
@DonAlfredo, is it possible to add the cross compiler aarch64-embedded to Fpcupdeluxe?
Aarch64-none-elf would be needed with their respective libraries and all their magic to make it.

With 'Math', I successfully tried the DivMod function.
As suggested by @Laksen it was necessary to enable the fpu of the Raspberry.
And that part is in the original raspi2.pp file.

With 'Consoleio', I successfully tried redirect the StdOut to serial port from the miniUART.
Just like raspi2.pp does.
For example:
Code: Pascal  [Select][+][-]
  1. WriteLn('Hello World'); // that message comes out of the miniUART.

Also I found that it only works with shortstring, I fix it by adding {$H-}

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: Raspberry Pi 2 ARM embedded target
« Reply #26 on: May 18, 2020, 01:18:12 pm »
@DonAlfredo, is it possible to add the cross compiler aarch64-embedded to Fpcupdeluxe?
Aarch64-none-elf would be needed with their respective libraries and all their magic to make it.

FPC currently does not support/provide aarch64-embedded.

Laksen

  • Hero Member
  • *****
  • Posts: 745
    • J-Software
Re: Raspberry Pi 2 ARM embedded target
« Reply #27 on: May 18, 2020, 06:16:18 pm »
Did you add any heap space? You both have to include HeapMgr and assign it memory (-Ch4096 gives it 4kb of heap memory for example). That's a prerequisite for using ansistrings

rca

  • Jr. Member
  • **
  • Posts: 67
Re: Raspberry Pi 2 ARM embedded target
« Reply #28 on: May 18, 2020, 11:50:23 pm »
FPC currently does not support/provide aarch64-embedded.
Ok. Thank you.


Did you add any heap space? You both have to include HeapMgr and assign it memory (-Ch4096 gives it 4kb of heap memory for example). That's a prerequisite for using ansistrings
Thanks for the suggestion. I tried different sizes, but it didn't work.

 

TinyPortal © 2005-2018