2020-03-21 01:16 PM
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;
Solved! Go to Solution.
2020-03-21 01:55 PM
Look at the ARM website, e.g. ARM v7-M Architecture Reference Manual
2020-03-21 01:55 PM
Look at the ARM website, e.g. ARM v7-M Architecture Reference Manual
2020-03-21 02:18 PM
Thank you. I found it. Using that info doesn't look easy, but luckily, I found some code which seem to work.
2020-03-21 05:23 PM
Note also that DWT is generally defined in the header files. So DWT->CYCCNT, for example, should be recognized by the compiler.
2020-03-22 12:30 PM
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.
2020-03-22 08:25 PM
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".
2020-03-22 09:48 PM
Just define STM32F746xx in project settings and include <stm32f7xx.h> in code.
2023-03-18 06:43 AM
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