Skip to main content
SIDRI.1
Associate III
April 11, 2021
Question

How to print Float values on Keil IDE

  • April 11, 2021
  • 3 replies
  • 3561 views

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.

This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
April 11, 2021

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

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
SIDRI.1
SIDRI.1Author
Associate III
April 11, 2021

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

Tesla DeLorean
Guru
April 11, 2021

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 VenmoUp vote any posts that you find helpful, it shows what's working..
GWang.3
Associate II
April 11, 2021

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