cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L053R8 Nucleo : using printf() window under Keil (ST-Link V2)

stephane239955
Associate II
Posted on November 14, 2014 at 11:38

Hi,

Is-it possible to use printf() window under Keil in debug session when using ST-Link Debugger?

I possible, how to proceed, Is-there a tutorial ?

Thanks
1 REPLY 1
Posted on November 14, 2014 at 14:20

There is Google..

As far as I'm aware the Cortex-M0/M0+ does not provide a SWV (Serial Wire Viewer) channel on SWO pin. So you aren't going to be able to use the ''Debug Serial (printf)'' pane. What you could do is use the USART and Nucleo's VCP to get serial output via a terminal application pointed at COMxx Keil provides a standard way of retargetting console output. You could look at the retarget.c/serial.c in the various board/chip examples provided by Keil. I don't have an L0 Nucleo, it doesn't use the Standard Peripheral Library, but if you've configured the USART the standard Keil mechanism would look like this

//******************************************************************************
// Hosting of stdio functionality through USART1 on Keil
//******************************************************************************
#include <
rt_misc.h
>
#pragma import(__use_no_semihosting_swi)
struct __FILE { int handle; /* Add whatever you need here */ };
FILE __stdout;
FILE __stdin;
int fputc(int ch, FILE *f)
{
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, ch);
return(ch);
}
int fgetc(FILE *f)
{
char ch;
while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
ch = USART_ReceiveData(USART1);
return((int)ch);
}
int ferror(FILE *f)
{
/* Your implementation of ferror */
return EOF;
}
void _ttywrch(int ch)
{
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, ch);
}
void _sys_exit(int return_code)
{
label: goto label; /* endless loop */
}
//******************************************************************************

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..