Showing results for 
Search instead for 
Did you mean: 

STM32F103C8T6 Timer2 and Timer3 Channel 3 PWM not working?

Associate II

I'm trying to set TIM2 in PWM mode, but I'm getting weird results. CH1 to CH4 are enabled but CH3 on PA2 shows no output no matter I do. The weird thing happens when I try to remap TIM2. There are three remap options, Remap2 is the one I'm interested in:

No remap: CH1=PA0, CH2=PA1, CH3=PA2, CH4=PA3 => no output on CH3(PA2)
Remap1: CH1=PA2, CH2=PA3, CH3=PA15, CH4=PB3 => no output on CH1(PA2) and CH3(PA15)
Remap2: CH1=PA0, CH2=PA1, CH3=PB10, CH4=PB11 => no output on CH1(PA0), CH2(PA1) and CH3(PB10)
Remap3: CH1=PA15, CH2=PB3, CH3=PB10, CH4=PB11 => no output on CH2(PB3) and CH3(PB10)

All GPIO ports are configured correctly, CNF=AF and MODE=OUT. TIM2 clock = 36MHz. Tried lower clock but same result. Tried enabling both TIM2 and TIM3 four PWM channels, no remapping. Got no signal out on CH3 on both timers. Tried another Blue Pill, same result. Tested the GPIO ports PA2 and PB0 and they are both ok.

Here is the code I'm using:

 ldr r0, = TIM2      @ APB1 Clock - 36MHz
    ldr r1, = 0
    str r1, [r0, #TIMx_PSC] @ Clock/Prescaler

    ldr r1, = 256
    str r1, [r0, #TIMx_ARR] @ Count-Down value for timer

    ldr r1, = 128           @ Output Compare preload value
    str r1, [r0, #TIMx_CCR1]    @ CH1
    str r1, [r0, #TIMx_CCR2]    @ CH2
    str r1, [r0, #TIMx_CCR3]    @ CH3
    str r1, [r0, #TIMx_CCR4]    @ CH4
    ldr r1, = 6<<OC2M | 1<<OC2PE | 6<<OC1M | 1<<OC1PE
    str r1, [r0, #TIMx_CCMR1]   @ CH1 & CH2 PWM Mode1
    ldr r1, = 6<<OC4M | 1<<OC4PE | 6<<OC3M | 1<<OC3PE
    str r1, [r0, #TIMx_CCMR2]   @ CH3 & CH4 PWM Mode1
    ldr r1, = 1<<CC4E | 1<<CC3E | 1<<CC2E | 1<<CC1E
    str r1, [r0, #TIMx_CCER]    @ CH1 to CH4 Enable

    ldr r1, = 3<<CMS
    str r1, [r0, #TIMx_CR1]


    ldr r1, [r0, #TIMx_CR1]
    orr r1, #1<<CEN     @ Counter Enable
    str r1, [r0, #TIMx_CR1]

What other peripherals are enabled?

Note, that if you use blue pill, it is very unlikely that it's a genuine ST part.


No other peripheral enabled, just the timers.

I made another test enabling all four channels on TIM1, TIM2, TIM3 and TIM4 at the same time.

Only TIM1 outputs signal on all channels.  TIM2, TIM3 and TIM4 don't have output on CH3.

I'm feeling this is a hardware issue. Probably not a genuine ST part.

Read out and check/post content of TIM and relevant GPIO/AFIO registers.



>not a genuine ST part

simple check: in cubeIDE , start debug...if you can debug, its STM part. if GD (GD32F103) , ide will not allow debug.

+ even if GD part, on PA2 is TIM1 ch3 output .  but no remap !


(from gd32f103 ds )


so if nothing coming ever on pa2 - try toggle gpio ...maybe short ?

If you feel a post has answered your question, please click "Accept as Solution".