Redirect printf()

cancel
Showing results for 
Search instead for 
Did you mean: 

Redirect printf()

Jump to solution
1,318 Views
mathias_edman
Contributor III

Hi NXP,

I am trying to redirect the printf() to Uart. I am using S32 studio (Version: 2017.R1 Build id: 171018)  with gnu toolchain and MPC5777C and I have tried with pretty much every possible combination of newlib and ewl with lower layer functions such as _write(), _read(), write(), read(),_sbrk(), _open(),  _isatty(), _fstat(), __read_console, __write_console etc. etc.

Usually in other projects, I manage to do this simply using read() write() functions with newlib, but this does not seem to work correctly using S32 studio with the MCU I work with currently.

With newlib I can get printf() to work and it will call write() and read(), but for some reason using %d and similar will return null chars like below.

printf("number %d %s", 57, "MCU");

Result:

'n', 'u', 'm', 'b', 'e', 'r', ' ', \0, \0, ' ', 'M', 'C', 'U'

Is there some kind of magic involved here that I need to understand in order to get this up and running?

Regards,

Mathias

0 Kudos
1 Solution
1,039 Views
mathias_edman
Contributor III

Hi Alexander,

Thanks for the reply. I am not really doing anything interesting in my project, I just print out the chars that I get in write() function. So write is the only "low level" function that I have implemented and that obviously works. All the rest, as you say, is handled by newlib functions.

Doing conversions with functions like sprintf, itoa does not work either. They just return \0 regardless, just like printf().

Could you perhaps try and redirect the printf() with the tools and newlib (compiled for power-PC) version that I am currently using?

Could be a good project to share to everyone as well.

Regards,

Mathias

UPDATE1***

I based my project on an example project that merges binaries for both cores into one elf. I suspect that something is wrong with the link script in this project. When I created a new project (one project for each core) and added software for UART and newlib everything works as it should. If I find more details about this problem I will post them in this thread.

View solution in original post

0 Kudos
3 Replies
1,039 Views
mathias_edman
Contributor III

Anyone?

0 Kudos
1,039 Views
alexanderfedoto
NXP Employee
NXP Employee

Can you share your project that reproduces problem. Since this functionality uses standard newlib routines, I tend believe there is a problem in your low layer implementation.

0 Kudos
1,040 Views
mathias_edman
Contributor III

Hi Alexander,

Thanks for the reply. I am not really doing anything interesting in my project, I just print out the chars that I get in write() function. So write is the only "low level" function that I have implemented and that obviously works. All the rest, as you say, is handled by newlib functions.

Doing conversions with functions like sprintf, itoa does not work either. They just return \0 regardless, just like printf().

Could you perhaps try and redirect the printf() with the tools and newlib (compiled for power-PC) version that I am currently using?

Could be a good project to share to everyone as well.

Regards,

Mathias

UPDATE1***

I based my project on an example project that merges binaries for both cores into one elf. I suspect that something is wrong with the link script in this project. When I created a new project (one project for each core) and added software for UART and newlib everything works as it should. If I find more details about this problem I will post them in this thread.

0 Kudos