You don't need to call HAL_TIMEx_MasterConfigSynchronization() if you're not changing from the default (non chained/synchronized) configuration.It is automatically called when you call HAL_TIM_PWM_Init(), but you must make sure your handle variables are properly initialized (see #1 above). Don't call HAL_TIM_PWM_MspInit() manually.It is particularly maddening when the behaviour changes from compile to compile or from function call to function call as the stack memory changes. memset(&sConfigOC, 0, sizeof(sConfigOC)) Local variables are not automatically initialized and you will have unexpected/unintended configuration because the HAL makes very basic assumptions about the peripheral state based on these handle variables. Make sure you initialize (zero out) your stack-allocated structs.I'm late to the party, but I found myself in a similar situation and have the real answer, or at least the answer that I've personally verified to work with my own STM32 board and the STM32CubeMx drivers. * Initialize all configured peripherals */ * Reset of all peripherals, Initializes the Flash interface and the Systick. GPIO_InitStruct.Alternate = GPIO_AF2_TIM3 įinally my main() looks like this: (I'm calling SystemInit() from main because I'm using STCube generated files with coocox coide) int main(void) GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_8|GPIO_PIN_7|GPIO_PIN_6 The GPIO is initialized in the HAL_TIM_PWM_MspInit() function: void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* htim_pwm)
HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4) HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_3) HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2) HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) SConfigOC.OCFastMode = TIM_OCFAST_ENABLE SConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH SConfigOC.OCIdleState = TIM_OCIDLESTATE_SET HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig)
SMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE SMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET In my main() I call the Timer initialization function: /* TIM3 init function */ I'm trying to switch to the ST HAL libraries and can't seem to get the PWM to work.