cancel
Showing results for 
Search instead for 
Did you mean: 

Periodic PC sample packets via DWT

Scopi
Associate II

I am trying to persuade an stm32F412 to provide Periodic PC sample packets.

Reference manual RM0402 implies it is doable (Configure DWT as a PC sampler)

The "Cortex-M4 Technical Reference Manual r0p0" says 
"You can configure the DWT to generate PC samples at defined intervals" and DWT registers are described in the ARMv7M Architecture Reference Manual

That reference manual contains what I thought were reasonable instructions.

I can see the CYCCNT register changing value as expected.

I have confirmed that ITM and DWT registers can be written to. 

I'm obviously missing something!

The below code does generate ITM packets over the SWO interface of my stlink v2-mini e, picked up via openocd, so I believe that the serial and clock speeds are set correctly.

 

 
DBGMCU->CR |= DBGMCU_CR_TRACE_IOEN; CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; DWT->CYCCNT = 0; ITM->LAR = 0xC5ACCE55; // unlock the ITM registers ITM->TCR |= ITM_TCR_ITMENA_Msk; // enable the ITM ITM->TCR |= ITM_TCR_DWTENA_Msk; //manual described as necessary ITM->TCR |= ITM_TCR_SYNCENA_Msk; //This plus DWT syntap should mean I see synch packets ITM->TPR = 0xFFFFFFFF; // enable unprivileged acc. ITM->TER = 0xFFFFFFFF; // enable all ports TPI->CSPSR = 1; // port width = 1 bit TPI->SPPR = 2; // UART encoding TPI->ACPR = (5-1); TPI->FFCR &= ~TPI_FFCR_EnFCont_Msk; // no formatter (unclear what this function really means, more reading required) //TPI->FFCR |= TPI_FFCR_EnFCont_Msk; //with this turned on, ITM does seem to emit more readable packets DWT->CTRL = 0; DWT->CTRL |= (0b1111 << DWT_CTRL_POSTINIT_Pos ); //Try to start the countdown from a high point DWT->CTRL |= DWT_CTRL_CYCTAP_Msk | (0xFUL << DWT_CTRL_POSTPRESET_Pos); //Reset countdown DWT->CTRL &= ~DWT_CTRL_CYCTAP_Msk; //Changing how frequent the counter tics DWT->CTRL |= (DWT_CTRL_CYCCNTENA_Msk); //enable counter DWT->CTRL |=(DWT_CTRL_PCSAMPLENA_Msk); //enable pcsampling

 

I am trying to use the itm-tools code found at https://github.com/japaric/itm-tools to decode the packets. I have no reason to believe that tool is flawed; I can see it recognising other packet types.

1 ACCEPTED SOLUTION

Accepted Solutions
Scopi
Associate II

Absolute PEBKAC issue here - although I was getting 'other packet types' recognised by the decoder, when I looked at the SWO line on the logic analyser it was clear there was a baudrate mismatch. Doubling the value in ACPR made everything work.

View solution in original post

1 REPLY 1
Scopi
Associate II

Absolute PEBKAC issue here - although I was getting 'other packet types' recognised by the decoder, when I looked at the SWO line on the logic analyser it was clear there was a baudrate mismatch. Doubling the value in ACPR made everything work.