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 */
}
main.c:
-----------
#include <UART.h>
#include <stdio.h>
int main(void)
{
volatile int i = 0;
printf("Hello World! %d \n",i);
...
}
Stanish
Message Edited by stanish on 2009-09-18 12:02 PM