AnsweredAssumed Answered

printf and undefined reference to 'InitializeUART'

Question asked by Keith Smith on Mar 21, 2014
Latest reply on Mar 26, 2014 by Jorge_Gonzalez

I created a project with Console I/O radio button checked and added source to the project that called printf(). I’m using CodeWarrior v10.5.

 

The linker reported that InitializeUART, ReadUARTN, and WriteUARTN were undefined and referenced in uart_console_io.c which is part of libuart.a.

 

There are few discussions that ask the question how to use printf() with CodeWarrior.

There are few discussions that report InitializeUART() undefined.

I didn't find any good 'how to' answers to connect printf() with a UART.

 

I searched the CodeWarrior directory tree for the function InitializeUART(). I found it declared in /sys/UART.h. I found in ew/EWL_C/src/sys/uart_console_io.c a call to InitializeUART().

 

So...now I know where the source is located that makes the call to InitializeUART(), but not the definition of the function.

 

I found in a USB host example, files sci.<c,h>. These files are part of the example and define 'InitializeUART', 'ReadUARTN', and 'WriteUARTN'. Curious.

 

However, if one looks at a CodeWarrior example 'hello world' for a specific processor, say k60, one finds in the drivers subfolder the directory uart as well as printf.c in the common folder. This appears to be an older example, because it defines its own uart drivers and its own printf(). No mention of InitializeUART.

 

I then found InitializeUART defined in /lib/wizard/ColdFire/uart_support.c.

In MCU/ARM_GCC_Support/UART is readme.txt that states one needs to add UART support to wizard created projects. The document that is supposed to help is MCU/Help/PDF/Targeting Microcontrollers.pdf. There is very little discussion on UARTs in this document. There are only two target boards available, TWR-K60N512 and TWR-KL25Z18. The source for these boards does not include definitions for InitalizeUART, etc.

 

In MCU/lib/wizard_data/ColdFire is the original uart_support.c, which defines InitializeUART, ReadUARTN, and WriteUARTN.

 

Thus, there appears to be two ways to resolve undefined reference to InitializeUART, write your own (borrow and modify) version of uart_support.c or start with an example that supplies its own printf().


An alternative is to replace all printf()s with sprintf()s then call puts(). But puts() (as does putchar()) results in the same undefined InitializeUART.

 

Did I miss something?

Outcomes