Sysprogs forums › Forums › VisualGDB › float in sprintf
- This topic has 7 replies, 4 voices, and was last updated 5 years ago by
Reza1757.
-
AuthorPosts
-
February 25, 2014 at 09:25 #722
alireza.r
Participanthello every one i tried to use sprintf and change a float variable to chars in visual stdio via VisualGDB
like:float a;
char b[5];sprinf(b,”%f”,a);
but it make hard fault in micro(stm407), how i can active float variable in sprintf or printf ?
February 25, 2014 at 22:13 #2897ket
ParticipantHi,
Please read our STM32F4 tutorial on the topic for hints:
http://visualgdb.com/tutorials/arm/stm32/fpu/February 26, 2014 at 12:50 #2896alireza.r
Participantthanks for your replay
but my problem is with hardware floating point. if i use software floating point the program run correctly
but when chose hardware floating point the hard fault occur.Note that -mfloat-abi=hard has been added to GCC flags correctly
i use sprintf(..) and in Disassembly it is vcvt.f64.f32
how can i solved this problem.March 3, 2014 at 04:43 #2894support
KeymasterHi,
This problem means that the standard C library has been compiled in a way that treats the ‘%f’ format in a way that uses the double type. We would recommend simply using an alternative implementation of sprintf() from some open-source library and tweaking it so that it only uses the float type.
March 3, 2014 at 11:39 #2895alireza.r
Participantthanks for your replay bazis
but i have this problem with float variable too.
i readied this link before
http://visualgdb.com/tutorials/arm/stm32/fpu/and i understood that this problem occre with double type but i just use float not double
and i have this problem.March 4, 2014 at 05:35 #2893support
KeymasterHi,
The problem is that printf() inside itself uses ‘double’. Although you pass a float there, it reads ‘%f’ in your string and somehow converts it to double. You cannot change this behavior by modifying your program as it is located inside the printf() that is a part of the standard library. You could either modify the standard library used by GCC (which is somewhat cumbersome), or simply use another open-source implementation of printf() (there should be plenty of those available online).
September 25, 2021 at 00:11 #31375Reza1757
ParticipantHi
I’m using vidualGDB for programming on STM32 microcontroller with visual studio 2019.
When I want to convert float into string with sprintf() function then it seems doesn’t work.
I want puts a buffer array on LCD but when I puts it float variable doesn’t visible…
I saw just characters and no number.
September 25, 2021 at 00:21 #31376Reza1757
Participant -
AuthorPosts
- You must be logged in to reply to this topic.