Need to measure cycle count using DWT

Hello team,


I am trying to use the DWT unit for getting the cycle count in Debug mode.
Below is my configuration:



Although I am unable to get the cycle count in my code. Any additional configuration needed?

thanks,

Aditya

Parents
  • This code below works for me:


      // Bit mask definitions (*_Msk) are from core_cm3.h

      // To use DWT, you have to set the Trace Enable bit in DEMCR...
      CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;

      // Trace DEMCR might not be writable from CPU (only debugger??)
      if( !(CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) ) {
        GPIO_PinOutSet( LED1 );
        return -1;
      }

      // CYCCNT might not be implemented ?
      if( DWT->CTRL & DWT_CTRL_NOCYCCNT_Msk ) {
        GPIO_PinOutSet( LED1 );
        return -1;
      }
     
      // Reset the cycle counter and enable it, so it starts counting
      DWT->CYCCNT = 0;
      DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;

    Note how I use CoreDebug-> where you used DCB->. Where are you getting the macro 'DCB' from?  I don't see it in e.g. core_cm3.h. 

Reply
  • This code below works for me:


      // Bit mask definitions (*_Msk) are from core_cm3.h

      // To use DWT, you have to set the Trace Enable bit in DEMCR...
      CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;

      // Trace DEMCR might not be writable from CPU (only debugger??)
      if( !(CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) ) {
        GPIO_PinOutSet( LED1 );
        return -1;
      }

      // CYCCNT might not be implemented ?
      if( DWT->CTRL & DWT_CTRL_NOCYCCNT_Msk ) {
        GPIO_PinOutSet( LED1 );
        return -1;
      }
     
      // Reset the cycle counter and enable it, so it starts counting
      DWT->CYCCNT = 0;
      DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;

    Note how I use CoreDebug-> where you used DCB->. Where are you getting the macro 'DCB' from?  I don't see it in e.g. core_cm3.h. 

Children
No data