2015-08-27 02:11 PM
I'm trying to setup one of the LEDs on the STM3210E-EVAL board as a PWM output so that I can vary the brightness. I am targeting the red LED, which is on port F, pin 8. I have setup timer 13 which should be tied to that pin for PWM output, but I feel like like I am missing a step somewhere. Here is the current function to initialize the pin, setup the timer, and setup the PWM:
void led_init(void)
{
TIM_OC_InitTypeDef sConfigOC;
TIM_HandleTypeDef htim13;
/*Configure GPIO pins : PF8 */
__HAL_AFIO_REMAP_TIM13_ENABLE();
__GPIOF_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
htimInstance = TIM13;
htimInit.Prescaler = (uint32_t)(72000000 / 2000000) - 1;
htimInit.CounterMode = TIM_COUNTERMODE_UP;
htimInit.Period = 700;
htimInit.ClockDivision = TIM_CLOCKDIVISION_DIV1;
HAL_TIM_Base_Init(&htim13);
HAL_TIM_PWM_Init(&htim13);
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 350;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
HAL_TIM_PWM_ConfigChannel(&htim13, &sConfigOC, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim13, TIM_CHANNEL_1);
}
Any advice would be greatly appreciated!
Thank you!
#stm32f103 #stm3120e-eval
2015-08-31 02:57 AM
Hi DWORD32,
The STM3210E-EVAL products are based on the STM32F103ZET6 or on the STM32F103ZGT6.Can you please precise on which device is based your board?Because if you are using STM32F103ZET6, it doesn’t embed TIM13.-Syrine-2015-08-31 06:55 AM
Hi Syrine,
The part number listed on the processor is: STM32F103ZGT6Regards.2015-11-02 04:47 AM
I have the same Problem. I used the PWM example and it works for the Pins PA0 to PA4 with timer 2. But there is no PWM on Pins PF8 if I change to Timer 13. Do I need to remap the Pin? How can I do that?
Thanks for any help! :) regards Max2015-11-02 05:50 AM
Yes, you'll need to Remap the pin (TIM13 Remap Enable, per example above). You'd need to make sure the AFIO and GPIOF clocks are enabled first.
With these METOO type questions please confirm if you are using exactly the same part, and HAL or SPL libraries.