Printing negative floats with DbgConsole_Printf in mcuxpresso SDK 2.15

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Printing negative floats with DbgConsole_Printf in mcuxpresso SDK 2.15

跳至解决方案
790 次查看
laugechristense
Contributor II

Hi All,

 

I have a problem using DbgConsole_Printf for printing negative floats on a custom board using mcuxpresso IDE 11.8 and mcuxpresso SDK version 2.12.

I have isolated the problem and see the same behavior with the demo projects on an lpcxpresso55s36 eval-board with the newest IDE and SDK versions. I went through a bunch of posts but can't seem to solve the problem.

 

How to reproduce the problem:

Using mcuxpresso IDE 11.9.0 open "Import SDK example(s)"...

select lpcxpresso55s36 board.

select the "hello_world" project under "demo_apps" and click next.

Check the box "Redlib: Use floating point version of printf" and leave other settings at default values.

laugechristense_0-1706178943806.png

I have modified main() by adding 4 lines using PRINTF.

PRINTF("hello world.\r\n");
PRINTF("%f\r\n", (float) 12.34);
PRINTF("%f\r\n", (float) -12.34);
PRINTF("%f\r\n", (float) 1);
PRINTF("%f\r\n", (float) -1);

 

All five lines print. However, the negative floats are printed without a minus sign and with incorrect characters. The output is:

hello world.
12.340000
12./40000
1.000000
1.//////

The error seems to arise in "DbgConsole_ConvertFloatRadixNumToString" when it scans through the digits of the negative fractpart.

 

Please let me know if I need to provide more information.

How do I use the debug console with negative floats?

 

Kind regards Lauge

0 项奖励
回复
1 解答
718 次查看
Alex_Wang
NXP Employee
NXP Employee

Hi,  @laugechristense 

Thank you for your reply. Yes, the PRINTF() function should be used frequently in projects, and for floating negative types you can use the printf() function first.

Best regards, Alex

在原帖中查看解决方案

0 项奖励
回复
3 回复数
728 次查看
laugechristense
Contributor II

Thank you @Alex_Wang 

I got your solution to work. As far as I can see, your code avoids the SDK debug_console. Should it just not be used in general?

 

Kind regards Lauge

0 项奖励
回复
719 次查看
Alex_Wang
NXP Employee
NXP Employee

Hi,  @laugechristense 

Thank you for your reply. Yes, the PRINTF() function should be used frequently in projects, and for floating negative types you can use the printf() function first.

Best regards, Alex

0 项奖励
回复
763 次查看
Alex_Wang
NXP Employee
NXP Employee

Hello, @laugechristense 

You can try it out by following these steps:

1. Add #include "stdio.h":

Alex_Wang_0-1706259786553.png

 

2. Set macro definition SDK_DEBUGCONSOLE_UART=1, right-click project -> Open the properties window and refer to the following image:

Alex_Wang_1-1706259805704.png

 

3.Use the printf () function to print normally.

	printf("%f\r\n", (float) -12.34);
	printf("%f\r\n", (float) -12.34);
	printf("%f\r\n", (float) 1);
	printf("%f\r\n", (float) -1);

The results are as follows:

Alex_Wang_2-1706259861643.png

Best regards, Alex

0 项奖励
回复