I had to modify PCMaster's code slightly to first enable TIM2 clock, and then for my purposes I tweaked the PSC calculation to give 10x the resolution. But now it's working perfectly for my needs of a tenth of a microsecond timing source.
PCMaster thanks for such a nice concise and simple example!
const uint32_t M4_CLOCK_SPEED = 240000000;
void setupTenthsTimer() {
RCC->APB1LENR |= RCC_APB1LENR_TIM2EN;
TIM2->CR1 = 0;
TIM2->CNT = 0;
TIM2->PSC = (M4_CLOCK_SPEED / 10000000) - 1;
TIM2->ARR = 0xFFFFFFFF;
TIM2->EGR = TIM_EGR_UG;
TIM2->CR1 |= TIM_CR1_CEN;
}
uint32_t getMicrosecondTenths() {
return (uint32_t)TIM2->CNT;
}