From 1407b35ce87f9db931075f8193f8faef4891b912 Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Mon, 29 Aug 2016 12:10:44 +0200 Subject: [PATCH] pwm master config moved --- .../stm32f4-discovery/include/stm32f4-discovery.h | 15 +++++++++++++++ .../arch/stm32f4xx/driver/include/stm32f4_pwm.h | 1 + .../firmware/arch/stm32f4xx/driver/stm32f4_pwm.c | 5 +---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/source/firmware/arch/stm32f4xx/board/stm32f4-discovery/include/stm32f4-discovery.h b/source/firmware/arch/stm32f4xx/board/stm32f4-discovery/include/stm32f4-discovery.h index 32fe8bb..6487b3e 100755 --- a/source/firmware/arch/stm32f4xx/board/stm32f4-discovery/include/stm32f4-discovery.h +++ b/source/firmware/arch/stm32f4xx/board/stm32f4-discovery/include/stm32f4-discovery.h @@ -172,6 +172,11 @@ static TIM_OC_InitTypeDef t4_output_compare_cfg = { .OCNIdleState = TIM_OCNIDLESTATE_SET }; +static TIM_MasterConfigTypeDef t4_master_cfg = { + .MasterOutputTrigger = TIM_TRGO_RESET, + .MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE, +}; + static const GPIO_InitTypeDef port_cfg_D15 = { .Pin = GPIO_PIN_15, .Mode = GPIO_MODE_AF_PP, @@ -189,6 +194,7 @@ static struct stm32f4_pwm str32f4_pwm_4 = { .pwm_gpio = &t4c4_gpio, .timer_handle = &tim4_handle, .output_compare_cfg = &t4_output_compare_cfg, + .master_cfg = &t4_master_cfg, .channel = TIM_CHANNEL_4, }; @@ -223,6 +229,7 @@ static struct stm32f4_pwm str32f4_pwm_3 = { .pwm_gpio = &stm32f4_pwm_t4c3_gpio, .timer_handle = &tim4_handle, .output_compare_cfg = &t4_output_compare_cfg, + .master_cfg = &t4_master_cfg, .channel = TIM_CHANNEL_3, }; @@ -257,6 +264,7 @@ static struct stm32f4_pwm str32f4_pwm_2 = { .pwm_gpio = &stm32f4_pwm_t4c2_gpio, .timer_handle = &tim4_handle, .output_compare_cfg = &t4_output_compare_cfg, + .master_cfg = &t4_master_cfg, .channel = TIM_CHANNEL_2, }; @@ -291,6 +299,7 @@ static struct stm32f4_pwm str32f4_pwm_1 = { .pwm_gpio = &stm32f4_pwm_t4c1_gpio, .timer_handle = &tim4_handle, .output_compare_cfg = &t4_output_compare_cfg, + .master_cfg = &t4_master_cfg, .channel = TIM_CHANNEL_1, }; @@ -331,6 +340,11 @@ static TIM_OC_InitTypeDef t5_output_compare_cfg = { .OCNIdleState = TIM_OCNIDLESTATE_SET }; +static TIM_MasterConfigTypeDef t5_master_cfg = { + .MasterOutputTrigger = TIM_TRGO_RESET, + .MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE, +}; + static const GPIO_InitTypeDef port_cfg_A1 = { .Pin = GPIO_PIN_1, .Mode = GPIO_MODE_AF_PP, @@ -348,6 +362,7 @@ static struct stm32f4_pwm str32f4_pwm5_c2 = { .pwm_gpio = &t5c2_gpio, .timer_handle = &tim5_handle, .output_compare_cfg = &t5_output_compare_cfg, + .master_cfg = &t5_master_cfg, .channel = TIM_CHANNEL_2, }; diff --git a/source/firmware/arch/stm32f4xx/driver/include/stm32f4_pwm.h b/source/firmware/arch/stm32f4xx/driver/include/stm32f4_pwm.h index 709c838..cff1216 100644 --- a/source/firmware/arch/stm32f4xx/driver/include/stm32f4_pwm.h +++ b/source/firmware/arch/stm32f4xx/driver/include/stm32f4_pwm.h @@ -14,6 +14,7 @@ struct stm32f4_pwm { const struct stm32f4_gpio *pwm_gpio; TIM_HandleTypeDef *timer_handle; TIM_OC_InitTypeDef *output_compare_cfg; + TIM_MasterConfigTypeDef *master_cfg; uint32_t channel; }; #pragma pack(pop) diff --git a/source/firmware/arch/stm32f4xx/driver/stm32f4_pwm.c b/source/firmware/arch/stm32f4xx/driver/stm32f4_pwm.c index 580c5cb..e51dd99 100644 --- a/source/firmware/arch/stm32f4xx/driver/stm32f4_pwm.c +++ b/source/firmware/arch/stm32f4xx/driver/stm32f4_pwm.c @@ -30,10 +30,7 @@ int stm32f4_pwm_open(const void *pwm) HAL_TIM_PWM_Init(this->timer_handle); HAL_TIM_PWM_ConfigChannel(this->timer_handle, this->output_compare_cfg, this->channel); - TIM_MasterConfigTypeDef sMasterConfig; - sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; - sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; - HAL_TIMEx_MasterConfigSynchronization(this->timer_handle, &sMasterConfig); + HAL_TIMEx_MasterConfigSynchronization(this->timer_handle, this->master_cfg); TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig; sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;