Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2021-02

Enabling hardware floating point processor for cortex-m4f on embedded and freertos

8 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Ring

When rtl for arm-embedded/arm-freertos is build with hardfloat the fpu should also automagically get enabled, by default it is off which causes a crash when floats are used.

This small patch fixes that problem in cortexm4f_start.inc

can you please apply this patch to trunk?

Thank you,

Michael

diff --git a/rtl/embedded/arm/cortexm4f_start.inc
b/rtl/embedded/arm/cortexm4f_start.inc
index 82202b1565..fa557becfc 100644
--- a/rtl/embedded/arm/cortexm4f_start.inc
+++ b/rtl/embedded/arm/cortexm4f_start.inc
@@ -43,6 +43,14 @@ asm
   str r1, [r0]
 {$endif REMAP_VECTTAB}

+{$if not defined(FPUSOFT)}
+  ldr r0, .Lcpacr
+  ldr r1, [r0]
+  orr r1, r1, #0xf00000
+  str r1, [r0]
+  dsb
+  isb
+{$endif not defined(FPUSOFT)}
   bl PASCALMAIN
   b HaltProc

@@ -56,10 +64,13 @@ asm
   .long _data
 .L_edata:
   .long _edata
+{$if not defined(FPUSOFT)}
+.Lcpacr:
+  .long 0xE000ED88
+{$endif not defined(FPUSOFT)}
 {$ifdef REMAP_VECTTAB}
 .Lvtor:
   .long 0xE000ED08
 .Ltext_start:
   .long _text_start
 {$endif REMAP_VECTTAB}
-end;
\ No newline at end of file
diff --git a/rtl/freertos/arm/cortexm4f_start.inc
b/rtl/freertos/arm/cortexm4f_start.inc
index 82202b1565..70b75ee6ae 100644
--- a/rtl/freertos/arm/cortexm4f_start.inc
+++ b/rtl/freertos/arm/cortexm4f_start.inc
@@ -43,6 +43,14 @@ asm
   str r1, [r0]
 {$endif REMAP_VECTTAB}

+{$if not defined(FPUSOFT)}
+  ldr r0, .Lcpacr
+  ldr r1, [r0]
+  orr r1, r1, #0xf00000
+  str r1, [r0]
+  dsb
+  isb
+{$endif not defined(FPUSOFT)}
   bl PASCALMAIN
   b HaltProc

@@ -56,10 +64,14 @@ asm
   .long _data
 .L_edata:
   .long _edata
+{$if not defined(FPUSOFT)}
+.Lcpacr:
+  .long 0xE000ED88
+{$endif not defined(FPUSOFT)}
 {$ifdef REMAP_VECTTAB}
 .Lvtor:
   .long 0xE000ED08
 .Ltext_start:
   .long _text_start
 {$endif REMAP_VECTTAB}
-end;
\ No newline at end of file
+end;

Reply by email

Florian Klämpfl
to Michael Ring
Michael Ring wrote 7 lines
When rtl for arm-embedded/arm-freertos is build with hardfloat the fpu should also automagically get enabled, by default it is off which causes a crash when floats are used. This small patch fixes that problem in cortexm4f_start.inc can you please apply this patch to trunk?

Thanks, I applied it in a modified form so the presence of an vfp unit is checked, this should be more future and fool proof :)

Reply by email

Michael Ring
to Florian Klämpfl

You are the best, thank you!

Michael

Florian Klämpfl wrote 14 lines
Am 19.02.21 um 21:55 schrieb Michael Ring via fpc-devel: > When rtl for arm-embedded/arm-freertos is build with hardfloat the > fpu should also automagically get enabled, by default it is off which > causes a crash when floats are used. > > This small patch fixes that problem in cortexm4f_start.inc > > can you please apply this patch to trunk? Thanks, I applied it in a modified form so the presence of an vfp unit is checked, this should be more future and fool proof :) _______________________________________________ fpc-devel maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Michael Ring
to Michael Ring

I have created an issue with this patch for ermbedded target, for unknown reason the 'end;' at the end of the patch for rtl/embedded/arm/cortexm4f_start.inc is missing, likely when I copy/pasted I lost that line. Sorry for this....

Will there in the future be a way to provide pull-requests via github (or does this already work??) I guess that would reduce the likelyhood of such a stupid error..

And then I also found another small mishap in
rtl/freertos/arm/cortexm4f_start.inc, there a 'not' was left over after you changed the logic for fpu detection.

When Investigating I saw that lm4f120 is built as armv7m but is actually armv7em (plus it uses m4f include). Not sure if it is woth fixing a seven years old file, so I left things as they are.

Michael

diff --git a/rtl/embedded/arm/cortexm4f_start.inc
b/rtl/embedded/arm/cortexm4f_start.inc
index dc2928c70a..62017d9834 100644
--- a/rtl/embedded/arm/cortexm4f_start.inc
+++ b/rtl/embedded/arm/cortexm4f_start.inc
@@ -74,3 +74,4 @@ asm
 .Ltext_start:
   .long _text_start
 {$endif REMAP_VECTTAB}
+end;
diff --git a/rtl/freertos/arm/cortexm4f_start.inc
b/rtl/freertos/arm/cortexm4f_start.inc
index 756aeb994a..62017d9834 100644
--- a/rtl/freertos/arm/cortexm4f_start.inc
+++ b/rtl/freertos/arm/cortexm4f_start.inc
@@ -64,7 +64,7 @@ asm
   .long _data
 .L_edata:
   .long _edata
-{$if not defined(FPUARM_HAS_VFP_EXTENSION)}
+{$if defined(FPUARM_HAS_VFP_EXTENSION)}
 .Lcpacr:
   .long 0xE000ED88
 {$endif defined(FPUARM_HAS_VFP_EXTENSION)}

Michael Ring wrote 22 lines
You are the best, thank you! Michael Am 19.02.21 um 22:11 schrieb Florian Klämpfl via fpc-devel: > Am 19.02.21 um 21:55 schrieb Michael Ring via fpc-devel: >> When rtl for arm-embedded/arm-freertos is build with hardfloat the >> fpu should also automagically get enabled, by default it is off >> which causes a crash when floats are used. >> >> This small patch fixes that problem in cortexm4f_start.inc >> >> can you please apply this patch to trunk? > > Thanks, I applied it in a modified form so the presence of an vfp > unit is checked, this should be more future and fool proof :) > _______________________________________________ > fpc-devel maillist  -  > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel _______________________________________________ fpc-devel maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Florian Klämpfl
to Michael Ring
Michael Ring wrote
I have created an issue with this patch for ermbedded target, for unknown reason the 'end;' at the end of the patch for rtl/embedded/arm/cortexm4f_start.inc is missing, likely when I copy/pasted I lost that line. Sorry for this....

I committed it.

Will there in the future be a way to provide pull-requests via github (or does this already work??) I guess that would reduce the likelyhood of such a stupid error..

Most likely yes, however, so far nobody really found the time for the switch to git.

Show quoted text 8 lines
And then I also found another small mishap in rtl/freertos/arm/cortexm4f_start.inc, there a 'not' was left over after you changed the logic for fpu detection. When Investigating I saw that lm4f120 is built as armv7m but is actually armv7em (plus it uses m4f include). Not sure if it is woth fixing a seven years old file, so I left things as they are.

This doesn't matter imo, it should be fixed. So you mean just moving it to another subarch in the makefile?

Reply by email

Michael Ring
to Florian Klämpfl

lm4f120: yes, it should be moved in the makefile. But let me dig a little big, perhaps there are more files that are wrong, will come back to you.

Michael

Florian Klämpfl wrote 30 lines
Am 20.02.21 um 10:35 schrieb Michael Ring via fpc-devel: > I have created an issue with this patch for ermbedded target, for > unknown reason the 'end;' at the end of the patch for > rtl/embedded/arm/cortexm4f_start.inc is missing, likely when I > copy/pasted I lost that line. Sorry for this.... I committed it. > > Will there in the future be a way to provide pull-requests via github > (or does this already work??) I guess that would reduce the > likelyhood of such a stupid error.. Most likely yes, however, so far nobody really found the time for the switch to git. > > And then I also found another small mishap in > rtl/freertos/arm/cortexm4f_start.inc, there a 'not' was left over > after you changed the logic for fpu detection. > > When Investigating I saw that lm4f120 is built as armv7m but is > actually armv7em (plus it uses m4f include). Not sure if it is woth > fixing a seven years old file, so I left things as they are. This doesn't matter imo, it should be fixed. So you mean just moving it to another subarch in the makefile? _______________________________________________ fpc-devel maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Michael Ring
to Michael Ring

the lm4f120 was the only unit that did not fit. funny enough it was already defined for armv7em so this patch only removes it from armv7m

diff --git a/rtl/embedded/Makefile b/rtl/embedded/Makefile index 1b39161b56..e3242e2a2b 100644
--- a/rtl/embedded/Makefile
+++ b/rtl/embedded/Makefile
@@ -374,7 +374,7 @@ CPU_SPECIFIC_COMMON_UNITS=
 ifeq ($(ARCH),arm)
 CPU_SPECIFIC_COMMON_UNITS=sysutils math classes fgl macpas typinfo types rtlconsts getopts lineinfo
 ifeq ($(SUBARCH),armv7m)
-CPU_UNITS=lm3fury lm3tempest stm32f10x_ld stm32f10x_md stm32f10x_hd stm32f10x_xl stm32f10x_conn stm32f10x_cl lpc13xx lpc1768 lm4f120 sam3x8e xmc4500 cortexm3 cortexm4 # thumb2_bare
+CPU_UNITS=lm3fury lm3tempest stm32f10x_ld stm32f10x_md stm32f10x_hd stm32f10x_xl stm32f10x_conn stm32f10x_cl lpc13xx lpc1768 sam3x8e xmc4500 cortexm3 cortexm4 # thumb2_bare
 CPU_UNITS_DEFINED=1
 endif
 ifeq ($(SUBARCH),armv7em)
diff --git a/rtl/embedded/Makefile.fpc b/rtl/embedded/Makefile.fpc index ff89dc336c..8817d786bd 100644
--- a/rtl/embedded/Makefile.fpc
+++ b/rtl/embedded/Makefile.fpc
@@ -71,7 +71,7 @@ CPU_SPECIFIC_COMMON_UNITS=
 ifeq ($(ARCH),arm)
 CPU_SPECIFIC_COMMON_UNITS=sysutils math classes fgl macpas typinfo types rtlconsts getopts lineinfo
 ifeq ($(SUBARCH),armv7m)
-CPU_UNITS=lm3fury lm3tempest stm32f10x_ld stm32f10x_md stm32f10x_hd stm32f10x_xl stm32f10x_conn stm32f10x_cl lpc13xx lpc1768 lm4f120 sam3x8e xmc4500 cortexm3 cortexm4 # thumb2_bare
+CPU_UNITS=lm3fury lm3tempest stm32f10x_ld stm32f10x_md stm32f10x_hd stm32f10x_xl stm32f10x_conn stm32f10x_cl lpc13xx lpc1768 sam3x8e xmc4500 cortexm3 cortexm4 # thumb2_bare
 CPU_UNITS_DEFINED=1
 endif
 ifeq ($(SUBARCH),armv7em)

Michael Ring wrote 41 lines
lm4f120: yes, it should be moved in the makefile. But let me dig a little big, perhaps there are more files that are wrong, will come back to you. Michael Am 20.02.21 um 21:51 schrieb Florian Klämpfl via fpc-devel: > Am 20.02.21 um 10:35 schrieb Michael Ring via fpc-devel: >> I have created an issue with this patch for ermbedded target, for >> unknown reason the 'end;' at the end of the patch for >> rtl/embedded/arm/cortexm4f_start.inc is missing, likely when I >> copy/pasted I lost that line. Sorry for this.... > > I committed it. > >> >> Will there in the future be a way to provide pull-requests via >> github (or does this already work??) I guess that would reduce the >> likelyhood of such a stupid error.. > > Most likely yes, however, so far nobody really found the time for the > switch to git. > >> >> And then I also found another small mishap in >> rtl/freertos/arm/cortexm4f_start.inc, there a 'not' was left over >> after you changed the logic for fpu detection. >> >> When Investigating I saw that lm4f120 is built as armv7m but is >> actually armv7em (plus it uses m4f include). Not sure if it is woth >> fixing a seven years old file, so I left things as they are. > > This doesn't matter imo, it should be fixed. So you mean just moving > it to another subarch in the makefile? > _______________________________________________ > fpc-devel maillist  -  > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel _______________________________________________ fpc-devel maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email