I setup a project using harmony v2 for a pic32mx470f512l. In drivers -> USART i configured the UART (strange its called USART in harmony in datasheet says its a UART):

enter image description here

Now i want to use the function printf, like we can easily use in MCC. How can it be implement in harmony?

I seem to have made it work after

but i get wrong chars on termite: enter image description here enter image description here

The configs i made in device configuration: enter image description here

  • \$\begingroup\$ By default, MPLAB® XC32's libraries use UART2 for STDOUT. This means that formatted output functions such as printf() use UART2. The MPLAB XC32 compiler provides a __XC_UART variable that you may use to switch the default to UART 1. \$\endgroup\$
    – Mike
    Jun 12 '19 at 5:44
  • \$\begingroup\$ @Mike hi. Yes i used __XC_UART = 1 in my code to use UART1. But the characters are the ones you see on the screenshot. With MCC i had the same problem its really hard to find a frequency of the oscillator and baud rate of UART that works well. \$\endgroup\$
    – Nmaster88
    Jun 12 '19 at 7:41
  • \$\begingroup\$ 9600 baud is really slow, so should be fine. Double check oszillator frequency. \$\endgroup\$
    – Mike
    Jun 12 '19 at 7:47
  • \$\begingroup\$ @Mike after i programmed again the pic it seems its ok now! If this works there is no need for me to use the overcomplicated api debug_uart that harmony has. I hope it is not needed. \$\endgroup\$
    – Nmaster88
    Jun 12 '19 at 7:51

I was facing a similar issue with a PIC32MX and my solution was to use the configuration as in the image below for the USART driver.

USART settings on Harmony

Then, I've enabled the 'Use Console System Service?', under 'Harmony Framework Configuration > System Services > Console', using the configurations listed in the image below.

Console settings

Hopefully, these configurations may be applicable to your situation. Don't forget to configure the desired pins as U2TX and U2RX.


You would not use printf to just send data through the USART. You should use the interface defined by Harmony (Page 1295). If you are looking to send something akin to debug messages, there is a debugger console that is supported that uses the SYS_MESSAGE() function which might be similar enough. There is an example harmony project that demonstrates how to use it (located at microchip\harmony\v2_05\apps\examples\system\debug_uart\firmware\src)

  • \$\begingroup\$ The thing is i'm porting a project from a pic16f that uses printf for uart. It is not possible to use it with USART in pic32? I will check that example, it works the same way as printf then? \$\endgroup\$
    – Nmaster88
    Jun 11 '19 at 18:17
  • \$\begingroup\$ It works the same way as printf() at a high level. You can familiarize yourself with the console interface in this application note: ww1.microchip.com/downloads/en/DeviceDoc/… \$\endgroup\$ Jun 11 '19 at 18:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.