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

14 REPLIES 14

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

Hey i wanted to ask that there are more bridges that are unslodered on my stm32f401re board do i need to solder them too like i am facing the same problem of channel 4 and channel 3 pwm output though ch1 and 2 are working correctly . also can u tell me more about like why these boards come with unsoldered bridges  as i am beginner.

thank u 

Check in UM1724 and in the schematics: you can find both on the Nucleo's web folder, one under Documentation and the other under CAD Resources tab.

JW

Thanks 

 

Velecs
Associate II

Hey can u also tell me like i am implemeting usar1 on my stm32f401re baremetal and whenever i put this condition if ( USART2->SR & USART_SR_RXNE ) in the reception function i never enters the condition and it cant return the recieved data.

also if i just recive data without any condition it works properly and i am also observing that the rxe bit in the sr register never sets .

can u help me with this issue 

this is  the code snipeet of reception code 

 

volatile uint8_t Uart_Receive(int Uart_Module) {

uint8_t receivedData = 0; // Variable to hold received data

 

if (Uart_Module == 1) {

// Check if data is received (RXNE flag set) for USART1

//while( !( USART1->SR & RXE )){ // RXNE flag has a direct value of 0x20

if ( USART2->SR & RXE ){

receivedData = (uint8_t)USART1->DR; // Read received data

return receivedData;

}

} else if (Uart_Module == 6) {

// Check if data is received (RXNE flag set) for USART6

while( !( USART6->SR & RXE )) { // RXNE flag has a direct value of 0x20

receivedData = (uint8_t)USART6->DR; // Read received data

return receivedData;

}

}

 

return 0; // Return 0 if no data is received or invalid UART module

}

> i am implemeting usar1 on my stm32f401re baremetal and whenever i put this condition if ( USART2->SR & USART_SR_RXNE )

So, USART1 or USART2?

Also, in the code snippet, you have some RXE symbol, are you sure it's equal to USART_SR_RXNE?

Also, if you observe the USART registers (namely USART_DR) in the debugger, it will clear the USART_SR.RXNE flag in the same way as if you read it from processor, so don't observe the USART registers in debugger during debugging.

JW