cancel
Showing results for 
Search instead for 
Did you mean: 

How to print Float values on Keil IDE

SIDRI.1
Associate III

0693W000008zC2XQAU.pngI 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.

4 REPLIES 4

Check Use MicroLIB, should by default support printf("%lf\n",x) or dtoa()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
SIDRI.1
Associate III

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).

GWang.3
Associate III

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

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..