2014-07-31 05:25 PM
Greetings,
I'm attempting to use stm32cubemx to configure the timers of a stm32f427ig to control a few rgb leds as open-drain, pwm outputs. I'm using timers 1,3,4,5, and 8. All of them are using channels 1 thru 3, except timers 1 and 3, which are using a 4th channel attached to a single-color auxiliary LED.The ''regular'' timers are working as-expected. However, the advanced timers, 1 and 8 aren't putting a signal out on their configured pins. So far, I've only gotten Ch 4 working on timer 1. Channels 1-3 on timers 1 and 8 simply aren't working, even through their configuration is identical to that of Ch 4 on Tim1.(As an added-bonus, STM32CubeMX seems to hang/crash often while generating code. Often losing custom code sections in main.c)I'm starting the PWM units after initialization using the following commands:HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4); HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_2); HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3); HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_2); HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_3); HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2); HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3); HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4); HAL_TIM_PWM_Start(&htim8, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim8, TIM_CHANNEL_2); HAL_TIM_PWM_Start(&htim8, TIM_CHANNEL_3);I've attached the .ioc used. Any advice as to why the advanced timers aren't working as expected would be appreciated. :)2014-07-31 06:04 PM
Any advice as to why the advanced timers aren't working as expected would be appreciated.
Probably a broken code generator, or other bug. TIM1 and TIM8 would need to have PWM Output enabled explicitly. In the old firmware library TIM_CtrlPWMOutputs(TIM1, ENABLE);2014-08-01 02:23 AM
The outputs get enabled as part of of the HAL_TIM_PWM_Start(). But, I think I've (mostly) figured it out...
The one thing channel 4 doesn't have in common with the others is that it has no complimentary output. It would seem that the TIM_CR2_CCPC bit is on by default. (In effect, a feature apparently meant for hall-sensors is holding channels 1-3 in an off state.) Disabling the feature with:htim1.Instance->CR2 &= ~(TIM_CR2_CCPC);
htim8.Instance->CR2 &= ~(TIM_CR2_CCPC);
makes the timers behave as-expected. Why that bit is enabled by default, I do not know. This is probably more of a HAL driver issue than an STM32CubeMX issue.2014-09-16 02:40 AM
Hello,
There is an issue with current STM32CubeMX 4.3.1 and earlier versions. This will be fixed in next release. As a workaround, please add the following code highlighted in red below to ensure that optional fields are initialized as well. sConfigOC.OCMode = TIM_OCMODE_PWM1;sConfigOC.Pulse = 0; sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1); Best Regards