I got a mpc5566 evb and tried to use the printf function. There were three link errors:
undefined: 'InitializedUART' Referenced from '__init_uart_console' in MSL_C.PPCEABI.bare.V.UC.a
...
I found in the CodeWarrior help file that to use console IO function, we need the serial IO library. It gives the path of the library: installDir\PowerPC_EABI_Tools\
CodeWarriorTRK\Transport\processor\ppc\serial\BoardName\Bin
But in my codewarrior folder I didn't find a Transport folder under PowerPC_EABI_Tools\
CodeWarriorTRK\. There are only two file folders Export and Processor.
Doesn't the codewarrior mpc55xx support console IO functions or did I miss something?
Thanks
Hello zxiaorong,
In order to use printf() console function for serial output terminal purposes you have to implement some low level ESCI routines since these functions are not part of a library. TRK libs are no more available in CW for MPC5xxx.
Prototypes needed are defined within <UART.h> file.
1)include prototypes into your code:
#include <UART.h>
If path to "UART.h" is not included within the project please add it into system paths (ALT+F7 -> Access Paths -> "System Paths" -> "Add..." and enter "{Compiler}\PowerPC_EABI_Support\MSL\MSL_C\MSL_Common_Embedded\Include"
2)add implementations of following callback functions that are called internally by printf():
UARTError InitializeUART(UARTBaudRate baudRate);
UARTError ReadUARTN(void* bytes, unsigned long length);
UARTError WriteUARTN(const void* bytes, unsigned long length);
3)functions have to return "kUARTNoError" otherwise pritntf() doesn't output any character.
See below simple output terminal example. The routines are derived from low level SCI routines available here: "<CodeWarrior root directory>\(CodeWarrior_Examples)\555x_Cookbook\eSCI-Simple\src\main.c":
UART.c
----------
#include <UART.h>#include "MPC5554.h"
// Initialize UART to 9600 baud, 8 bits, no parity, Tx & Rx enabled
UARTError InitializeUART(UARTBaudRate baudRate) //BaudRate is not used in this simple example
{
/* MPC555x including MPC563x: use the next 3 lines for either 8 or 40 MHz crystal */
FMPLL.SYNCR.R = 0x16080000; /* 8 MHz xtal: 0x16080000; 40MHz: 0x46100000 */
while(FMPLL.SYNSR.B.LOCK != 1) {}; /* Wait for FMPLL to LOCK */
FMPLL.SYNCR.R = 0x16000000; /* 8 MHz xtal: 0x16000000; 40MHz: 0x46080000 */
ESCI_A.CR2.R = 0x2000; /* Module is enabled (default setting ) */
ESCI_A.CR1.R = 0x01A1000C; /* 9600 baud, 8 bits, no parity, Tx & Rx enabled */
/* Use the following two lines for MPC555x */
SIU.PCR[89].R = 0x400; /* Configure pad for primary func: TxDA */
SIU.PCR[90].R = 0x400; /* Configure pad for primary func: RxDA */
return kUARTNoError; /* Return No Error */
}
// Read UART is empty
UARTError ReadUARTN(void* bytes, unsigned long length)
{
}
// Write UART simply send buffer on ESCI - no ISR used
UARTError WriteUARTN(const void* bytes, unsigned long length)
{
char *tmp =(char *)bytes;
unsigned long j; /* Dummy variable */
for (j=0; j< length; j++)
{ /* Loop for character string */
while (ESCI_A.SR.B.TDRE == 0) {} /* Wait for transmit data reg empty = 1 */
ESCI_A.SR.R = 0x80000000; /* Clear TDRE flag */
ESCI_A.DR.B.D = *(tmp++); /* Transmit 8 bits Data */
}
return kUARTNoError; /* Return No Error */
}
#include <UART.h>
#include <stdio.h>
int main(void)
{
volatile int i = 0;
printf("Hello World! %d \n",i);
...
}Stanish
Hi Stanish,
Thank you for your kind reply. I tried these steps and now there is no link error. But It can't still display anything. I use a P&E debugger and where is the string I want to print supposed to display? In the status window? I debugged the program and it seemed the program didn't end up correctly. But I don't know what's the problem. The program counter jumped to some address 0000204E and then a hard reset occured.
Thanks
Xiaorong