Inaccurate timer interrupt STM32
There are two things wrong with your code:

1) you attempt to reset and restart the counter in the interrupt handler with "TIM1->EGR |= 0x01;" . But you're using the automatic reload mode of the counter so you shouldn't do that.

2) You never clear the interrupt from the timer. The timer sets the interrupt,
but you're responsible for clearing it once you've handled it. Since you don't do that, when your IRQ handler returns, the cpu immediately dispatches the same interrupt and calls it again. To clear the interrupt you need to clear bit 0 of TIM1_SR with something like

TIM1->SR &amp;= ~0x1; 

(or perhaps TIM1->SR &amp;= ~TIM_SR_UIF; if you have that defined)