2021-05-21 05:36 AM
I need some clock synchronization between M4 and A7 cores. So I need steady clock values from A7 and M4 for single time point
Solved! Go to Solution.
2021-05-24 06:37 AM
From M4, for instance:
(note that as you read a 64 bit counter over a 32-bit bus, you should ensure no rollover in between the two access of STGEN registers)
#define STGENR_CNTCVL_OFF 0x0000
#define STGENR_CNTCVU_OFF 0x0004
#define STGENR_CNTCVL (*(uint32_t *) (STGENR_BASE + STGENR_CNTCVL_OFF))
#define STGENR_CNTCVU (*(uint32_t *) (STGENR_BASE + STGENR_CNTCVU_OFF))
uint32_t cntr_upper, cntr_lower;
uint64_t cntr;
__HAL_RCC_STGENRO_CLK_ENABLE();
do
{
cntr_upper = STGENR_CNTCVU;
cntr_lower = STGENR_CNTCVL;
}
while (STGENR_CNTCVU != cntr_upper);
cntr = ((uint64_t)cntr_upper << 32) + (uint64_t)cntr_lower;
This code is for example only (not tested).
Regards.
2021-05-21 06:37 AM
Hi,
there is many different ways, depending on SW effort and precision you need. e.g.:
Regards.
2021-05-21 06:56 AM
If I allocate two different TIMers (one for Linux, one on M4) with same trigger source, these timers would start working at different times (one at Linux startup, another at M4 firmware startup) . They would have shift. How can I measure this shift ?
2021-05-21 07:05 AM
I was more thinking about two timers reset regularly by a common source (e.g. once every second or more), not sure this is easy to do nor it will work with your requirements.
STGENR (which is typically a 64 bit counter on HSE) might be more straightforward if high precision is needed.
2021-05-24 12:37 AM
From here https://wiki.st.com/stm32mpu/wiki/STGEN_internal_peripheral it comes out like STGEN is Linux side only. How can I get its values from M4 side ?
2021-05-24 06:37 AM
From M4, for instance:
(note that as you read a 64 bit counter over a 32-bit bus, you should ensure no rollover in between the two access of STGEN registers)
#define STGENR_CNTCVL_OFF 0x0000
#define STGENR_CNTCVU_OFF 0x0004
#define STGENR_CNTCVL (*(uint32_t *) (STGENR_BASE + STGENR_CNTCVL_OFF))
#define STGENR_CNTCVU (*(uint32_t *) (STGENR_BASE + STGENR_CNTCVU_OFF))
uint32_t cntr_upper, cntr_lower;
uint64_t cntr;
__HAL_RCC_STGENRO_CLK_ENABLE();
do
{
cntr_upper = STGENR_CNTCVU;
cntr_lower = STGENR_CNTCVL;
}
while (STGENR_CNTCVU != cntr_upper);
cntr = ((uint64_t)cntr_upper << 32) + (uint64_t)cntr_lower;
This code is for example only (not tested).
Regards.
2021-06-01 07:56 AM
Hi! Why don't you recommend to read M4 Timer directly from Linux? This way looks the most obvious and accurate.
2021-06-01 08:15 AM
Hi,
I'm more an Hw guy and I'm not sure, for Sw point of view, it is possible to setup a Linux user space application to read timers which are only assigned to M4 runtime without some hack or not portable/clean SW. E.g. you cannot be sure the TIMx access paths are clocked as TIMx is not assigned to Linux, thus could lead to Linux crash/deadlock if e.g. the Cortex-M4 application is not yet started or in low-power mode.
But for sure, HW-wise it is possible to read them from Linux, except obviously if TIMx resource is isolated using ETZPC config.
Regards.