This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is there a way to generate PC sample packets and obtain the corresponding local timestamps by ITM in Cortex M4?

Hi guys,

I am studying how to do hardware tracing on Cortex-M4 MCU. I enabled the PC sampling and local timestamps by enabling DWT and ITM registers. However, many of the output packets are overflow and only PeriodicPCSamples are preserved. I hope to have a PeriodicPCSample packet with its local timestamps (clock cycles). How can I achieve this?

Here is how I set up:

In OpenOCD:

tpiu create stm32f3x.cpu.tpiu -dap stm32f3x.dap -ap-num 0
stm32f3x.cpu.tpiu configure -protocol uart -output itm.fifo -traceclk 8000000 -pin-freq 2000000 -formatter 0
stm32f3x.cpu.tpiu enable
itm port 0 on

In c:

#define DWT_CTRL_CYCEVTENA_Pos             22U                                         /*!< DWT CTRL: CYCEVTENA Position */

#define DWT_CTRL_CYCEVTENA_Msk             (0x1UL << DWT_CTRL_CYCEVTENA_Pos)  /*!< DWT CTRL: POSTPRESET Mask */
#define DWT_CTRL_POSTPRESET_Pos             1U                                         /*!< DWT CTRL: POSTPRESET Position */
#define DWT_CTRL_POSTPRESET_Msk            (0xFUL << DWT_CTRL_POSTPRESET_Pos)        

#define DWT_CTRL_PCSAMPLENA_Pos            12U                                         /*!< DWT CTRL: PCSAMPLENA Position */
#define DWT_CTRL_PCSAMPLENA_Msk            (0x1UL << DWT_CTRL_PCSAMPLENA_Pos)          /*!< DWT CTRL: PCSAMPLENA Mask */

DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
DWT->CTRL |= (0x1UL << DWT_CTRL_POSTPRESET_Pos);
DWT->CTRL |= DWT_CTRL_PCSAMPLENA_Msk;

Thank you all!