2021-04-11 02:14 AM
I am developing a bare-metal project using the stm32F103 MCU, under Keil Uvision IDE,
I am not able to print the float values (from the temperature sensor), but it works fine with an integer.
Is there a method to use ,? I tried to implement another printf library but it doesn't work with float.
I have no option to select float value in my IDE as shown in the image.
Thank you.
2021-04-11 07:11 AM
Check Use MicroLIB, should by default support printf("%lf\n",x) or dtoa()
2021-04-11 01:44 PM
Thank's for response,
I have checked MicroLIB, my compiler shows these errors :
.\Objects\float.axf: Error: L6218E: Undefined symbol __use_two_region_memory (referred from startup_stm32f10x_md.o).
.\Objects\float.axf: Error: L6218E: Undefined symbol __initial_sp (referred from entry2.o).
2021-04-11 02:31 PM
Method 1:
#include <stdio.h>
float f1;
char buffer[20];
sprintf(buffer,"%7.2f\n",f1);
However, sprintf may not be thread-safe.
Method 2: - thread-safe approach
// display f1 in %7.2f format, assuming fl>=0
float f1;
uint32_t f1_int,f1_frac;
f1_int =f1; // integer part of f1 float number
f1_frac = (f1-f1_int)*100; // fractional part of float number f1
2021-04-11 04:19 PM
Use a template
STM32Cube_FW_F1_V1.8.0\Projects\STM32F103RB-Nucleo\Templates
or
Use the startup from here
STM32Cube_FW_F1_V1.8.0\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\arm\startup_stm32f100xb.s