How can i use printf(using uart) on mpc5744

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can i use printf(using uart) on mpc5744

3,873 Views
fyw
Contributor IV

The platform is S32(S32 Design Studio for Power Architecture, Version 1.0 build 151127), now i can use uart send data to the serial port terminal. if i want to use "printf" with uart, how should i configure the project? 

Thank you very much!

 

  UART_SendData(&LINFlexD_X ,0xaa);  /* this is ok now*/

  printf ("Characters: %c %c \n", 'a', 65);    /*build err here  Description Resource Path Location Type

S32DS/e200_ewl/EWL_C/src/stdio/printf.c undefined reference to `__pformatter' Example_Base  line 44 C/C++ Problem

*/

Labels (1)
15 Replies

2,309 Views
fyw
Contributor IV

It already look like this:   but it still report the err  

.stack (NOLOAD) : ALIGN(16)

    {

      __HEAP = . ;

      . += __HEAP_SIZE ;

      __HEAP_END = . ;

      _stack_end = . ;

      . +=  __STACK_SIZE ;

      _stack_addr = . ;

      __SP_INIT = . ;

      . += 4;

    } > m_data

Secondly, i find in the uart_console_io.c file,  the three include file(below) cann't be found.  I think this uart_console_io.c file is not suitable for  newlib

#include <ansi_parms.h>

#include "console_io.h"

#include <ewl_misra_types.h>

0 Kudos

2,309 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

use the following code for .stack section

.stack (NOLOAD) : ALIGN(16)

    {

      __HEAP = . ;

      _end = . ;

      end = . ;

      . += __HEAP_SIZE ;

      __HEAP_END = . ;

      _stack_end = . ;

      . +=  __STACK_SIZE ;

      _stack_addr = . ;

      __SP_INIT = . ;

      . += 4;

    } > m_data

Regards,

Martin

2,309 Views
fyw
Contributor IV

Thank you Martin Kovar! This works!

But i still have another problem. Since i choose the newlib, i find that the "uart_console_io.c" file doesn't work well.   "uart_console_io.c" file has three include file :

#include <ansi_parms.h>

#include "console_io.h"

#include <ewl_misra_types.h>

The three file could not be found. So add the path(you can see in the pic below)无标题.png

After that the project build OK. But when the program runs, i find that the printf can not send anything.

I put a breakpoint at function "__write_console", and find that the program doesnot stop at the function "__write_console".

So i guess that the printf does not call "__write_console". 

Need other settings?

0 Kudos

2,309 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

sorry for delay, but I have no experience with printf function using newlib library yet. Please give me a time, I will investigate, how it works and I will write you back if it is possible to use it.

Regards,

Martin

2,309 Views
fyw
Contributor IV

Thank you very much!

0 Kudos

2,309 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

at first, I would like to apologize for my previous claim. EWL library supports formaters like %d or %f. There is completely different issue, which can be easily fixed.

Add the following line to the Linker flags:

-Xlinker --undefined=__pformatterFP -Xlinker --defsym=__pformatter=__pformatterFP

pastedImage_0.png

Now it will work correct.

Regards,

Martin

2,309 Views
fyw
Contributor IV

Thank you very much! It works!

I wander is there any book or document introduce about the "linker" thing of S32?

for example  i do not know the exact meaning of the following two lines(list follow) and also the "-Xlinker --undefined=__pformatterFP -Xlinker --defsym=__pformatter=__pformatterFP"

.stack (NOLOAD) : ALIGN(16)

    {

      __HEAP = . ;

      _end = . ;???????????????

      end = . ;???????????????

      . += __HEAP_SIZE ;

      __HEAP_END = . ;

      _stack_end = . ;

      . +=  __STACK_SIZE ;

      _stack_addr = . ;

      __SP_INIT = . ;

      . += 4;

    } > m_data

0 Kudos

2,309 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

S32DS uses gcc compiler and linker and these are under GNU GPL license. So the documentation is public, please look at the following URLs.

https://sourceware.org/binutils/docs/ld/

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&sqi=2&ved=0ahUKEwjWrK...

About "-Xlinker --undefined=__pformatterFP -Xlinker --defsym=__pformatter=__pformatterFP", it is little bit complicated, but I will try to explain.

When you call printf with some formatter, for example printf("%d",0xAA), function int_t _EWL_CDECL printf from printf.c file is called. In this function, __pformatter function is called. But this __pformatter calls function from stdio_api.h, which is not correct. Correct function, which has to be called is function __pformatterFP placed in  __printformat.c file.

So the linker flag says that there is undefined symbol __pformatterFP (part -Xlinker --undefined=__pformatterFP) and define symbol __pformatter as a __pformatterFP (part -Xlinker --defsym=__pformatter=__pformatterFP ). So from my point of view, symbol __pformatter is replaced by __pformatterFP. Now correct function is called and the program could be compiled.

About the end symbols, please look at the following URL:

libgloss/libnosys/sbrk.c - native_client/nacl-newlib - Git at Google

You can see that line 10 declares extern char  end; /* Set by linker. */. This is the symbol which has to be add to the linker file.

I hope it helps you a little bit, but if you have any other questions, please feel free to write me back.

Regards,

Martin

2,309 Views
fyw
Contributor IV

Thank you very much!!!

2,309 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

please look at the following example:

Example MPC5744P PinToggleStationery S32DS

If you have any other questions, please feel free to write me back.

Regards,

Martin

2,309 Views
fyw
Contributor IV

Thank you very much!

now i find a strange problem

if i write like this:

printf("Best Regards, Technical Information Center\r\n");   --->It's OK!

but if i write like this:

printf("Best Regards %d, Technical Information Center\r\n", 0xAA);   ---> it reports an err

"S32DS/e200_ewl/EWL_C/src/stdio/printf.c undefined reference to `__pformatter' Example_Base  line 44 C/C++ Problem"

i find even in the project"Example MPC5744P PinToggleStationery S32DS", it also reports the same err

0 Kudos

2,309 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

EWL library does contain only printf function, which accepts const char * parameter. If you want to pass any other parameters like integer, float, etc.. you have to use NewLib library. This library can be chosen while you create a project (in project wizard) or you can change it in project settings (see figure below)

pastedImage_1.png

Regards,

Martin

2,309 Views
fyw
Contributor IV

${VLE_NEWLIB_DIR}/newlib

-------------------------- where is this path?  I can not find in my computer

0 Kudos

2,309 Views
fyw
Contributor IV

Thank you Martin Kovar ,

I have tried this

(learn form this  Linker errors when using the "new" operator )

but i meet the same problem " sbrk.c:21: undefined reference to `end' "

the author say " changed the heap size and added an "end" definition at the beginning of the heap section, it works just fine."

I donot know how "added an "end" definition at the beginning of the heap section"?  could you help me for that?  thank you very much!

0 Kudos

2,310 Views
bdn
Contributor III

Hi,

you have to change your linke file. In your project folder direct to Project_Settings and edit section.ld

Section .stack should look like that:

.stack (NOLOAD) : ALIGN(16)
{
  __HEAP = . ;
  . += __HEAP_SIZE ;
  __HEAP_END = . ;
  _stack_end = . ;
  . +=  __STACK_SIZE ;
  _stack_addr = . ;
  __SP_INIT = . ;
  . += 4;
} > m_data

Regards,

Bernhard

0 Kudos