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.
In order to give better visibility on the answered topics, please click on 'Best Answer' on the reply which solved your issue or answered your question.Tip of the day: Try Sidekick STM32 AI agent