2024-12-24 10:44 AM
I want to generate 6 PWMs using channel 1 of timers 1,8,2,3,4,5. All of them are set the same way except ARR, PSC and CCR1 registers. However, it turned out that timers 2 and 3 don't have PWM signal on their pins. The content of registers for those timers are the same (checked during debugging). I also tried to initialize timers by writing directly to registers, with no luck. MCU: STM32F103RCT6. Here is the the initialization for timer 3, for example:
// ------------------------- PA6 settings ------------------------- //
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN; // Port A clock (PA6 - TIM3_CH1)
GPIOA->CRL |= GPIO_CRL_MODE6; // PA6 speed MAX
GPIOA->CRL &= ~GPIO_CRL_CNF6_0; // Alternate function Push-Pull
GPIOA->CRL |= GPIO_CRL_CNF6_1;
// ------------------------- TIM3 settings ------------------------- //
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; // TIM3 clock
TIM3->CCMR1 &= ~TIM_CCMR1_OC1M_0; // PWM mode 1
TIM3->CCMR1 |= TIM_CCMR1_OC1M_1;
TIM3->CCMR1 |= TIM_CCMR1_OC1M_2;
TIM3->CCMR1 |= TIM_CCMR1_OC1PE; // enable preload register
TIM3->CR1 |= TIM_CR1_ARPE; // enable auto-reload preload register
TIM3->EGR |= TIM_EGR_UG; // generate an update
TIM3->CCER &= ~TIM_CCER_CC1P; // polarity: active HIGH
TIM3->CCER |= TIM_CCER_CC1E; // Output signal enable
TIM3->ARR = 11999; // period
TIM3->CCR1 = 5999; // pulse %
TIM3->PSC = 1; // prescaler
TIM3->CR1 |= TIM_CR1_CEN; // PWM on
I tried another STM32F103RCT6, but behaviour is the same. Is that hardware issue inside the MCU?
2024-12-25 01:53 AM
Hello @Dan_Ko, welcome to ST community,
The issue could be that it's needed to remap the alternate function by software to different port pins, because by default PA6 for example is connected to TIM8_BKIN/ADC12_IN6
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.
2024-12-25 10:26 AM - edited 2024-12-25 10:27 AM
Hello Sarra,
If I set up TIM3 using CubeMX, should not it be remapped by default?