cancel
Showing results for 
Search instead for 
Did you mean: 

How to enable snprintf float?

DEyer.1
Associate II

Hello,

I'm trying to snprintf into a data buffer, but the application dies precisely on this call. I'm not using nanolib because I want exceptions. My CMake file looks like this: Notice that I added the -u printf_float to the linker flags. Is this not all that is needed?

 

Thanks for any help!

set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_PROCESSOR arm) set(CMAKE_C_COMPILER_FORCED TRUE) set(CMAKE_CXX_COMPILER_FORCED TRUE) set(CMAKE_C_COMPILER_ID GNU) set(CMAKE_CXX_COMPILER_ID GNU) # set standard c++ version set(CMAKE_CXX_STANDARD 17) # Some default GCC settings # arm-none-eabi- must be part of path environment # set(TOOLCHAIN_PREFIX arm-none-eabi-) set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc) set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER}) set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++) set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}g++) set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy) set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size) set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf") set(CMAKE_EXECUTABLE_SUFFIX_C ".elf") set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf") set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) # MCU specific flags set(TARGET_FLAGS "-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard ") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_FLAGS}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -fdata-sections -ffunction-sections -fexceptions") if(CMAKE_BUILD_TYPE MATCHES Debug) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g3") endif() if(CMAKE_BUILD_TYPE MATCHES Release) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -g0") endif() set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp -MMD -MP") set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-threadsafe-statics -fexceptions -funwind-tables") # add_compile_options(-fexceptions) # add_compile_options(-funwind-tables) # set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions -fno-threadsafe-statics") set(CMAKE_C_LINK_FLAGS "${TARGET_FLAGS}") set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -T \"${CMAKE_SOURCE_DIR}/stm32g474retx_flash.ld\"") # set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --specs=nano.specs") set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections") set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--start-group -lc -lm -Wl,--end-group") set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--print-memory-usage") set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -u _printf_float") set(CMAKE_CXX_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--start-group -lstdc++ -lsupc++ -Wl,--end-group")
View more
1 REPLY 1
DEyer.1
Associate II

DEyer1_0-1736864026499.png

 

This is what the call stack looks like, Note "_log" is is my function which calls the snprintf. All buffers as are and big enough and the format specificer is also correct "Some float value %f". Any ideas?