printf to a different UART

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

printf to a different UART

4,463 Views
vale
Contributor I
Hallo,
I'm currently developing on a M52235EVB with a project created in C language on Codewarrior stationery.
Currently printf function outputs to UART0. Unfortunately I need UART0 for a different purpose.
How can I easily get printf output to a different UART, for example UART2?
Thank you
Valentina
 
Labels (1)
0 Kudos
6 Replies

760 Views
SimonMarsden_de
Contributor II
Take a look at the file UART_unity.c. This contains routines called ReadUARTN() and WriteUARTN() which printf() and scanf() call to do the low-level board-specific I/O.

These routines make use of a couple of support routines, uart_getchar() and uart_putchar(). These are passed an argument which is the UART channel. You need to change all occurrences in UART_Unity.c from e.g.

uart_putchar(0,...)

...to

uart_putchar(1,...)


In addition, you will need to make sure that the UART channel is correctly initialised, and that the GPIO pins are set up so that the UART signals are brought out to the physical pins. (Modifications are typically needed in xxx_sysinit.c)


Hope this helps. Good luck.


Simon
0 Kudos

760 Views
vale
Contributor I
Hallo Simon,
you were right.
Simply changing the first argument to uart_putchar in the WriteUARTN routine in UART_unity.c file did the work! printf now outputs to UART2.
Thank you very much.
 
valentina
 
P.S. To everyone facing the same problem on the M52235EVB board, remember to remove the jumpers if you want to use UART2 as some pins seem to be multiplexed between UART2 and CAN.
 
0 Kudos

760 Views
CrasyCat
Specialist III
Hello
 
I am not an expert in Coldfire, but I quickly looked into the source files within a M52235EVB stationery.
 
I am not sure it works (I did not try it myself), but can you try the following:
  - Edit the file io.h in your {Project}\src\include directory.
  - Change following lines
       #define out_char  uart0_out_char
       #define in_char   uart0_in_char
       #define char_present uart0_char_present
    into
     #define out_char  uart2_out_char
     #define in_char   uart2_in_char
     #define char_present uart2_char_present
 
  Also make sure the UART2 is initialized properly in function mcf523x_uart_init from hwinit.c in directory
  {Project}\src\common
 
 Hopefully this works :smileywink:
CrasyCat
0 Kudos

760 Views
vale
Contributor I
Sorry,
I'm developing on Codewarrior Standard Edition, version 6.3 and I've no io.h in my working directory.
Actually these are the files i've got in my source dir:
Int_handlers.c
m52235evb.c
main.c
mcf52235.c
mcf52235_lo.s
mcf52235_sysinit.c
mcf52235_vectors.s
mcf5xxx.c
mcf5xxx_lo.s
uart.c
UART_unity.c
 
And these are the files I've got in my Include dir:
codewarrior_UART.h
common.h
Int_handlers.h
m52235evb.h
mcf52235.h
mcf5xxx.h
mwerks.h
uart.h
 
I didn't find anything similar to out_char or in_char in these files.
I also have the precompiled files C_4i_CF_SZ_MSL.a, fp_coldfire.a and C_4i_CF_Runtime.a automatically linked to my project (added by CodeWarrior)....
Any idea?
 
Valentina 
 
0 Kudos

760 Views
mccPaul
Contributor I
Hi Valentina,
 
The copy of m52235evb.h that I have from the Nichelite demo software that came with our 52235EVB has this line in it:
 
Code:
#define TERMINAL_PORT   0

 
Setting that to 1 or 2 will change which UART is used for console output. If your source code is from a different project and doesn't have this #define then search for something related to the UARTs such as baud rate - try searching for 9600 if that is what your baud rate is set to. Most probably you will find a #define nearby that obviously relates to the UART number.
 
If this fails then you could try setting a breakpoint on your call to printf and trace through the source until you find the function that puts a char into the UART's TX buffer, most likely you will find some constants there that specify UART 0, 1 or 2.
 
Good luck,
 
Paul.
0 Kudos

760 Views
vale
Contributor I
Hi Paul,
I found the
#define TERMINAL_PORT 0
but changing to other values doesn't sort any effect. printf keeps outputting to UART0.
Actually the macro TERMINAL_PORT is not used anywhere in the project source files.
I tried to trace printf as you suggested but stepping in printf I found myself in an assembly routine.
The addresses of the assembly code correspond to
parse_format (C_4i_CF_SZ_MSL.a printf.o)
as I read in the Internal ROM.elf.xmap file.
 
I guess printf is part of the precompiled libraries. 
 
Can you suggest a method to overcome this configuration?
 
Valentina 
0 Kudos