cancel
Showing results for 
Search instead for 
Did you mean: 

printf over the SWO

spa2
Associate II
Posted on November 08, 2010 at 15:05

printf over the SWO

1 REPLY 1
Posted on May 17, 2011 at 14:14

I’m looking for a small example on how to printf over the SWO to the Keil IDE, I can do it by RS323 to a terminal, but how do I point it to the SWO instead of the UART, can someone please provide me with a small example or a link to where I can read about it. Thanks

Replace the semi-hosting routines, specifically the fputc() and _ttywrch() with routines that access the M3's debug channel.

Something along the following lines, using the core_cm3 CMSIS Core Support package.

#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) {

  return (ITM_SendChar((uint32_t)ch));

}

int fgetc(FILE *f) {

  return ((int)ITM_ReceiveChar());

}

int ferror(FILE *f) {

  /* Your implementation of ferror */

  return EOF;

}

void _ttywrch(int ch) {

  ITM_SendChar((uint32_t)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..