Вот как я инициализировал timer2 для работы в режиме ШИМ Инициализировал порт А
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // включил порт
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3; //PA0-PA3 выход TIM2_CH1-TIM2_CH3
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
Конфигурирую Timer2 в режим ШИМ четыре канала
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
// Time Base configuration
TIM_TimeBaseStructure.TIM_Period = 10000; // период ШИМ
TIM_TimeBaseStructure.TIM_Prescaler = 2;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
//--------------- Channel 1, 2,3 and 4 Configuration in PWM mode --------------------
// PWM1 Mode configuration: Channel1
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 400; // заполнение периода ШИМ
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM2, &TIM_OCInitStructure);
// ---------PWM1 Mode configuration: Channel2 ------------------
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 800;
TIM_OC2Init(TIM2, &TIM_OCInitStructure);
//----------- PWM1 Mode configuration: Channel3 -----------------
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 1600;
TIM_OC3Init(TIM2, &TIM_OCInitStructure);
//----------- PWM1 Mode configuration: Channel4 ----------------------
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 3200;
TIM_OC4Init(TIM2, &TIM_OCInitStructure);
//---------- TIM1 enable counter --------------
TIM_Cmd(TIM2, ENABLE);
//---------- TIM1 Main Output Enable ----------
TIM_CtrlPWMOutputs(TIM2, ENABLE);