Skip to main content
LMI2
Senior III
March 21, 2020
Solved

Where are DWT_CTRL, DWT, CYCCNT and so on, explained

  • March 21, 2020
  • 6 replies
  • 8411 views

I wanted to do a simple test with my STM32f746 protoboard and count clock pulses. Problems are normal (I get all zeros) but in what datasheet/pdf are those registers explained or mentioned. I searched several pdfs in the net and none had those keywords.

//address of the register
volatile unsigned int *DWT_CYCCNT = (volatile unsigned int *)0xE0001004; 
 
//address of the register
volatile unsigned int *DWT_CONTROL = (volatile unsigned int *)0xE0001000; 
 
//address of the register
volatile unsigned int *DWT_LAR = (volatile unsigned int *)0xE0001FB0; 
 
//address of the register
volatile unsigned int *SCB_DEMCR = (volatile unsigned int *)0xE000EDFC;
 
*DWT_LAR = 0xC5ACCE55; // unlock (CM7)
*SCB_DEMCR |= 0x01000000;
*DWT_CYCCNT = 0; // reset the counter
*DWT_CONTROL |= 1 ; // enable the counter
x = *DWT_CYCCNT;

This topic has been closed for replies.
Best answer by Uwe Bonnes

Look at the ARM website, e.g. ARM v7-M Architecture  Reference Manual

6 replies

Uwe Bonnes
Uwe BonnesBest answer
Chief
March 21, 2020

Look at the ARM website, e.g. ARM v7-M Architecture  Reference Manual

LMI2
LMI2Author
Senior III
March 21, 2020

Thank you. I found it. Using that info doesn't look easy, but luckily, I found some code which seem to work.

TDK
March 22, 2020

Note also that DWT is generally defined in the header files. So DWT->CYCCNT, for example, should be recognized by the compiler.

"If you feel a post has answered your question, please click ""Accept as Solution""."
LMI2
LMI2Author
Senior III
March 22, 2020

What does "So DWT->CYCCNT, for example, should be recognized by the compiler." mean?

If I comment for example "volatile unsigned int *DWT_CYCCNT  = (volatile unsigned int *)0xE0001004; //address of the register" line Keil gives an errpr.

Tesla DeLorean
Guru
March 18, 2023

The example code in the top post should be relatively free standing, not requiring include files, and basically illustrating the registers, and the sequence. ie Pseudo-code that should actually compile, and has no external dependencies. As I recall it comes by way of a Keil example or app note, or from example posted by Joseph Yiu, and modified with retelling over time. The CM7 needs the LAR (Lock Access Register) to be written to allow registers to be modified in DWT, this wasn't shown/used in CM3 / CM4 examples. It also relies on the DWT unit being optioned on the core, all STM32 cores compile this in, the CM0(+) parts don't t have that option.

The CMSIS compatible headers should allow you to use more classical C structures and pointers

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
TDK
March 23, 2020

It means DWT is defined in the core_cm7.h file, so you don't need to redefine it. Just use DWT->CYCCNT. This helps your code be more readable/portable. Note that I did not type "DWT_CYCCNT".

"If you feel a post has answered your question, please click ""Accept as Solution""."
Piranha
Principal III
March 23, 2020

Just define STM32F746xx in project settings and include <stm32f7xx.h> in code.

https://community.st.com/s/question/0D53W00000379BESAY/header-files-required-for-programming-stm32f446-mcu-in-c