AnsweredAssumed Answered

STM32L-Discovery - ITM_SendChar lost chars

Question asked by Bogdan Golab on Mar 12, 2017
Latest reply on Mar 13, 2017 by Clive One



I used to use the ITM_SendChar with STM32F3 Discovery board in the past with no problem.


Now I wanted get an text output from another VCOM-less board - the STM32L-Discovery.

I configured the ST-LINK debugger the regular way for ITM:

XTAL=2Mhz (sourced from the ST-LINK MCU)
Core Clock=2Mhz,
Trace Enable,
ITM Stimulus Port:0,
Unchecked Trace Events to reduce load


and re-targeted the putc() to ITM_SendChar().


Unfortunately the output is not reliable. I use Keil Debug PrintViewer as the SWV terminal:

Counter: 0
Counter: 1
ounter: 2
Counter: 3
Counter: 4
ounter: 5
ounter: 6
Counter: 7
Counter: 9
Counter: 10
Counter: 1
Counter: 12


I added some delay in-between the consequtive ITM_SendChar() calls but did not succede.

See simple example of failing code:

#include "stm32l1xx.h"
#include "stdio.h"
#include "string.h"

struct __FILE {
    int dummy;

FILE __stdout;

int fputc(int ch, FILE *f)

volatile uint32_t msTicks=0, last_msTicks=0;   // counts 1ms timeTicks - global var also good for debugging
uint32_t counter=0;

void SysTick_Handler(void) {

void ITM_PrintString(char *msg)
     int k;
     int ll=strlen(msg);

#define PERIOD     1000

int main(void)
     SystemCoreClockUpdate ();                                        // to update SystemCoreClock var - add SystemCoreClock to Watch to see exact value used
     SysTick_Config(SystemCoreClock/1000);          // systick setup
     while (1) {
                    printf("Counter: %d\n\r", counter);



Please share any idea I would try to narrow down the issue.