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
解決済! 解決策の投稿を見る。
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
Hello yf2,
you can use the instruction counter:
DWT->CYCCNT
regards
Hi @yf2 ,
Use this code to get the system clock:
SystemCoreClock = CLOCK_GetRootClockFreq(kCLOCK_Root_M7);
Wish it helps you!
Best Regards,
Kerry
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
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
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
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