STM32F411 DWT CYCCNT counter width











up vote
0
down vote

favorite
1












For some time I have been using the DWT cycle counter, CYCCNT in STM32F4 processors for timing operations. Everywhere I look, the assumption is that this is a 32 bit counter.



However, I am now using the STM32F411CE processor and it looks to me like there are only 31 bits.
I run this code:



CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
DWT->CTRL |= 1;
uint32_t next = millis()+200;
DWT->CYCCNT = 0;
while(1){
while(next > millis()){
// do nothing
}
next += 200;
printf("%8lu %12lun",next,DWT->CYCCNT);
}


And observe the results on the terminal. The processor is running at 100MHz, so the counter increases by 20 million after 200ms. After a while the counter value wraps but it wraps at 2^31, not 2^32:



21435   2039916353
21635 2059916353
21835 2079916353
22035 2099916353
22235 2119916353
22435 2139916341
22635 12432705
22835 32432705
23035 52432705
23235 72432705


So, can anyone point me to any definitive information about the CYCCNT counter width on the STM32F411 processor? Or have I overlooked something embarrassingly simple?



UPDATE:



I ran the exact same code on a board containing an STM32F405 processor and got these results:



30419   4204732031
30619 4233532031
30819 4262332031
31019 4291132031
31219 24964735
31419 53764738
31619 82564738
31819 111364735


So it seems clear to me that the '405 processor CYCCNT register is 32 bit whereas the '411 processor is only 31 bit. Most odd!



UPDATE2:



A second board with the same processor type behaves perfectly as well. A friend also ran the code on his (different) '411 board with no problems. It now seems that the board itself is faulty or, possibly, the processor is broken. All the other processor functions appear correct. Looks like it is just time to swap out the processor.










share|improve this question
























  • How strange. Thanks for updating.
    – Colin
    Nov 25 at 11:25















up vote
0
down vote

favorite
1












For some time I have been using the DWT cycle counter, CYCCNT in STM32F4 processors for timing operations. Everywhere I look, the assumption is that this is a 32 bit counter.



However, I am now using the STM32F411CE processor and it looks to me like there are only 31 bits.
I run this code:



CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
DWT->CTRL |= 1;
uint32_t next = millis()+200;
DWT->CYCCNT = 0;
while(1){
while(next > millis()){
// do nothing
}
next += 200;
printf("%8lu %12lun",next,DWT->CYCCNT);
}


And observe the results on the terminal. The processor is running at 100MHz, so the counter increases by 20 million after 200ms. After a while the counter value wraps but it wraps at 2^31, not 2^32:



21435   2039916353
21635 2059916353
21835 2079916353
22035 2099916353
22235 2119916353
22435 2139916341
22635 12432705
22835 32432705
23035 52432705
23235 72432705


So, can anyone point me to any definitive information about the CYCCNT counter width on the STM32F411 processor? Or have I overlooked something embarrassingly simple?



UPDATE:



I ran the exact same code on a board containing an STM32F405 processor and got these results:



30419   4204732031
30619 4233532031
30819 4262332031
31019 4291132031
31219 24964735
31419 53764738
31619 82564738
31819 111364735


So it seems clear to me that the '405 processor CYCCNT register is 32 bit whereas the '411 processor is only 31 bit. Most odd!



UPDATE2:



A second board with the same processor type behaves perfectly as well. A friend also ran the code on his (different) '411 board with no problems. It now seems that the board itself is faulty or, possibly, the processor is broken. All the other processor functions appear correct. Looks like it is just time to swap out the processor.










share|improve this question
























  • How strange. Thanks for updating.
    – Colin
    Nov 25 at 11:25













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





For some time I have been using the DWT cycle counter, CYCCNT in STM32F4 processors for timing operations. Everywhere I look, the assumption is that this is a 32 bit counter.



However, I am now using the STM32F411CE processor and it looks to me like there are only 31 bits.
I run this code:



CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
DWT->CTRL |= 1;
uint32_t next = millis()+200;
DWT->CYCCNT = 0;
while(1){
while(next > millis()){
// do nothing
}
next += 200;
printf("%8lu %12lun",next,DWT->CYCCNT);
}


And observe the results on the terminal. The processor is running at 100MHz, so the counter increases by 20 million after 200ms. After a while the counter value wraps but it wraps at 2^31, not 2^32:



21435   2039916353
21635 2059916353
21835 2079916353
22035 2099916353
22235 2119916353
22435 2139916341
22635 12432705
22835 32432705
23035 52432705
23235 72432705


So, can anyone point me to any definitive information about the CYCCNT counter width on the STM32F411 processor? Or have I overlooked something embarrassingly simple?



UPDATE:



I ran the exact same code on a board containing an STM32F405 processor and got these results:



30419   4204732031
30619 4233532031
30819 4262332031
31019 4291132031
31219 24964735
31419 53764738
31619 82564738
31819 111364735


So it seems clear to me that the '405 processor CYCCNT register is 32 bit whereas the '411 processor is only 31 bit. Most odd!



UPDATE2:



A second board with the same processor type behaves perfectly as well. A friend also ran the code on his (different) '411 board with no problems. It now seems that the board itself is faulty or, possibly, the processor is broken. All the other processor functions appear correct. Looks like it is just time to swap out the processor.










share|improve this question















For some time I have been using the DWT cycle counter, CYCCNT in STM32F4 processors for timing operations. Everywhere I look, the assumption is that this is a 32 bit counter.



However, I am now using the STM32F411CE processor and it looks to me like there are only 31 bits.
I run this code:



CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
DWT->CTRL |= 1;
uint32_t next = millis()+200;
DWT->CYCCNT = 0;
while(1){
while(next > millis()){
// do nothing
}
next += 200;
printf("%8lu %12lun",next,DWT->CYCCNT);
}


And observe the results on the terminal. The processor is running at 100MHz, so the counter increases by 20 million after 200ms. After a while the counter value wraps but it wraps at 2^31, not 2^32:



21435   2039916353
21635 2059916353
21835 2079916353
22035 2099916353
22235 2119916353
22435 2139916341
22635 12432705
22835 32432705
23035 52432705
23235 72432705


So, can anyone point me to any definitive information about the CYCCNT counter width on the STM32F411 processor? Or have I overlooked something embarrassingly simple?



UPDATE:



I ran the exact same code on a board containing an STM32F405 processor and got these results:



30419   4204732031
30619 4233532031
30819 4262332031
31019 4291132031
31219 24964735
31419 53764738
31619 82564738
31819 111364735


So it seems clear to me that the '405 processor CYCCNT register is 32 bit whereas the '411 processor is only 31 bit. Most odd!



UPDATE2:



A second board with the same processor type behaves perfectly as well. A friend also ran the code on his (different) '411 board with no problems. It now seems that the board itself is faulty or, possibly, the processor is broken. All the other processor functions appear correct. Looks like it is just time to swap out the processor.







stm32 stm32f4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 at 0:38

























asked Nov 22 at 15:52









Peter Harrison

58119




58119












  • How strange. Thanks for updating.
    – Colin
    Nov 25 at 11:25


















  • How strange. Thanks for updating.
    – Colin
    Nov 25 at 11:25
















How strange. Thanks for updating.
– Colin
Nov 25 at 11:25




How strange. Thanks for updating.
– Colin
Nov 25 at 11:25












1 Answer
1






active

oldest

votes

















up vote
0
down vote













The description of DWT_CYCCNT is in section C1.8.8 of the Arm V7m Architecture Reference manual which you can get from here



Section C1.8.3 says




CYCCNT is an optional free-running 32-bit cycle counter.



When implemented and enabled, CYCCNT increments on each cycle of the processor clock. When the counter
overflows it wraps to zero, transparently.




So this doesn't explain your findings.






share|improve this answer





















  • Thanks for the link. At least now I know it is supposed to be 32 bit.
    – Peter Harrison
    Nov 23 at 14:00











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434504%2fstm32f411-dwt-cyccnt-counter-width%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













The description of DWT_CYCCNT is in section C1.8.8 of the Arm V7m Architecture Reference manual which you can get from here



Section C1.8.3 says




CYCCNT is an optional free-running 32-bit cycle counter.



When implemented and enabled, CYCCNT increments on each cycle of the processor clock. When the counter
overflows it wraps to zero, transparently.




So this doesn't explain your findings.






share|improve this answer





















  • Thanks for the link. At least now I know it is supposed to be 32 bit.
    – Peter Harrison
    Nov 23 at 14:00















up vote
0
down vote













The description of DWT_CYCCNT is in section C1.8.8 of the Arm V7m Architecture Reference manual which you can get from here



Section C1.8.3 says




CYCCNT is an optional free-running 32-bit cycle counter.



When implemented and enabled, CYCCNT increments on each cycle of the processor clock. When the counter
overflows it wraps to zero, transparently.




So this doesn't explain your findings.






share|improve this answer





















  • Thanks for the link. At least now I know it is supposed to be 32 bit.
    – Peter Harrison
    Nov 23 at 14:00













up vote
0
down vote










up vote
0
down vote









The description of DWT_CYCCNT is in section C1.8.8 of the Arm V7m Architecture Reference manual which you can get from here



Section C1.8.3 says




CYCCNT is an optional free-running 32-bit cycle counter.



When implemented and enabled, CYCCNT increments on each cycle of the processor clock. When the counter
overflows it wraps to zero, transparently.




So this doesn't explain your findings.






share|improve this answer












The description of DWT_CYCCNT is in section C1.8.8 of the Arm V7m Architecture Reference manual which you can get from here



Section C1.8.3 says




CYCCNT is an optional free-running 32-bit cycle counter.



When implemented and enabled, CYCCNT increments on each cycle of the processor clock. When the counter
overflows it wraps to zero, transparently.




So this doesn't explain your findings.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 at 16:15









Colin

1,98511222




1,98511222












  • Thanks for the link. At least now I know it is supposed to be 32 bit.
    – Peter Harrison
    Nov 23 at 14:00


















  • Thanks for the link. At least now I know it is supposed to be 32 bit.
    – Peter Harrison
    Nov 23 at 14:00
















Thanks for the link. At least now I know it is supposed to be 32 bit.
– Peter Harrison
Nov 23 at 14:00




Thanks for the link. At least now I know it is supposed to be 32 bit.
– Peter Harrison
Nov 23 at 14:00


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434504%2fstm32f411-dwt-cyccnt-counter-width%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

Alexandru Averescu

Trompette piccolo