trace_printf 不使用浮点数

trace_printf not working with floats

使用 Eclipse IDE 对 STM32F0xx 探索板进行编程。尝试做一些数学运算,购买 TIM2 时钟计数器并将其除以 48000000 以得出一个时间段。

如果我将我的工作变量声明为 uint32_t,它会给我截断的答案。我想要的是一个十进制值,我原以为将其声明为浮点数可以解决问题,但是当我这样做时,什么也不会打印出来。

variable = (TIM2->CNT)/48000000;
trace_printf("%i",variable);

与 uint32_t 声明的变量一起工作,但是将占位符更改为 %f 甚至保留原样以进行 float 声明会产生 nada。是否需要转换为浮点数?

我已经很久没有编写任何 C 代码了,我确信我在使用 CooCox 之前遇到过同样的问题,但我不记得当时的解决方案是什么。

TY @harmic! http://www.ece.uvic.ca/~brent/ceng355/printf.html

Printing Floating Point Numbers Using trace_printf

To enable the trace_printf to print floating point numbers do the following in your project.

  • Under the projects menu item select properties option.
  • Expand out the C/C++ Build Section and select the settings option.
  • Now select the tab "Tool Settings". Under the section "Cross ARM C++ Linker" select Miscellaneous.
  • Click the checkbox that says "Use float with nano printf (-u_printf_float).
  • Now click apply and then OK.
  • Rebuild your project and floating point numbers should now print.

Please see picture below for configuration settings and sample code with results.

这正是我所需要的。我会在 class 中宣传 link。