Accessing DEMCR registers on 1170

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Accessing DEMCR registers on 1170

2,096 Views
yunlian
Contributor I

Hi,

    I want to evaluate some performance on cortax-m7 CPU, so I chose the 1170 board.

I installed the DSP form emcraft and from there I want to access DWT registers for performance monitor.

To do that, I need to modify the DEMCR registers. However, I cannot even access it

Below code gave me a segmentation fault.

How can I access the register then?

 

Thanks

 

#include "stdio.h"

#include "stdint.h"

int main() {        

uint32_t a = (volatile uint32_t)0xE000EDFC;

return 0;

}

0 Kudos
Reply
5 Replies

2,047 Views
yunlian
Contributor I

Thanks all for kindly reply and suggestions,

Re  "2) You assign the variable 'a' the _value_ of 0xE000EDFC ? Why ?"

My code snippet got modified (auto formatting).

The one I try to show is 

uint32_t a = *(volatile uint32_t *)0xE000EDFC;

I want to read/write the content of this register to enable DWT.

However, I got error

(gdb) p *(volatile uint32_t*)0xE000edfc
Cannot access memory at address 0xe000edfc

I tried to create a simple test case with @nickwallis 's implementation.

To do that, I copied some structure declaration and macros from

CMSIS/Core/Include/core_cm7.h

e.g.

typedef struct
{
__IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */
__OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */
__IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */
__IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */
} CoreDebug_Type;

 

But I still got the same issue on the statement

CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; // enable trace for DWT features

The statement above tried to modify the content of address 0xE000EDFC, so this is the same error I got before.

 

I did this exploration on linux dsp from emcrafts and used their gcc toolchain. Would this makes a different?

What environment/work flow do you use to make it work?

 

Thanks

0 Kudos
Reply

2,089 Views
yunlian
Contributor I

Sorry, there were two '*' being eaten when I try to copy the snippet around.

What I am trying to do is something like

https://mcuoneclipse.com/2017/01/30/cycle-counting-on-arm-cortex-m-with-dwt/

to read the DWT_CYCCNT register.

I followed their code and got segmentation fault.

And below is my test code to show that I cannot read the content of this DEMCR register.

I got segmentation fault from it.

 

#include "stdio.h"

#include "stdint.h"

int main() {        

uint32_t a = *(volatile uint32_t *)0xE000EDFC;

return 0;

}

 

 

0 Kudos
Reply

2,079 Views
carstengroen
Senior Contributor II

Please answer my question 1) above.

What do you mean with "segmentation fault"? where is it (precisely) detected?

My DWT implementation on a RT106x (which is also M7) is like this:

//-----------------------------------------------------------------------------
// DWT.c                                                           20140212 CHG
//-----------------------------------------------------------------------------
#include "System.h"
#include "dwt.h"
#include "fsl_device_registers.h"

extern unsigned int SystemCoreClock;
//-----------------------------------------------------------------------------
// Return number of nSec that a number of cycles represent
// Takes CPU clock into account
//-----------------------------------------------------------------------------
unsigned int timeDWT(unsigned int cycles) {
  float clk;
  // Get CPU frequency
  clk=SystemCoreClock;
  return (1E09 * (1.0/clk) * (float)cycles);
}


//-----------------------------------------------------------------------------
// Enable cycle counter
//-----------------------------------------------------------------------------
void enableDWT(void) {
    CoreDebug->DEMCR |= (1<<24);
	DWT->CTRL = 1;
	DWT->CYCCNT = 0;
}

//-----------------------------------------------------------------------------
// return current cycle counter (counts CPU cycles)
//-----------------------------------------------------------------------------
unsigned int readDWT(void) {
  return DWT->CYCCNT;
}

 

0 Kudos
Reply

2,076 Views
nickwallis
Senior Contributor I

I'm not certain it's essential to do this, but in my implementation I unlock access to the DWT registers, like this:

	// measure time
	CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; // enable trace for DWT features
	DWT->LAR = 0xc5acce55; // unlock access to DWT registers
	DWT->CYCCNT = 0; // reset the cycle count value

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

// DO SOMETHING HERE .......

	DWT->CTRL &= ~DWT_CTRL_CYCCNTENA_Msk; // disable the cycle counter

	cycles = DWT->CYCCNT;
0 Kudos
Reply

2,091 Views
carstengroen
Senior Contributor II

1) Where do you expect your program will go when you do a return in the main function ?

2) You assign the variable 'a' the _value_ of 0xE000EDFC ? Why ?

0 Kudos
Reply