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?
Hello Keith:
Basically all you summarize is correct. As there are many devices with different pinouts and configuration, you need to add the low level UART support for your projects. An easy way to do this is to use the ConsoleIO component provided with Processor Expert, and if you do not want to use Processor Expert you could simply "steal" the generated functions. The next tutorial by our colleague Erich Styger will provide you the tricks to achieve this:
Tutorial: Printf() with (and without) Processor Expert | MCU on Eclipse
Also, it is a good option to avoid using such console functions (printf, getchar and the like). In such case the next tutorial might be also useful:
Tutorial: printf() and “Hello World!” with the Freedom KL25Z Board | MCU on Eclipse
Hope this helps!
Regards
Jorge Gonzalez
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------