How to read system clock value of RT117x

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to read system clock value of RT117x

ソリューションへジャンプ
2,088件の閲覧回数
yf2
Contributor III

Dear support,

I am learning RT117x programming with RT1170-EVK and I can run simple minimum program like below from debugger:

void main(){
int j;
for(int i=0;i<10;i++){
j=10-i;
}
}

This is obviously meaningless but it can run in debugger and we can add more features.

Now I am wondering what API is available for me to read the system wall clock value so that to know how time goes between different operations? 

Regards,

yf2

 

タグ(1)
0 件の賞賛
返信
1 解決策
2,037件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @yf2 ,

 Some code snap like this:

uint32_t cnt_start_value;
uint32_t cnt_end_value;
uint32_t overhead;

void systick_init(void)
{
    SysTick->VAL   = 0UL;	//clear current timer value
    SysTick->LOAD = 0x00FFFFFF;
    SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;   
}

void systick_disable(void)
{
    SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
}

void cal_systick_read_overhead(void)
{
  	uint32_t cnt_start_value;
    uint32_t cnt_end_value;
	
	cnt_start_value = SysTick->VAL;
  
    cnt_end_value = SysTick->VAL;
	
	overhead = cnt_start_value - cnt_end_value;
	
#ifdef DEBUG_PRINT
	printf("systick start value: 0x%x\n\r", cnt_start_value);
	printf("systick end value: 0x%x\n\r", cnt_end_value);
	printf("systick current value read overhead: 0x%x\n\r", overhead);
#endif

}

	systick_init();	
	cal_systick_read_overhead();
	systick_disable();

	systick_init();	
	test_app();
	systick_disable();

void test_app()
{
  	uint32_t cnt_start_value;
    uint32_t cnt_end_value;
	uint32_t execution_cycle;	//actual execution cycle
	cnt_start_value = SysTick->VAL;
//Your code line, eg
   int j;
   for(int i=0;i<10;i++){
      j=10-i;
   }	
	cnt_start_value = SysTick->VAL;
	
	execution_cycle = cnt_start_value - cnt_end_value - overhead;
	
#ifdef DEBUG_PRINT
	printf("systick start value: 0x%x\n\r", cnt_start_value);
	printf("systick end value: 0x%x\n\r", cnt_end_value);
	printf("actual execution cycle for code: 0x%x\n\r", execution_cycle);
#endif	
}

 

 

Wish it helps you!

Best Regards,

Kerry

元の投稿で解決策を見る

0 件の賞賛
返信
6 返答(返信)
2,070件の閲覧回数
Masmiseim
Senior Contributor I

Hello yf2,

you can use the instruction counter:
DWT->CYCCNT

regards

2,080件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @yf2 ,

  Use this code to get the system clock:

SystemCoreClock = CLOCK_GetRootClockFreq(kCLOCK_Root_M7);

 

Wish it helps you!

Best Regards,

Kerry

0 件の賞賛
返信
2,075件の閲覧回数
yf2
Contributor III

@kerryzhou 

You might have misunderstood my question. I don't need system clock frequency, I need a simple way to know the current time, better to microsecond (us) precision.

Regards,

yf2

 

 

0 件の賞賛
返信
2,073件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @yf2 ,

  So, you want to know the code execution time, right?

  If yes, you totally can use the systick,  before your API, reset the systick, then after API, read the systick counter, then you can cacluate the time.

 Even other timer also can do it.

Best Regards,

kerry

0 件の賞賛
返信
2,057件の閲覧回数
yf2
Contributor III

@kerryzhou 

 

Yes maybe this systick thing can meet my requirements, can you teach how to read it with a few lines of source code?

 

Regards,

yf2

0 件の賞賛
返信
2,038件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi @yf2 ,

 Some code snap like this:

uint32_t cnt_start_value;
uint32_t cnt_end_value;
uint32_t overhead;

void systick_init(void)
{
    SysTick->VAL   = 0UL;	//clear current timer value
    SysTick->LOAD = 0x00FFFFFF;
    SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;   
}

void systick_disable(void)
{
    SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
}

void cal_systick_read_overhead(void)
{
  	uint32_t cnt_start_value;
    uint32_t cnt_end_value;
	
	cnt_start_value = SysTick->VAL;
  
    cnt_end_value = SysTick->VAL;
	
	overhead = cnt_start_value - cnt_end_value;
	
#ifdef DEBUG_PRINT
	printf("systick start value: 0x%x\n\r", cnt_start_value);
	printf("systick end value: 0x%x\n\r", cnt_end_value);
	printf("systick current value read overhead: 0x%x\n\r", overhead);
#endif

}

	systick_init();	
	cal_systick_read_overhead();
	systick_disable();

	systick_init();	
	test_app();
	systick_disable();

void test_app()
{
  	uint32_t cnt_start_value;
    uint32_t cnt_end_value;
	uint32_t execution_cycle;	//actual execution cycle
	cnt_start_value = SysTick->VAL;
//Your code line, eg
   int j;
   for(int i=0;i<10;i++){
      j=10-i;
   }	
	cnt_start_value = SysTick->VAL;
	
	execution_cycle = cnt_start_value - cnt_end_value - overhead;
	
#ifdef DEBUG_PRINT
	printf("systick start value: 0x%x\n\r", cnt_start_value);
	printf("systick end value: 0x%x\n\r", cnt_end_value);
	printf("actual execution cycle for code: 0x%x\n\r", execution_cycle);
#endif	
}

 

 

Wish it helps you!

Best Regards,

Kerry

0 件の賞賛
返信