cancel
Showing results for 
Search instead for 
Did you mean: 

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

LMI2
Lead

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Uwe Bonnes
Principal III

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

View solution in original post

7 REPLIES 7
Uwe Bonnes
Principal III

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

LMI2
Lead

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

TDK
Guru

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
Lead

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.

TDK
Guru

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
Chief II

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

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
Up vote any posts that you find helpful, it shows what's working..