AnsweredAssumed Answered

ITM usage and SWO pin

Question asked by Davide Michelis on Jun 6, 2018
Latest reply on Jun 6, 2018 by Davide Michelis

Good morning,

I am trying to add some trace capabilities to my system: UART is obviously too slow so I would like to use ITM. I report my situation:

I use a STM32F3DISCO board, FreeRTOS, Eclipse with Jlink debugger plugin and AC6 plugin as IDE and JLink when I need it (I don't have a physical JLink probe but I reflash the micro).

I have implemented the code but nothing works: probably I didn't understand everything. The code I use is:


#define DEMCRx   (*((unsigned long *) 0xe000edfc))
#define TRCENA  0x01000000  // enable trace
#define ITM_STIM0 (*((unsigned long *) 0xe0000000))
#define ITM_STIM1 (*((unsigned long *) 0xe0000004))
#define ITM_STIM2 (*((unsigned long *) 0xe0000008))
#define ITM_STIM3 (*((unsigned long *) 0xe000000c))
#define ITM_TER   (*((unsigned long *) 0xe0000e00))
#define ITM_TPR   (*((unsigned long *) 0xe0000e40))
#define ITM_TCR   (*((unsigned long *) 0xe0000e80))
#define ITM_LAR   (*((unsigned long *) 0xe0000fb0))
#define ITM_LAR_ACCESS  0xc5acce55
#define DBGMCU              ((DBGMCU_TypeDef *) DBGMCU_BASE)

 

void itm_init(void) {
    uint32_t SWOSpeed = 3000000;
    uint32_t SWOPrescaler = (48000000 / SWOSpeed) - 1; // SWOSpeed in Hz

 

    CoreDebug->DEMCR = 1 << CoreDebug_DEMCR_TRCENA_Pos;

 

    DBGMCU->CR = 0x00000027;
    *((volatile unsigned *) 0xE00400F0) = 0x00000002;
    *((volatile unsigned *) 0xE0040010) = SWOPrescaler;
    *((volatile unsigned *) 0xE0000FB0) = 0xC5ACCE55;
    *((volatile unsigned *) 0xE0000E80) = 0x0001000D;
    *((volatile unsigned *) 0xE0000E40) = 0x0000000F;
    *((volatile unsigned *) 0xE0000E00) = 0x00000001;
    *((volatile unsigned *) 0xE0001000) = 0x400003FE;
    *((volatile unsigned *) 0xE0040304) = 0x00000100;
}

int SWO_PrintChar(int ch){
    (void) ITM_SendChar(ch);

    return(ch);
}

void SWO_PrintString(const char *s) {
  while (*s!='\0') {
    SWO_PrintChar(*s++);
  }
}

 

ITM_SendChar() is already defined in core_cm4.c

I have connected PB3 to pin6 of CN3 because SB10 is not soldered...which utility may I use to see the output of my SWO_PrintString calls?

 

Thank you in advance.

Best regards

Outcomes