cancel
Showing results for 
Search instead for 
Did you mean: 

ITM usage and SWO pin

Davide Michelis
Associate II
Posted on June 06, 2018 at 10:25

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:

&sharpdefine DEMCRx   (*((unsigned long *) 0xe000edfc))

&sharpdefine TRCENA  0x01000000  // enable trace

&sharpdefine ITM_STIM0 (*((unsigned long *) 0xe0000000))

&sharpdefine ITM_STIM1 (*((unsigned long *) 0xe0000004))

&sharpdefine ITM_STIM2 (*((unsigned long *) 0xe0000008))

&sharpdefine ITM_STIM3 (*((unsigned long *) 0xe000000c))

&sharpdefine ITM_TER   (*((unsigned long *) 0xe0000e00))

&sharpdefine ITM_TPR   (*((unsigned long *) 0xe0000e40))

&sharpdefine ITM_TCR   (*((unsigned long *) 0xe0000e80))

&sharpdefine ITM_LAR   (*((unsigned long *) 0xe0000fb0))

&sharpdefine ITM_LAR_ACCESS  0xc5acce55

&sharpdefine 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

#itm #swd #jlink #freertos #debug #trace #swo
4 REPLIES 4
Davide Michelis
Associate II
Posted on June 06, 2018 at 10:48

I have tried in this way just now: I reflashed the firmware stlink->jlink, then using the Jlink SWO viewer i have tried to get data, but nothing happens, no message is shown (PB3 is connected to pin6 of CN3, always with SB10 not connected).

Posted on June 06, 2018 at 12:35

The debugger should do the ITM initialization. The core clock must match SystemCoreClock. For stand alone operation the ST-LINK Utilities SWV Window should work with standard firmware.

I tend to use solder on the bridge rather than attempt to jumper.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 06, 2018 at 13:04

https://community.st.com/0D50X00009Xkho5SAB

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 06, 2018 at 14:15

Ok then, I'm working on a system where I don't have admin credentials so I have to wait before I can install stlink utility. In the meantime I have tried the solution of Jlink (SEGGER RTT) and it works good: Now I would like to know if there is a way to reduce as much as I can the overhead due to tracing: in fact I have noted that when I add the tracing features the system is slowed down in a visible manner (less than UART but still slowed)...

The solution I want investigate so far are:

UART:really bad, slow but always available and simple to configure

ITM+SWO: to be tried

SEGGER RTT: much faster but requires ram overhead and still affects the system

Thanks for the answer and the help.

Best regards.