High resolution time on iMX8 M4 in FreeRTOS

I would like to measure the time interval between successive bytes received by the M4 UART. I would like a high resolution reading, ideally nanosecond but sub microsecond would do. Obviously the clock ticks are way too slow so is it possible to read the real time clock via the M4 using FreeRTOS?

The timing does not need to be absolute, just the relative time between successive reads.

Hi @Andy.McClernon!

Usually with FreeRTOS you can only measure time relative to the tick interrupt frequency.

A possible solution would be to initialize another, unused timer (TPM or LPIT) and get data from that with a function reading from that timer.

Hi @gustavo.tx and @Andy.McClernon,

I think this is an interesting when you think about synchronising data acquisition between the M4 and the A53 cores. Ideally I would like to read the same high resolution timer that I get from time.time_ns() under Linux.

Does anyone know if that is possible? How are other people synchronising data across the cores?



Hey @edwaugh!

This can probably be done by using the proper timer peripheral interrupt, but I don’t know if the MCUXpresso SDK provides any such examples. The peripheral should be able to trigger these interrupts, though.