How to get elapsed time of a function or the system has started?

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

How to get elapsed time of a function or the system has started?

Jump to solution
2,125 Views
vikingyuan
Contributor II

Hi,

I'm using RT1060 and MCUXpresso IDE. Is there any function or SDK sample that I can measured the elapsed time of a function? Or the time since the system has started? Thanks!

0 Kudos
1 Solution
2,120 Views
ErichStyger
Senior Contributor V

The easiest thing is that you simply read the ARM Cortex cycle counter:

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

https://mcuoneclipse.com/2018/06/28/measuring-arm-cortex-m-cpu-cycles-spent-with-the-mcuxpresso-ecli...

With the SystemCoreClock variable you know the clock frequency, with this you have a time information. Just keep in mind that this would not reflect any clock speed changes.

With the above you can measure the time elapsed for a function too.

Otherwise you can use the RTC registers too for a system time.

I hope this helps,

Erich

View solution in original post

3 Replies
2,121 Views
ErichStyger
Senior Contributor V

The easiest thing is that you simply read the ARM Cortex cycle counter:

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

https://mcuoneclipse.com/2018/06/28/measuring-arm-cortex-m-cpu-cycles-spent-with-the-mcuxpresso-ecli...

With the SystemCoreClock variable you know the clock frequency, with this you have a time information. Just keep in mind that this would not reflect any clock speed changes.

With the above you can measure the time elapsed for a function too.

Otherwise you can use the RTC registers too for a system time.

I hope this helps,

Erich

625 Views
GanesanGuru
Contributor IV

Hi @ErichStyger ,

The link mentioned about MCU with DWT feature. What about MCU without DWT?

How to obtain the elapsed time from system startup in iMX RT1064 - to be precise if asked so?

 

0 Kudos
569 Views
ErichStyger
Senior Contributor V

An alternative approach might be to get the execution time with semihosting and

McuSemihost_Op_SYS_CLOCK

See https://mcuoneclipse.com/2023/03/09/using-semihosting-the-direct-way/ and the implementation in McuSemihost.c

I hope this helps,

Erich

 

0 Kudos