title: Printf output using UART in ARM Cortex-M3 microcontroller
body: <p>I have LPC1768 based board - <a href="http://mbed.org/users/wim/notebook/landtiger-baseboard/" rel="nofollow noreferrer">LandTiger</a> (worth checking manual at the bottom). To program it I use Keil uVision4/72 Lite and J-Link EDU from Segger. My simple program to interact with joystick and diodes works fine, but...</p>
  <p>I am trying to implement debug printf, so I can see printf output in Keil <strong>&quot;Debug (printf) Viewer&quot;</strong> window. Problem is that I dont see any output - I think I am on right track because when I run the debugger I can see <strong>Trace:Running</strong> at the bottom of the window (before it was <strong>Trace:No Synchronization</strong>). Unfortunately I dont see anything in UART and Debug output windows.</p>
  <p>I've spent quite a lot of time trying to make it work and would appreciate any help, thank you ;)</p>
  <p>My Keil settings are:</p>
  <p><strong>Project/Options for Target/Debug</strong> set to <strong>J-Link/J-Trace Cortex</strong>.</p>
  <p>Then inside it's settings I have <strong>SEGGER</strong> selected with <strong>Port:SW</strong> and <strong>MAX CLOCK:10 MHz</strong>.</p>
  <p><strong>Trace tab</strong> is enabled with <strong>100Mhz Core Clock</strong> and <strong>SWO Prescaler = 17</strong> (which results in <strong>5.882352MHz SWO Clock</strong>).</p>
  <p><strong>ITM Stimulus Ports</strong> are set to <strong>Enable:0xFFFFFFFF</strong> and <strong>Privilege:0x0000000F</strong></p>
  <p>Here are parts of my code:</p>
  <blockquote>
  <p>define FOSC                        12000000</p>
  <p>define FCCLK                      (FOSC  * 8)</p>
  <p>define FCCO                       (FCCLK * 3)</p>
  <p>define FPCLK                      (FCCLK / 4)</p>
  <p>define UART0_BPS     115200</p>
  <p>void UART0_Init (void)</p>
  <p>{</p>
  <p>uint16_t usFdiv;</p>
  <p>/* UART0 */</p>
  <p>LPC_PINCON-&gt;PINSEL0 |= (1 &lt;&lt; 4);/* Pin P0.2 used as TXD0 (Com0) */</p>
  <p>LPC_PINCON-&gt;PINSEL0 |= (1 &lt;&lt; 6);/* Pin P0.3 used as RXD0 (Com0) */</p>
  <p>LPC_UART0-&gt;LCR  = 0x83;</p>
  <p>usFdiv = (FPCLK / 16) / UART0_BPS;</p>
  <p>LPC_UART0-&gt;DLM  = usFdiv / 256;</p>
  <p>LPC_UART0-&gt;DLL  = usFdiv % 256;</p>
  <p>LPC_UART0-&gt;LCR  = 0x03;</p>
  <p>LPC_UART0-&gt;FCR  = 0x06;<br />
  }</p>
  </blockquote>
  <p>Sending code:</p>
  <blockquote>
  <p>int UART0_SendByte (int ucData)</p>
  <p>{</p>
  <p>while (!(LPC_UART0-&gt;LSR &amp; 0x20)){};</p>
  <p>return (LPC_UART0-&gt;THR = ucData);</p>
  <p>}</p>
  </blockquote>
  <p>And my fputc for printf (it is called - checked)</p>
  <blockquote>
  <p>int fputc(int c, FILE *f)</p>
  <p>{</p>
  <p>if (c == '\n')  {</p>
  <p>UART0_SendByte('\r');</p>
  <p>}</p>
  <p>return (UART0_SendByte(c));</p>
  <p>}</p>
  </blockquote>
  <p>Any ideas?</p>
  <p>Regards!</p>