Using one timer as prescaler for another timer STM32F103RB
Hello,
STM32F103RB microcontroller.
I want to use Using one timer as prescaler for another timer mode (see figures below).


I want the slave timer to increment its counter every time the master timer generates update events. But the slave timer does this regardless of the update event (incrementing occurs constantly). I can't understand why. Tell me what I did wrong? I'm attaching the code.
#include "stm32f1xx.h"
static void init_tim3(void);
static void init_tim4(void);
static void init_tim3(void)
{
TIM3->CR1 &= ~0x00000001;
TIM3->CR2 |= 0x0020;
TIM3->PSC = 0x00000000;
TIM3->ARR = 0xFFFF;
TIM3->CNT = 0x0000;
TIM3->SR &= ~0x0001;
TIM3->DIER |= 0x0001;
//TIM3->CR1 |= 0x00000001;
}
static void init_tim4(void)
{
TIM4->CR1 &= ~0x00000001;
TIM4->SMCR |= 0x0020;
TIM4->SMCR |= 0x0007;
TIM4->PSC = 0x00000000;
TIM4->ARR = 0x007A;
TIM4->CNT = 0x0000;
//TIM4->CR1 |= 0x00000001;
}
void init_tim3_tim4(void)
{
init_tim3();
init_tim4();
TIM3->CR1 |= 0x00000001;
TIM4->CR1 |= 0x00000001;
}
