2026-03-08 4:11 PM
Trying to run timer2 to set pwm signal for the BLUE LED (PA5).
The MCU is STM32U083MCT6 and I used rm for STM32U083MC series (https://www.st.com/resource/en/reference_manual/rm0503-stm32u0-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf)
I set each bit and register separately to be sure that everything is set correctly, but still miss something related to TIM2.
What settings to check related to TIM2 and what is the best approach to configure timers of this MCU?
Solved! Go to Solution.
2026-03-08 4:22 PM
Generate an update event to update ARR.
2026-03-08 4:22 PM
Generate an update event to update ARR.
2026-03-09 3:25 AM
It works! Thank you!
2026-03-09 5:04 AM
Hello @Turbo
Did you enable the GPIOA clock?
I'am not seeing
RCC->IOPENR |= RCC_IOPENR_GPIOAEN;
in your code.
However, can you try this code sequence, it should make you able to toggle PA5 pin using TIM2
/* USER CODE BEGIN 2 */
RCC->IOPENR |= RCC_IOPENR_GPIOAEN;
RCC->APBENR1 |= RCC_APBENR1_TIM2EN;
(void)RCC->IOPENR;
GPIOA->MODER &= ~(0x3U << (5 * 2));
GPIOA->MODER |= (0x2U << (5 * 2));
GPIOA->OTYPER &= ~(1U << 5);
GPIOA->OSPEEDR &= ~(0x3U << (5 * 2));
GPIOA->OSPEEDR |= (0x3U << (5 * 2));
GPIOA->PUPDR &= ~(0x3U << (5 * 2));
GPIOA->AFR[0] &= ~(0xFU << (5 * 4));
GPIOA->AFR[0] |= (0x1U << (5 * 4));
TIM2->CR1 = 0x0000U;
TIM2->PSC = 15;
TIM2->ARR = 999;
TIM2->CCR1 = 500;
TIM2->CCMR1 &= ~(TIM_CCMR1_OC1M | TIM_CCMR1_CC1S);
TIM2->CCMR1 |= (6U << TIM_CCMR1_OC1M_Pos);
TIM2->CCMR1 |= TIM_CCMR1_OC1PE;
TIM2->CCER &= ~TIM_CCER_CC1P;
TIM2->CCER |= TIM_CCER_CC1E;
TIM2->CR1 |= TIM_CR1_ARPE;
TIM2->EGR = TIM_EGR_UG;
TIM2->CR1 |= TIM_CR1_CEN;
/* USER CODE END 2 */
.
BR
Gyessine
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.