diff --git a/arch/arm/src/stm32/Kconfig b/arch/arm/src/stm32/Kconfig index 141058ece8..02441b567d 100644 --- a/arch/arm/src/stm32/Kconfig +++ b/arch/arm/src/stm32/Kconfig @@ -2195,7 +2195,7 @@ config STM32_COMP6 config STM32_COMP7 bool "COMP7" default n - depends on STM32_HAVE_COMP6 + depends on STM32_HAVE_COMP7 config STM32_BKP bool "BKP" @@ -5864,6 +5864,11 @@ config STM32_HRTIM_DEADTIME depends on STM32_HRTIM_PWM default n +config STM32_HRTIM_PUSHPULL + bool "HRTIM push-pull mode" + depends on STM32_HRTIM_PWM + default n + config STM32_HRTIM_DMA bool "HRTIM DMA" default n @@ -6041,6 +6046,11 @@ config STM32_HRTIM_TIMA_DT default n depends on (STM32_HRTIM_DEADTIME && STM32_HRTIM_TIMA_PWM) +config STM32_HRTIM_TIMA_PSHPLL + bool "HRTIM TIMA PWM Push-pull mode" + default n + depends on (STM32_HRTIM_PUSHPULL && STM32_HRTIM_TIMA_PWM) + endmenu # "HRTIM Timer A Configuration" menu "HRTIM Timer B Configuration" @@ -6106,6 +6116,11 @@ config STM32_HRTIM_TIMB_DT default n depends on (STM32_HRTIM_DEADTIME && STM32_HRTIM_TIMB_PWM) +config STM32_HRTIM_TIMB_PSHPLL + bool "HRTIM TIMB PWM Push-pull mode" + default n + depends on (STM32_HRTIM_PUSHPULL && STM32_HRTIM_TIMB_PWM) + endmenu # "HRTIM Timer B Configuration" menu "HRTIM Timer C Configuration" @@ -6171,6 +6186,11 @@ config STM32_HRTIM_TIMC_DT default n depends on (STM32_HRTIM_DEADTIME && STM32_HRTIM_TIMC_PWM) +config STM32_HRTIM_TIMC_PSHPLL + bool "HRTIM TIMC PWM Push-pull mode" + default n + depends on (STM32_HRTIM_PUSHPULL && STM32_HRTIM_TIMC_PWM) + endmenu # "HRTIM Timer C Configuration" menu "HRTIM Timer D Configuration" @@ -6236,6 +6256,11 @@ config STM32_HRTIM_TIMD_DT default n depends on (STM32_HRTIM_DEADTIME && STM32_HRTIM_TIMD_PWM) +config STM32_HRTIM_TIMD_PSHPLL + bool "HRTIM TIMD PWM Push-pull mode" + default n + depends on (STM32_HRTIM_PUSHPULL && STM32_HRTIM_TIMD_PWM) + endmenu # "HRTIM Timer D Configuration" menu "HRTIM Timer E Configuration" @@ -6301,6 +6326,11 @@ config STM32_HRTIM_TIME_DT default n depends on (STM32_HRTIM_DEADTIME && STM32_HRTIM_TIME_PWM) +config STM32_HRTIM_TIME_PSHPLL + bool "HRTIM TIME PWM Push-pull mode" + default n + depends on (STM32_HRTIM_PUSHPULL && STM32_HRTIM_TIME_PWM) + endmenu # "HRTIM Timer E Configuration" endif # STM32_HRTIM1 diff --git a/arch/arm/src/stm32/stm32_hrtim.c b/arch/arm/src/stm32/stm32_hrtim.c index 121b0e2e4f..af1c032c38 100644 --- a/arch/arm/src/stm32/stm32_hrtim.c +++ b/arch/arm/src/stm32/stm32_hrtim.c @@ -180,6 +180,29 @@ # error "CONFIG_STM32_HRTIM_CHOPPER must be set" # endif #endif +#if defined(CONFIG_STM32_HRTIM_TIMA_PSHPLL) || defined(CONFIG_STM32_HRTIM_TIMB_PSHPLL) || \ + defined(CONFIG_STM32_HRTIM_TIMC_PSHPLL) || defined(CONFIG_STM32_HRTIM_TIMD_PSHPLL) || \ + defined(CONFIG_STM32_HRTIM_TIME_PSHPLL) +# ifndef CONFIG_STM32_HRTIM_PUSHPULL +# error "CONFIG_STM32_HRTIM_PUSHPULL must be set" +# endif +#endif + +#if defined(CONFIG_STM32_HRTIM_TIMA_DT) && defined(CONFIG_STM32_HRTIM_TIMA_PSHPLL) +# error "The deadtime cannot be used simultaneously with the push-pull mode" +#endif +#if defined(CONFIG_STM32_HRTIM_TIMB_DT) && defined(CONFIG_STM32_HRTIM_TIMB_PSHPLL) +# error "The deadtime cannot be used simultaneously with the push-pull mode" +#endif +#if defined(CONFIG_STM32_HRTIM_TIMC_DT) && defined(CONFIG_STM32_HRTIM_TIMC_PSHPLL) +# error "The deadtime cannot be used simultaneously with the push-pull mode" +#endif +#if defined(CONFIG_STM32_HRTIM_TIMD_DT) && defined(CONFIG_STM32_HRTIM_TIMD_PSHPLL) +# error "The deadtime cannot be used simultaneously with the push-pull mode" +#endif +#if defined(CONFIG_STM32_HRTIM_TIME_DT) && defined(CONFIG_STM32_HRTIM_TIME_PSHPLL) +# error "The deadtime cannot be used simultaneously with the push-pull mode" +#endif #if defined(CONFIG_STM32_HRTIM_ADC1_TRG1) || defined(CONFIG_STM32_HRTIM_ADC1_TRG2) || \ defined(CONFIG_STM32_HRTIM_ADC1_TRG3) || defined(CONFIG_STM32_HRTIM_ADC1_TRG4) || \ @@ -305,7 +328,7 @@ struct stm32_hrtim_timout_s #ifdef CONFIG_STM32_HRTIM_CHOPPER struct stm32_hrtim_chopper_s { - uint16_t start:4; /* Chopper start pulsewidth */ + uint16_t start_pulse:4; /* Chopper start pulsewidth */ uint16_t freq:4; /* Chopper carrier frequency value */ uint16_t duty:3; /* Chopper duty cycle */ uint16_t _res:5; /* Reserved */ @@ -345,6 +368,8 @@ struct stm32_hrtim_tim_burst_s struct stm32_hrtim_pwm_s { + uint8_t pushpull:1; + uint8_t res:7; struct stm32_hrtim_timout_s ch1; /* Channel 1 Set/Reset configuration*/ struct stm32_hrtim_timout_s ch2; /* Channel 2 Set/Reset configuration */ @@ -786,6 +811,9 @@ static struct stm32_hrtim_slave_priv_s g_tima_priv = #ifdef CONFIG_STM32_HRTIM_TIMA_PWM .pwm = { +#ifdef CONFIG_STM32_HRTIM_TIMA_PSHPLL + .pushpull = 1, +#endif #ifdef CONFIG_STM32_HRTIM_TIMA_PWM_CH1 .ch1 = { @@ -883,6 +911,9 @@ static struct stm32_hrtim_slave_priv_s g_timb_priv = #ifdef CONFIG_STM32_HRTIM_TIMB_PWM .pwm = { +#ifdef CONFIG_STM32_HRTIM_TIMB_PSHPLL + .pushpull = 1, +#endif #ifdef CONFIG_STM32_HRTIM_TIMB_PWM_CH1 .ch1 = { @@ -980,6 +1011,9 @@ static struct stm32_hrtim_slave_priv_s g_timc_priv = #ifdef CONFIG_STM32_HRTIM_TIMC_PWM .pwm = { +#ifdef CONFIG_STM32_HRTIM_TIMC_PSHPLL + .pushpull = 1, +#endif #ifdef CONFIG_STM32_HRTIM_TIMC_PWM_CH1 .ch1 = { @@ -1077,6 +1111,9 @@ static struct stm32_hrtim_slave_priv_s g_timd_priv = #ifdef CONFIG_STM32_HRTIM_TIMD_PWM .pwm = { +#ifdef CONFIG_STM32_HRTIM_TIMD_PSHPLL + .pushpull = 1, +#endif #ifdef CONFIG_STM32_HRTIM_TIMD_PWM_CH1 .ch1 = { @@ -1174,6 +1211,9 @@ static struct stm32_hrtim_slave_priv_s g_time_priv = #ifdef CONFIG_STM32_HRTIM_TIME_PWM .pwm = { +#ifdef CONFIG_STM32_HRTIM_TIME_PSHPLL + .pushpull = 1, +#endif #ifdef CONFIG_STM32_HRTIM_TIME_PWM_CH1 .ch1 = { @@ -1518,7 +1558,7 @@ static const struct stm32_hrtim_ops_s g_hrtim1ops = .burst_pre_get = hrtim_burst_pre_get, #endif #ifdef CONFIG_STM32_HRTIM_CHOPPER - .chopper_enable = hrtim_chopper_enable + .chopper_enable = hrtim_chopper_enable, #endif #ifdef CONFIG_STM32_HRTIM_DEADTIME .deadtime_update = hrtim_deadtime_update, @@ -2808,6 +2848,15 @@ static int hrtim_tim_outputs_config(FAR struct stm32_hrtim_s *priv, uint8_t time } #endif +#ifdef CONFIG_STM32_HRTIM_PUSHPULL + if (slave->pwm.pushpull == 1) + { + /* Enable push-pull mode */ + + hrtim_tim_modifyreg(priv, timer, STM32_HRTIM_TIM_CR_OFFSET, 0, HRTIM_TIMCR_PSHPLL); + } +#endif + errout: return ret; } @@ -3640,13 +3689,13 @@ static int hrtim_chopper_enable(FAR struct hrtim_dev_s *dev, uint8_t timer, { /* Set enable bit */ - hrtim_tim_modifyreg(priv, index, STM32_HRTIM_TIM_OUTR_OFFSET, 0, val); + hrtim_tim_modifyreg(priv, timer, STM32_HRTIM_TIM_OUTR_OFFSET, 0, val); } else { /* Clear enable bit */ - hrtim_tim_modifyreg(priv, index, STM32_HRTIM_TIM_OUTR_OFFSET, val, 0); + hrtim_tim_modifyreg(priv, timer, STM32_HRTIM_TIM_OUTR_OFFSET, val, 0); } errout: @@ -3698,6 +3747,7 @@ static int hrtim_tim_chopper_cfg(FAR struct stm32_hrtim_s *priv, hrtim_tim_putreg(priv, timer, STM32_HRTIM_TIM_CHPR_OFFSET, regval); +errout: return OK; } @@ -4511,13 +4561,6 @@ static void hrtim_tim_mode_set(FAR struct stm32_hrtim_s *priv, uint8_t timer, regval |= HRTIM_CMNCR_CONT; } - /* Configure push-pull mode. Only Slaves */ - - if (mode & HRTIM_MODE_PSHPLL && timer != HRTIM_TIMER_MASTER) - { - regval |= HRTIM_TIMCR_PSHPLL; - } - /* Write register */ hrtim_tim_putreg(priv, timer, STM32_HRTIM_TIM_CR_OFFSET, regval); diff --git a/arch/arm/src/stm32/stm32_hrtim.h b/arch/arm/src/stm32/stm32_hrtim.h index da02364460..ee021a9d82 100644 --- a/arch/arm/src/stm32/stm32_hrtim.h +++ b/arch/arm/src/stm32/stm32_hrtim.h @@ -415,10 +415,6 @@ enum stm32_hrtim_mode_e HRTIM_MODE_HALF = (1 << 1), /* Half mode */ HRTIM_MODE_RETRIG = (1 << 2), /* Re-triggerable mode */ HRTIM_MODE_CONT = (1 << 3), /* Continuous mode */ - - /* Only slave Timers */ - - HRTIM_MODE_PSHPLL = (1 << 7), /* Push-Pull mode */ }; /* HRTIM Slave Timer auto-delayed mode diff --git a/configs/stm32f334-disco/src/stm32_smps.c b/configs/stm32f334-disco/src/stm32_smps.c index b1ae43e216..12f85667b1 100644 --- a/configs/stm32f334-disco/src/stm32_smps.c +++ b/configs/stm32f334-disco/src/stm32_smps.c @@ -748,7 +748,6 @@ static void smps_duty_set(struct smps_priv_s *priv, struct smps_lower_dev_s *low { per = HRTIM_PER_GET(hrtim, HRTIM_TIMER_TIMA); - if (out < priv->v_in) out = priv->v_in; if (out >= BOOST_VOLT_MAX) out = BOOST_VOLT_MAX; @@ -767,9 +766,24 @@ static void smps_duty_set(struct smps_priv_s *priv, struct smps_lower_dev_s *low case CONVERTER_MODE_BUCKBOOST: { - /* do something */ + /* Buck converter is set to fixed duty cycle (80%). + * Now we need set boost converter + */ -#warning TODO: buck boost mode + per = HRTIM_PER_GET(hrtim, HRTIM_TIMER_TIMA); + + if (out < priv->v_in) out = priv->v_in; + if (out >= BOOST_VOLT_MAX) out = BOOST_VOLT_MAX; + + duty = 1.0 - priv->v_in/out; + +#warning TODO: current limit in buck boost mode + + cmp = (uint16_t)(per * duty); + + /* Set T12 duty cycle. T5 is complementary to T12 */ + + HRTIM_CMP_SET(hrtim, HRTIM_TIMER_TIMB, HRTIM_CMP1, cmp); break; } @@ -857,6 +871,12 @@ static void smps_conv_mode_set(struct smps_priv_s *priv, struct smps_lower_dev_s HRTIM_OUTPUT_SET_SET(hrtim, HRTIM_OUT_TIMB_CH1, HRTIM_OUT_SET_PER); HRTIM_OUTPUT_RST_SET(hrtim, HRTIM_OUT_TIMB_CH1, HRTIM_OUT_RST_CMP1); + /* Set fixed duty cycle (80%) on buck converter (T4 and T11) */ + + HRTIM_CMP_SET(hrtim, HRTIM_TIMER_TIMA, HRTIM_CMP1, + 0.8 * ((uint16_t)HRTIM_PER_GET(hrtim, HRTIM_TIMER_TIMA))); + + break; }