printf and floats

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

printf and floats

1,941 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by g_mocken on Fri Jun 26 02:56:38 MST 2015
Hi,

generally I am aware of stack size  and library selection issues when using printf with floats. Using lplink2 with 4370, I have no problems to print floats to either UART or to the console via semihosting.

But when I use the same code (or a minimal test project) on a custom board with 4074, it always runs into a HardFault. The stack trace is:

Thread [1] <main> (Suspended : Signal : SIGSTOP:Stopped (signal))
HardFault_Handler() at cr_startup_lpc407x_8x.c:371 0x228
<signal handler called>() at 0xfffffff9
fp_display() at 0x1488
__vfprintf() at 0x24c2
printf_char() at 0x1146
main() at Test_4074_board.c:41 0x326

In this case, I was linking with RedLib(semihost) and trying in main() to perform:

    DEBUGOUT("float: %f\r\n", 123.456f);

I also tried more complex variants (e.g putting this line into a FreeRTOS task that was created with a large stack size), but with no success on 4074.

Any help would be appreciated.
Labels (1)
0 Kudos
5 Replies

1,108 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by www.FreeRTOS.org on Wed Jul 01 03:20:34 MST 2015
To use FreeRTOS on a Cortex-M3 part or a Cortex-M4 part that does not have an FPU (or if the FPU is turned off) then use the port files from FreeRTOS/source/portable/GCC/ARM_CM3.

To use FreeRTOS on a Cortex-M4F part (with hardware FPU) use the port files from FreeRTOS/source/portable/GCC/ARM_CM4F.

Hope this helps.



0 Kudos

1,108 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by g_mocken on Wed Jul 01 03:06:39 MST 2015

Quote: TheFallGuy
Looks like you have configured FreeRTOS for hardware float. Look at the FreeRTOS configuration header.



There is no such thing to configure in there. However I have now switched to the CM3 port (instead of CM4F) which can (only) be compiled without FPU support and apparently also runs on the CM4. It works!
0 Kudos

1,108 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheFallGuy on Fri Jun 26 23:42:14 MST 2015
Looks like you have configured FreeRTOS for hardware float. Look at the FreeRTOS configuration header.
0 Kudos

1,108 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by g_mocken on Fri Jun 26 11:06:59 MST 2015

Quote: lpcxpresso-support

But another possibility is that your project is configured to use hardware floating point - but the LPC4074 (unlike most LPC40xx parts) doesn't actually implement hardware FP.
Thus check your project settings



I am using "SoftABI". What should I use instead? "HardABI" crashes in the same way. "None" does not compile with FreeRTOS.
"None" does however solve the problem for a minimal test project without FreeRTOS!

Assuming that "None" is the way to go, do you have any additional hint on how to deal with FreeRTOS' compilation errors:

arm-none-eabi-gcc -std=c99 -D__MULTICORE_NONE -DDEBUG -D__CODE_RED -DCORE_M4 -D__USE_LPCOPEN -D__REDLIB__ -DCR_PRINTF_CHAR -I"/home/guido/lpc_workspace/lpc_chip_40xx/inc" [various other source files] -Og -g3 -Wall -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -fsingle-precision-constant -mcpu=cortex-m4 -mthumb -D__REDLIB__ -specs=redlib.specs -MMD -MP -MF"freertos/src/port.d" -MT"freertos/src/port.o" -MT"freertos/src/port.d" -o "freertos/src/port.o" "../freertos/src/port.c"
/tmp/ccQgaxFT.s: Assembler messages:
/tmp/ccQgaxFT.s:306: Error: selected processor does not support Thumb mode `vstmdbeq r0!,{s16-s31}'
/tmp/ccQgaxFT.s:308: Error: instruction not allowed in IT block -- `stmdb r0!,{r4-r11,r14}'
/tmp/ccQgaxFT.s:329: Error: selected processor does not support Thumb mode `vldmiaeq r0!,{s16-s31}'
/tmp/ccQgaxFT.s:331: Error: instruction not allowed in IT block -- `msr psp,r0'
make: *** [freertos/src/port.o] Fehler 1

?

On closer inspection , I noticed this line in port.c (the #error did not trigger, though):

#ifndef __VFP_FP__
#error This port can only be used when the project options are configured to enable hardware floating point support.
#endif


So is there any FreeRTOS port that can be used on lpc4074?
0 Kudos

1,108 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Fri Jun 26 08:28:09 MST 2015
Its always possible that you have run out of stack/heap.

http://www.lpcware.com/content/faq/lpcxpresso/heap-checking-redlib

But another possibility is that your project is configured to use hardware floating point - but the LPC4074 (unlike most LPC40xx parts) doesn't actually implement hardware FP.

Thus check your project settings - for more details see: http://www.lpcware.com/content/faq/lpcxpresso/cm4-floating-point

If that doesn't fix it, then it would be useful to see what exactly is triggering the hard fault - use the following FAQ as a guide on how to do this:

http://www.lpcware.com/content/faq/lpcxpresso/debugging-hard-fault

Regards,
LPCXpresso Support
0 Kudos