Hi community,
I am trying to setup sprintf to print float numbers to string.
I tried everything I found, changed libraries, but nothing brought a success.
Either I get not the right result or I get an hardfault when trying to print negative float values.
Actual processor LPC5506
Floating point unit FPv5-SP-D16 Hard ABI set
current library setting Redlib semihost
I am using UART0 to print
PreProcessor settings
CPU_LPC5506JBD64
CPU_LPC5506JBD64_cm33
SDK_OS_BAREMETAL
SDK_DEBUGCONSOLE=2
SERIAL_PORT_TYPE_UART=1
PRINTF_FLOAT_ENABLE=1
SCANF_FLOAT_ENABLE=1
PRINTF_ADVANCED_ENABLE=1
SCANF_ADVANCED_ENABLE=1
__MCUXPRESSO
__USE_CMSIS
DEBUG
DISABLEFLOAT16
__REDLIB__
trying this code
float P_Value = 3.123456f;
float I_Value = 123.4567f;
float D_Value = 0.654321f;
sprintf(g_txBuffer, "rpm = %d, P_Value = %f, I_Value = %f, D_Value = %f \r", rpm_ist, P_Value, I_Value, D_Value);
no warnings or errors
And the result is
rpm = 206, P_Value = -0.000000, I_Value = -0.000000, D_Value = -0.000000 <CR>
Is there a way to get sprintf to print the right values including negative values or do I have to write my own converter?
What I do not see?
Thanks in advance
Thanks for the fast answer, but this does not help.
All what you are proposing is already set and tried, but no success.
Compiler uses this
arm-none-eabi-gcc -DCPU_LPC5506JBD64 -DCPU_LPC5506JBD64_cm33 -DSDK_OS_BAREMETAL -DSDK_DEBUGCONSOLE=2 -DSERIAL_PORT_TYPE_UART=1 -DPRINTF_FLOAT_ENABLE=1 -DSCANF_FLOAT_ENABLE=1 -DPRINTF_ADVANCED_ENABLE=1 -DSCANF_ADVANCED_ENABLE=1 -D__MCUXPRESSO -D__USE_CMSIS -DDEBUG -DDISABLEFLOAT16 -D__REDLIB__ -I"D:\Software\FC5706P_workspace\FC5706P101B001\drivers" -I"D:\Software\FC5706P_workspace\FC5706P101B001\device" -I"D:\Software\FC5706P_workspace\FC5706P101B001\component\serial_manager" -I"D:\Software\FC5706P_workspace\FC5706P101B001\utilities" -I"D:\Software\FC5706P_workspace\FC5706P101B001\component\uart" -I"D:\Software\FC5706P_workspace\FC5706P101B001\CMSIS" -I"D:\Software\FC5706P_workspace\FC5706P101B001\component\lists" -I"D:\Software\FC5706P_workspace\FC5706P101B001\CMSIS_driver\Include" -I"D:\Software\FC5706P_workspace\FC5706P101B001\CMSIS\DSP\Include" -I"D:\Software\FC5706P_workspace\FC5706P101B001\CMSIS\DSP\PrivateInclude" -I"D:\Software\FC5706P_workspace\FC5706P101B001\CMSIS\DSP\Source\DistanceFunctions" -I"D:\Software\FC5706P_workspace\FC5706P101B001\CMSIS\NN\Include" -I"D:\Software\FC5706P_workspace\FC5706P101B001\board" -I"D:\Software\FC5706P_workspace\FC5706P101B001\source" -O0 -fno-common -g3 -gdwarf-4 -Wall -c -ffunction-sections -fdata-sections -fno-builtin -fmerge-constants -fmacro-prefix-map="../CMSIS/DSP/Source/BasicMathFunctions/"= -mcpu=cortex-m33 -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mthumb -D__REDLIB__ -fstack-usage -specs=redlib.specs -MMD -MP -MF"CMSIS/DSP/Source/BasicMathFunctions/BasicMathFunctionsF16.d" -MT"CMSIS/DSP/Source/BasicMathFunctions/BasicMathFunctionsF16.o" -MT"CMSIS/DSP/Source/BasicMathFunctions/BasicMathFunctionsF16.d" -o "CMSIS/DSP/Source/BasicMathFunctions/BasicMathFunctionsF16.o" "../CMSIS/DSP/Source/BasicMathFunctions/BasicMathFunctionsF16.c"
Hi @SvenAsbach
Did you include "stdio.h"? We need to make sure we have this header file included.
I just tested sprintf with your code, there is no issue on my side. See attached video.
Please also make sure you use floating point version of printf.
Can you please checking your issue with refering my screenshot and testing video?
Best Regards
Jun Zhang
Hi @SvenAsbach
If you use SDK demo, please try to enable floating support
Make sure the defined symbols, printf float is enabled.
Does this work for you?
Best Regards
Jun Zhang
Usually the problem is that CR_INTEGER_PRINTF is still defined in the -D options list.
Make sure you do a full 'clean' of the build an retry.
These are my (working) defines and Linker settings:
__REDLIB__
CPU_LPC55S69JBD100
CPU_LPC55S69JBD100_cm33
CPU_LPC55S69JBD100_cm33_core0
SDK_DEBUGCONSOLE=1
PRINTF_FLOAT_ENABLE=1
SERIAL_PORT_TYPE_UART=1
__MCUXPRESSO
__USE_CMSIS
DEBUG
I hope this helps,
Erich