<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Accessing DEMCR registers on 1170 in i.MX RT Crossover MCUs</title>
    <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Accessing-DEMCR-registers-on-1170/m-p/1516458#M21450</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; I want to evaluate some performance on cortax-m7 CPU, so I chose the 1170 board.&lt;/P&gt;&lt;P&gt;I installed the DSP form emcraft and from there I want to access DWT registers for performance monitor.&lt;/P&gt;&lt;P&gt;To do that, I need to modify the&amp;nbsp;DEMCR registers. However, I cannot even access it&lt;/P&gt;&lt;P&gt;Below code gave me a segmentation fault.&lt;/P&gt;&lt;P&gt;How can I access the register then?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;#include "stdio.h"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;#include "stdint.h" &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;int main() { &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;uint32_t a = &lt;/SPAN&gt;&lt;STRONG&gt;(volatile uint32_t&lt;/STRONG&gt;&lt;SPAN&gt;)0xE000EDFC; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;return 0; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Sep 2022 19:39:41 GMT</pubDate>
    <dc:creator>yunlian</dc:creator>
    <dc:date>2022-09-02T19:39:41Z</dc:date>
    <item>
      <title>Accessing DEMCR registers on 1170</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Accessing-DEMCR-registers-on-1170/m-p/1516458#M21450</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; I want to evaluate some performance on cortax-m7 CPU, so I chose the 1170 board.&lt;/P&gt;&lt;P&gt;I installed the DSP form emcraft and from there I want to access DWT registers for performance monitor.&lt;/P&gt;&lt;P&gt;To do that, I need to modify the&amp;nbsp;DEMCR registers. However, I cannot even access it&lt;/P&gt;&lt;P&gt;Below code gave me a segmentation fault.&lt;/P&gt;&lt;P&gt;How can I access the register then?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;#include "stdio.h"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;#include "stdint.h" &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;int main() { &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;uint32_t a = &lt;/SPAN&gt;&lt;STRONG&gt;(volatile uint32_t&lt;/STRONG&gt;&lt;SPAN&gt;)0xE000EDFC; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;return 0; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 19:39:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Accessing-DEMCR-registers-on-1170/m-p/1516458#M21450</guid>
      <dc:creator>yunlian</dc:creator>
      <dc:date>2022-09-02T19:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing DEMCR registers on 1170</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Accessing-DEMCR-registers-on-1170/m-p/1516466#M21451</link>
      <description>&lt;P&gt;1) Where do you expect your program will go when you do a return in the main function ?&lt;/P&gt;&lt;P&gt;2) You assign the variable 'a' the _value_ of&amp;nbsp;&lt;SPAN&gt;0xE000EDFC ? Why ?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 20:26:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Accessing-DEMCR-registers-on-1170/m-p/1516466#M21451</guid>
      <dc:creator>carstengroen</dc:creator>
      <dc:date>2022-09-02T20:26:09Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing DEMCR registers on 1170</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Accessing-DEMCR-registers-on-1170/m-p/1516478#M21453</link>
      <description>&lt;P&gt;Sorry, there were two '*' being eaten when I try to copy the snippet around.&lt;/P&gt;&lt;P&gt;What I am trying to do is something like&lt;/P&gt;&lt;P&gt;&lt;A href="https://mcuoneclipse.com/2017/01/30/cycle-counting-on-arm-cortex-m-with-dwt/" target="_blank"&gt;https://mcuoneclipse.com/2017/01/30/cycle-counting-on-arm-cortex-m-with-dwt/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;to read the&amp;nbsp;&lt;SPAN&gt;DWT_CYCCNT register.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I followed their code and got segmentation fault.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And below is my test code to show that I cannot read the content of this&amp;nbsp;DEMCR register.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I got segmentation fault from it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;#include "stdio.h"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;#include "stdint.h"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;int main() { &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;uint32_t&lt;/SPAN&gt; a =&amp;nbsp;*(volatile uint32_t *)0xE000EDFC;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;return 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 21:32:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Accessing-DEMCR-registers-on-1170/m-p/1516478#M21453</guid>
      <dc:creator>yunlian</dc:creator>
      <dc:date>2022-09-02T21:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing DEMCR registers on 1170</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Accessing-DEMCR-registers-on-1170/m-p/1516530#M21455</link>
      <description>&lt;P&gt;Please answer my question 1) above.&lt;/P&gt;&lt;P&gt;What do you mean with "segmentation fault"? where is it (precisely) detected?&lt;/P&gt;&lt;P&gt;My DWT implementation on a RT106x (which is also M7) is like this:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;//-----------------------------------------------------------------------------
// 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-&amp;gt;DEMCR |= (1&amp;lt;&amp;lt;24);
	DWT-&amp;gt;CTRL = 1;
	DWT-&amp;gt;CYCCNT = 0;
}

//-----------------------------------------------------------------------------
// return current cycle counter (counts CPU cycles)
//-----------------------------------------------------------------------------
unsigned int readDWT(void) {
  return DWT-&amp;gt;CYCCNT;
}
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Sep 2022 07:39:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Accessing-DEMCR-registers-on-1170/m-p/1516530#M21455</guid>
      <dc:creator>carstengroen</dc:creator>
      <dc:date>2022-09-03T07:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing DEMCR registers on 1170</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Accessing-DEMCR-registers-on-1170/m-p/1516548#M21456</link>
      <description>&lt;P&gt;I'm not certain it's essential to do this, but in my implementation I unlock access to the DWT registers, like this:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;	// measure time
	CoreDebug-&amp;gt;DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; // enable trace for DWT features
	DWT-&amp;gt;LAR = 0xc5acce55; // unlock access to DWT registers
	DWT-&amp;gt;CYCCNT = 0; // reset the cycle count value

	DWT-&amp;gt;CTRL |= DWT_CTRL_CYCCNTENA_Msk; // enable the cycle counter

// DO SOMETHING HERE .......

	DWT-&amp;gt;CTRL &amp;amp;= ~DWT_CTRL_CYCCNTENA_Msk; // disable the cycle counter

	cycles = DWT-&amp;gt;CYCCNT;&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 03 Sep 2022 12:42:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Accessing-DEMCR-registers-on-1170/m-p/1516548#M21456</guid>
      <dc:creator>nickwallis</dc:creator>
      <dc:date>2022-09-03T12:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing DEMCR registers on 1170</title>
      <link>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Accessing-DEMCR-registers-on-1170/m-p/1518757#M21518</link>
      <description>&lt;P&gt;Thanks all for kindly reply and suggestions,&lt;/P&gt;&lt;P&gt;Re&amp;nbsp; "&lt;SPAN&gt;2) You assign the variable 'a' the _value_ of&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;0xE000EDFC ? Why ?"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My code snippet got modified (auto formatting).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The one I try to show is&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;uint32_t&amp;nbsp;a =&amp;nbsp;*(volatile uint32_t *)0xE000EDFC;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to read/write the content of this register to enable DWT.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However, I got error&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;(gdb) p *(volatile uint32_t*)0xE000edfc&lt;BR /&gt;Cannot access memory at address 0xe000edfc&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I tried to create a simple test case with&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/77802"&gt;@nickwallis&lt;/a&gt; 's implementation.&lt;/P&gt;&lt;P&gt;To do that, I copied some structure declaration and macros from&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;CMSIS/Core/Include/core_cm7.h&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;e.g.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;typedef struct&lt;BR /&gt;{&lt;BR /&gt;__IOM uint32_t DHCSR; /*!&amp;lt; Offset: 0x000 (R/W) Debug Halting Control and Status Register */&lt;BR /&gt;__OM uint32_t DCRSR; /*!&amp;lt; Offset: 0x004 ( /W) Debug Core Register Selector Register */&lt;BR /&gt;__IOM uint32_t DCRDR; /*!&amp;lt; Offset: 0x008 (R/W) Debug Core Register Data Register */&lt;BR /&gt;__IOM uint32_t DEMCR; /*!&amp;lt; Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */&lt;BR /&gt;} CoreDebug_Type;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;&lt;SPAN class=""&gt;But I still got the same issue on the statement&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;CoreDebug-&amp;gt;DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; // enable trace for DWT features&lt;/PRE&gt;&lt;P&gt;The statement above tried to modify the content of address&amp;nbsp;&lt;SPAN&gt;0xE000EDFC, so this is the same error I got before.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I did this exploration on linux dsp from emcrafts and used their gcc toolchain. Would this makes a different?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What environment/work flow do you use to make it work?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 22:05:51 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-RT-Crossover-MCUs/Accessing-DEMCR-registers-on-1170/m-p/1518757#M21518</guid>
      <dc:creator>yunlian</dc:creator>
      <dc:date>2022-09-07T22:05:51Z</dc:date>
    </item>
  </channel>
</rss>

