Timer (output compare mode) not working on stm32f411re
There doesn't look like to be anything wrong with the assignments of the regsiters.
I believe the right bits are being set. Magic numbers don't help.
Please use the defines in the header file. eg: RCC_AHB1ENR_GPIOAEN
Although TIM2-&gt;CNT |=0; doesn't make sense.
I suspect the problem is with the RCC-&gt;APB1ENR |=1; and the other RCC write.  You need at least one APB clock delay to ensure it is actually set before doing anything else.  Simple way to do that is to read it back.
Snippet from STM32 LL library:
__STATIC_INLINE void LL_AHB1_GRP1_EnableClock(uint32_t Periphs)
{
  __IO uint32_t tmpreg;
  SET_BIT(RCC-&gt;AHB1ENR, Periphs);
  /* Delay after an RCC peripheral clock enabling */
  tmpreg = READ_BIT(RCC-&gt;AHB1ENR, Periphs);
  (void)tmpreg;
}
// __IO expands to the volatile keyword