This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP432P401R: How to initialize CYCCNT when debugger is not being used

Part Number: MSP432P401R

Hi folks,

I would like to be able to use DWT->CYCCNT for some hardware-based timing during low-level initialization.  However, it appears that the IAR Embedded Workbench automatically initializes the appropriate registers to enable up-counting of DWT->CYCCNT.  When run without the debugger, however, this initialization does not take place, so DWT->CYCCNT does not increment.

Can someone please provide some example code to enable the DWT module and enable DWT->CYCCNT so that the cycle counter will run even when my code is running stand-alone, without a debugger or IDE attached to it?

Many thanks!

  • Hello,

     You will have to set the CYCCNTENA bit in the DWT->CTRL register to enable the Cycle Counter before the counter would start incrementing.

    Try this:

    DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;

    Hopefully this helps.

      David

  • Hi David,

    Thanks for your reply. I had tried this, but it did not seem to work. I forget the link, but I had seen another post about enabling the DWT module, using something like the DEMCR register? I may have the name wrong... I think the author was implying that the DWT module had to be enabled thru some configuration register before the CYCCNT register could be enabled.

    I confess ignorance about this... the IAR environment apparently program the appropriate registers so CYCCNT is enabled right away during a debug session, but it seems that I will need to do it manually when running standalone.

    I sincerely appreciate the help! Thanks.

    Scott
  • I found the link that I mentioned above:  

    embeddedb.blogspot.com/.../how-to-count-cycles-on-arm-cortex-m.html

    The link shows setting the DEMCR as follows:

    // enable the use DWT
    *DEMCR = *DEMCR | 0x01000000;

    I'm not sure if this works yet.  Will have to give it a try today.

    Thanks,

    Scott

  • This seems to work, with thanks to David and the link above:

    // Enable the Data Watch and Trace module
    CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;

    DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; // Turn on the cycle counter

    I can now run stand-alone, and still use CYCCNT for low-level timing.

    Thanks again, David!

    Scott

**Attention** This is a public forum