2
votes

I have LPC1768 based board - LandTiger (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...

I am trying to implement debug printf, so I can see printf output in Keil "Debug (printf) Viewer" 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 Trace:Running at the bottom of the window (before it was Trace:No Synchronization). Unfortunately I dont see anything in UART and Debug output windows.

I've spent quite a lot of time trying to make it work and would appreciate any help, thank you ;)

My Keil settings are:

Project/Options for Target/Debug set to J-Link/J-Trace Cortex.

Then inside it's settings I have SEGGER selected with Port:SW and MAX CLOCK:10 MHz.

Trace tab is enabled with 100Mhz Core Clock and SWO Prescaler = 17 (which results in 5.882352MHz SWO Clock).

ITM Stimulus Ports are set to Enable:0xFFFFFFFF and Privilege:0x0000000F

Here are parts of my code:

define FOSC 12000000

define FCCLK (FOSC * 8)

define FCCO (FCCLK * 3)

define FPCLK (FCCLK / 4)

define UART0_BPS 115200

void UART0_Init (void)

{

uint16_t usFdiv;

/* UART0 */

LPC_PINCON->PINSEL0 |= (1 << 4);/* Pin P0.2 used as TXD0 (Com0) */

LPC_PINCON->PINSEL0 |= (1 << 6);/* Pin P0.3 used as RXD0 (Com0) */

LPC_UART0->LCR = 0x83;

usFdiv = (FPCLK / 16) / UART0_BPS;

LPC_UART0->DLM = usFdiv / 256;

LPC_UART0->DLL = usFdiv % 256;

LPC_UART0->LCR = 0x03;

LPC_UART0->FCR = 0x06;
}

Sending code:

int UART0_SendByte (int ucData)

{

while (!(LPC_UART0->LSR & 0x20)){};

return (LPC_UART0->THR = ucData);

}

And my fputc for printf (it is called - checked)

int fputc(int c, FILE *f)

{

if (c == '\n') {

UART0_SendByte('\r');

}

return (UART0_SendByte(c));

}

Any ideas?

Regards!

2
I don't understand, you are talking about trace capabilities of your debugger and yet you are writing bytes on the UART. What do you expect those bytes to go? Do you have a RS232 link between board and PC? Usually if you link your program with semihosting the printf sends data to the debugger IDE through the debug port (JLink in your case). So either you printf and don't override the fputc, and expect the output on the debug window, or you send to UART, connect the RS232 to the PC and see it on hyperterminal or something like that. I'm probably missing something.Balau
@Balau: You should post an answer rather than a comment - your are spot on.Clifford
I got confused with the info from Keil website. You guys are 100% right - all I had to do was to configure Keil target debug options correctly and then override fputc using ITM_SendChar from CMSIS. And it works fine! Thank you!Siegfried
@Clifford and Siegfried, I added an answer so that we can bring closure to the question also for those who find it later on.Balau

2 Answers

0
votes

Your fputc sends bytes directly to the UART, which goes to the RS232 connector on board. If you want to see the output of your fputc, you need to connect a cable between the board and the PC and see it with a client such as hyperterminal.

When you talk about the trace capabilities, it generally means that the adapter (J-Link in your case) creates high throughput communication between the program and the debugger and follows the execution of the program. There are other debug functionalities. For example if you compile with semihosting, the program executes the system calls (_write, _open, ...) that are intercepted by the debugger that executes them on the host machine.

So in my experience either you call printf, don't override the fputc and compile with semihosting, and expect the output on the debug window, or you send to UART, connect the RS232 to the PC and see it on hyperterminal.

I see you found a third method which uses the trace capabilities. I believe the semihosting option is a more general solution because it can be applied also on a setup that doesn't have trace capabilities but just JTAG (or SWD) connection.

0
votes

You want to write to the ETM cell with your printf command if you want the output to go to the SWD interface via the JLINK.

Follow the instructions in section 3.4 of http://cdn.energymicro.com/dl/an/pdf/an0043_efm32_debug_trace_capabilities.pdf.

Always check in your "printf" code that the last byte has gone out, otherwise output will not be correct.