PRINTF support for Scientific Notation, "e" specifier in KSDK 2.0

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

PRINTF support for Scientific Notation, "e" specifier in KSDK 2.0

ソリューションへジャンプ
1,039件の閲覧回数
marks
Contributor IV

Hello,

How do you get the "e" specifier to work with PRINTF in KSDK 2.0? Using IAR. 

 

For example, this code:

#include "fsl_debug_console.h"

#define PRINTF DbgConsole_Printf

float a_float_number = 123456.78;
PRINTF(" a_float_number = %e\n", a_float_number);
PRINTF(" a_float_number = %f\n", a_float_number);

 

generates this output:

 

a_float_number = e
a_float_number = 123456.781250

 

The same code works as expected in a KDSK 1.3 project with lower case printf. This is the output with KDSK 1.3:

 

a_float_number = 1.234568e+05
a_float_number = 123456.781250

 

I put #include <stdio.h> in the file but this made no difference. 

 

Maybe it is just not supported. The e specifere is not listed in the Kinetis SDK v.2.0 API Reference Manual in section 12.1.2 Advanced Feature. However, the e specifier is mentioned when discussing the # flag "Used with e, E and f, it forces the written output to contain a decimal point even if no digits would follow."

 

If e is not supported maybe it could be added next rev.

 

Any help would be greatly appreciated!

 

Thanks,

Mark

ラベル(1)
タグ(1)
0 件の賞賛
1 解決策
697件の閲覧回数
egoodii
Senior Contributor III

ASSUMING you are using the IAR-library (and not an explicit printf handler routine in your project) what size 'printf formatter' have you got selected on 'project-options-general_options-library_options' tab --- tiny, small, large, or full?  Each 'bigger' version gives more runtime formatting options (at the expense of size and speed, of course).

I am not personally familiar with "fsl_debug_console.h", but if it were ME I would let the IAR tool-library support true 'printf', and do the proper tie from their output as __write() to 'whatever' console stream this is ending up on.

元の投稿で解決策を見る

0 件の賞賛
3 返答(返信)
697件の閲覧回数
DavidS
NXP Employee
NXP Employee

Hi Mark,

Looking into the source code for PRINTF the "%e" format is not supported.  The formats I see in fsl_debug_console.c are:

if ((c == 'd') || (c == 'i') || (c == 'f') || (c == 'F') || (c == 'x') || (c == 'X') || (c == 'o') || (c == 'b') || (c == 'p') || (c == 'u'))

I took KSDK_v2 hellow_world example for FRDM-K64F and made the following changes to create a workaround for you:

#include <stdio.h> //DES test for "e" format support in sprintf

#if 1 //DES 1=change output format, 0=default code
float a_float_number = 123456.78;
char my_string_buffer[60];

sprintf(my_string_buffer, "%e", a_float_number);
PRINTF(" a_float_number = %s\n\r", my_string_buffer);
PRINTF(" a_float_number = %e\n\r", a_float_number);
PRINTF(" a_float_number = %f\n\r", a_float_number);
#endif

Terminal Output:

a_float_number = 1.234568e+05      <-- This used sprintf then PRINTF %s to get desired result
a_float_number = e
a_float_number = 123456.781250

Source hellow_world.c attached.

Regards,

David 

697件の閲覧回数
marks
Contributor IV

Hi David, Tried your method first (before Earls above) and it did not work first pass. Then changed project-options-general_options-library_options' tab --- to full and your solution, as well as the lower case printf, now work!

Thank you for the help!!

Best regards,

Mark

0 件の賞賛
698件の閲覧回数
egoodii
Senior Contributor III

ASSUMING you are using the IAR-library (and not an explicit printf handler routine in your project) what size 'printf formatter' have you got selected on 'project-options-general_options-library_options' tab --- tiny, small, large, or full?  Each 'bigger' version gives more runtime formatting options (at the expense of size and speed, of course).

I am not personally familiar with "fsl_debug_console.h", but if it were ME I would let the IAR tool-library support true 'printf', and do the proper tie from their output as __write() to 'whatever' console stream this is ending up on.

0 件の賞賛