[fpc-devel] Enabling hardware floating point processor for cortex-m4f on embedded and freertos

Michael Ring mail at michael-ring.org
Fri Feb 19 21:55:05 CET 2021


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;

-------------- next part --------------
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;


More information about the fpc-devel mailing list