K70 Printf to UART with Floating point - bare matal

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

K70 Printf to UART with Floating point - bare matal

2,792件の閲覧回数
PRJOY
Contributor II

On the Kinetis family  K70 example bare metal project printf & sprintf function do not support floating point.

but we need float value print also.

Pls help ..!

Regards,

PRJOY

ラベル(1)
5 返答(返信)

1,221件の閲覧回数
dorianhildebran
Contributor I

I use PEX, but maybe it works with bm also, i dont know.

In Project Properties -> C/C++ Build -> Settings -> Tools Settings -> Librarian -> Print formats

the default setting is "int". If you change it to "int_FP" you can print %d and %f

Hope it helps.

0 件の賞賛
返信

1,221件の閲覧回数
DavidS
NXP Employee
NXP Employee

Hi PRJOY,

The example baremetal code has its own printf() function that does only simple stuff to keep the printf() code size manageable for a small MCU.

You can use the development tools libraries for complex printf/scanf stuff.

I used CW10.2 and creted a new baremetal project.

Opened the project properties dialog box and made change to the Librarian settings (Print and Scan Formats now set to "int_FP").

The code I ran is:

/*
* main implementation: use this 'C' sample to create your own application
*
*/


#include <math.h> //DES added
#include <stdio.h>

#include "derivative.h" /* include peripheral declarations */

void mypow(double x, double y);  //prototype


int main(void)
{
int counter = 0;
float x=3.14678234;

printf("Hello (Kinetis) World in 'C' from MK70FN1M0 derivative! \n\r");

for(;;) {   
     counter++;
     mypow((double)2,(double)counter);
     printf("x=%f\n", x*(counter+3.1244232));
}

return 0;
}

void mypow(double x, double y)
{
double p;

y+=0.257;
x+=1.25;

p = pow(x, y);
switch (fpclassify(p))
{
  case FP_ZERO:
  case FP_NORMAL:
  case FP_SUBNORMAL:
   printf("%f ", p);
   break;
  default:
   printf("error in pow()");
   break;
}
}

 

The terminal output is:

Hello (Kinetis) World in 'C' from MK70FN1M0 derivative!

4.399845 x=12.978662

14.299496 x=16.125445

46.473364 x=19.272227


Regards,

David

0 件の賞賛
返信

1,221件の閲覧回数
PRJOY
Contributor II

Hi David,

Thanks for the info,

I have verified the example.

In this example default print the printf() message to CWDS console window via OSBDM

but we want to print the float value to terminal window (Hyper terminal) via K70 MCU UARTx its possible, How?

Regards,

PRJOY

0 件の賞賛
返信

1,221件の閲覧回数
DavidS
NXP Employee
NXP Employee

Hi PRJOY,

Hopefully others will have a method for you to try but my solution is to use the CW10.2 sprintf() to format the string and use the baremetal printf() to output the result to the UART as I haven't found the solution for having the CW10.2 printf() directed to the UART of the K70.

Today I only had access to the TWR-K60N512 so I used the KINETIS512_SC.zip baremetal code's hello world as the starting point.

#include "common.h"

#include <stdio.h>      //DES

/********************************************************************/

void main (void)

{

      char ch;

    char buffer[100];   //DES        

      float x=3.14678234;

      int counter = 0;

     

      sprintf(buffer, "Hello World from sprintf");          <--uses the CW10.2 library since #include <stdio.h> added at top of file...note I commented out the baremetal sprintf() function and prototype.

      printf("%s\n", buffer);                                   <-- uses the baremetal printf() routine.

     

      counter++;

      sprintf(buffer,"x=%f", x*(counter+3.1244232));

      printf("%s\n", buffer);

      printf("\nHello World!!\n");

}

0 件の賞賛
返信

1,221件の閲覧回数
PRJOY
Contributor II

Hi David,

Thanks for the info.

0 件の賞賛
返信