PRINTF in KDS

cancel
Showing results for 
Search instead for 
Did you mean: 

PRINTF in KDS

Jump to solution
1,364 Views
aerodame
Contributor III

I'm getting a strange output from PRINTF for formatted printing of floating point numbers using the %f.

 

Heres's my string...

 

 

PRINTF("t:%.6f\tx:%.4f\ty:%.4f\r\n",t,(float) x,(float)y);

 

But for some reason if I have x = -0.4935 in the debugger   The output of the PRINTF for that negative float number is:  -1.4935.   Is there a bug for negative numbers in PRINTF?

 

And why doesn't the library just use the standard lower case printf?  Why the non-standard uppercase version?

Labels (1)
0 Kudos
1 Solution
334 Views
DavidS
NXP Employee
NXP Employee

Hi Stephen

Thank you for the project.  A project is like a thousand words ;-)

I think there is an issue as you sate in the printf routine.

Attached is my updated fsl_debug_console.c that made two modifications in DbgConsole_ConvertFloatRadixNumToString() starting at line 611 .

    if (r >= 0)

    {

        fa = fractpart + (double)0.5;

        if (fa >= pow(10, precision_width))

        {

        fractpart++; //DES was intpart++;

        }

    }

    else

    {

        fa = fractpart - (double)0.5;

        if (fa <= pow(-10, precision_width))

        {

        fractpart--; //DES was intpart--;

        }

    }

Please let me know if this resolves your issue and I will report it to the KSDK_v2 team formally.

Sorry for the hassles.

Regards,

David

View solution in original post

11 Replies
334 Views
DavidS
NXP Employee
NXP Employee

Hi Stephen,

Did it work?

I see others have been helping on your new post.  I am following it too.

Regards,

David

0 Kudos
334 Views
aerodame
Contributor III

Yes, did indeed.  Thanks so much for the quick response.

0 Kudos
334 Views
aerodame
Contributor III

Uploading the example project (complete project that can be imported into KDS).

0 Kudos
335 Views
DavidS
NXP Employee
NXP Employee

Hi Stephen

Thank you for the project.  A project is like a thousand words ;-)

I think there is an issue as you sate in the printf routine.

Attached is my updated fsl_debug_console.c that made two modifications in DbgConsole_ConvertFloatRadixNumToString() starting at line 611 .

    if (r >= 0)

    {

        fa = fractpart + (double)0.5;

        if (fa >= pow(10, precision_width))

        {

        fractpart++; //DES was intpart++;

        }

    }

    else

    {

        fa = fractpart - (double)0.5;

        if (fa <= pow(-10, precision_width))

        {

        fractpart--; //DES was intpart--;

        }

    }

Please let me know if this resolves your issue and I will report it to the KSDK_v2 team formally.

Sorry for the hassles.

Regards,

David

View solution in original post

334 Views
aerodame
Contributor III

Excellent... will try that in a moment...

I have another issue that is troubling me too where when I create a brand new project and try to debug it... the debugger comes up running but doesn't run to main and stop...  (in fact, it doesn't even load the code).

I have a mix of cloned projects that I can get to work and then brand new ones that always have this issue...  I'm searching through the settings between the PRINTF demo that DOES debug and the brand new ones I have that don't work.

Like I said, I'll start a new topic on this, but be on the lookout for it if you will.

0 Kudos
334 Views
aerodame
Contributor III

OK, finally had some time to study this problem from two angles.  I'm fairly certain there is a bug in the PRINTF library.  Here's a slightly modified version of your helloprintf program with a printout from a positive and negative sine wave of a amplitude 1.0 and 2.0.  There is something wrong with float outputs were the negative numbers are offset by -1.

sine wave test:

0

0.156434

0.309017

0.453990

0.587785

0.707106

0.809017

0.891006

0.951056

0.987688

1.000000

0.987689

0.951057

0.891007

0.809018

0.707108

0.587787

0.453992

0.309019

0.156436

0.000002

-1.156432

-1.309014

-1.453988

-1.587783

-1.707104

-1.809015

-1.891005

-1.951055

-1.987688

-2.000000

-1.987689

-1.951058

-1.891009

-1.809020

-1.707111

-1.587791

-1.453996

-1.309024

-1.156442

-1.000007

sine wave test (amplitude of 2):

0

0.312869

0.618033

0.907980

1.175570

1.414213

1.618033

1.782012

1.902112

1.975376

2.000000

1.975377

1.902114

1.782014

1.618036

1.414216

1.175573

0.907984

0.618037

0.312873

0.000004

-1.312864

-1.618029

-1.907976

-2.175565

-2.414208

-2.618030

-2.782009

-2.902110

-2.975375

-3.000000

-2.975378

-2.902117

-2.782018

-2.618041

-2.414222

-2.175581

-1.907993

-1.618047

-1.312884

-1.000015

0 Kudos
334 Views
aerodame
Contributor III

I didn't have those options in my preprocessor settings, but added them anyway.. no Joy.

I will try your hello project tomorrow in a K22F project to see if it changes anything.

THanks!

0 Kudos
334 Views
DavidS
NXP Employee
NXP Employee

Hi Stephen,

Please let me know your results.

Can you post the project you have that is not working?

Regards,

David

0 Kudos
334 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Stephen,

Please tell me the version of KDS, your chip part number, and does your project is MQX project, ksdk project , or PE project

...

About the uppercase  PRINTF,  there is no special meaning , it also defined from  the "printf" .

BR

Alice

0 Kudos
334 Views
aerodame
Contributor III

Kinetis Design Studio  Version: 3.2.0

My project is just a new non-RTOS KSDK 2.0 project where I've added source code files that utilize the

#include "fsl_debug_console.h"

To obtain the PRINTF capability.

Platform is the FRDM-K22F.

It appears to me that there might be a bug in the printf capability for floating point numbers that are negative.  I will do some additional testing this morning also with integer positive and negative numbers and report back.

0 Kudos
334 Views
DavidS
NXP Employee
NXP Employee

Hi Stephen,

I'm using a FRDM-K64F with KSDK_v2.  I cloned the hello_world example and placed it in my path as follows:

C:\NXP\KSDK_v2\SDK_2.0_FRDM-K64F_KDS\boards\frdmk64f\user_apps\hello_world_fp

I think you just need to enable the #defines in the Properties->C/C++ Build->Settings->Tools Settings-> Cross ARM C Compiler->Preprocessor

pastedImage_0.png

All of the PRINTF/SCANF were=0.  I changed to =1.

Regards,

David

PS

I tested on FRDM-K22F successfully too using the standard hello_word example in KSDK_v2.