cancel
Showing results for 
Search instead for 
Did you mean: 

PWM Channels 3 and 4 of TIM2 not working on STM32L053

EPrüß.1
Associate II

As per the title: I am using Timer 2 for a PWM. Channel 1 and 2 work just fine, but Channel 3 and 4 won't output anything. Created the project with CubeMX. Tried enabling all 4 channels with all the same values except pulse (CCR) and probed the output-pins. The only user code is enabling the PWM with HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_1), ..._2), ..._3) and ..._4).

In the created code the Config-Struct is created, Channel 1 is initialized, only the pulse variable is changed, Channel 2 is initialized, etc.

The only difference between Channel 1 and 2 and Channel 3 and 4 I found is the CCMR1 / CCRM2 register.

Has anyone an idea where this error might stem from?

1 ACCEPTED SOLUTION

Accepted Solutions

On Nucleo64, PA2 and PA3 are connected through solder bridges to the onboard STLink's VCP Rx and Rx. See Nucleo manual and schematics.

I guess CubeMX caters for this connection. I don't use Cube/CubeMX and I generally recommend against using it.

JW

View solution in original post

4 REPLIES 4

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

What hardware? Are you sure the pins for TIM2_CH3/CH4 are properly connected? You can check them by setting them to GPIO output and toggling "manually".

JW

EPrüß.1
Associate II

Didn't check the GPIO registers yesterday. TIM registers look fine, GPIOA registers are not. In MODER the bits for all channels are set correctly to 0b10 (alternate function). The other registers have PA2 and PA3 set to the wrong type, speed, etc.. I don't know why that is as all GPIOs are initialized with the same arguements in HAL_TIM_MspPostInit and there isn't a second function in hal_msp that could set it to different values. Also all GPIOs are initialized with low speed, but Ch1 has high speed set in OSPEEDR. Similar with OTYPER, PUPDR.

My hardware is a NUCLEO-L053R9 board.

EPrüß.1
Associate II

Found my problem: The solder bridges on the bottom of the board.

GPOI registers were fine, just a bit confusing to read as the binary cuts off leading zeros.

To connect PA2 and PA3 to the 2.54mm pins, SB62 and SB63 must be bridged.

On Nucleo64, PA2 and PA3 are connected through solder bridges to the onboard STLink's VCP Rx and Rx. See Nucleo manual and schematics.

I guess CubeMX caters for this connection. I don't use Cube/CubeMX and I generally recommend against using it.

JW