Half bridge: New dts binding to fix pinmux
The previous approach to define the pinmux in the timer nodes didn't work because the timers don't have a pinctrl-0 property. This commit adds a new half-bridge binding similar to upstream Zephyr pwm binding, which is a child node of the used timer. It makes sense to define PWM frequency and dead-time also in this node, so the dcdc devicetree binding is redundant and therefore removed.
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@ extern LoadOutput load;
|
||||
#if BOARD_HAS_LOAD_OUTPUT
|
||||
#define DISCHARGE_CURRENT_MAX DT_PROP(DT_CHILD(DT_PATH(outputs), load), current_max)
|
||||
#else
|
||||
#define DISCHARGE_CURRENT_MAX DT_PROP(DT_PATH(dcdc), current_max)
|
||||
#define DISCHARGE_CURRENT_MAX DT_PROP(DT_PATH(pcb), dcdc_current_max)
|
||||
#endif
|
||||
|
||||
void battery_conf_init(BatConf *bat, int type, int num_cells, float nominal_capacity)
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
|
||||
#include <zephyr.h>
|
||||
|
||||
#define BOARD_HAS_DCDC DT_NODE_EXISTS(DT_PATH(dcdc))
|
||||
#define BOARD_HAS_DCDC DT_HAS_COMPAT_STATUS_OKAY(half_bridge)
|
||||
#define BOARD_HAS_PWM_PORT DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), pwm_switch))
|
||||
#define BOARD_HAS_LOAD_OUTPUT DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), load))
|
||||
#define BOARD_HAS_USB_OUTPUT DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), usb_pwr))
|
||||
|
||||
+3
-3
@@ -40,7 +40,7 @@ Dcdc::Dcdc(DcBus *high, DcBus *low, DcdcOperationMode op_mode)
|
||||
mode = op_mode;
|
||||
enable = true;
|
||||
state = DCDC_CONTROL_OFF;
|
||||
inductor_current_max = DT_PROP(DT_PATH(dcdc), current_max);
|
||||
inductor_current_max = DT_PROP(DT_PATH(pcb), dcdc_current_max);
|
||||
hs_voltage_max = DT_PROP(DT_PATH(pcb), hs_voltage_max);
|
||||
ls_voltage_max = DT_PROP(DT_PATH(pcb), ls_voltage_max);
|
||||
ls_voltage_min = 9.0;
|
||||
@@ -50,8 +50,8 @@ Dcdc::Dcdc(DcBus *high, DcBus *low, DcdcOperationMode op_mode)
|
||||
pwm_delta = 1; // start-condition of duty cycle pwr_inc_pwm_direction
|
||||
|
||||
// lower duty limit might have to be adjusted dynamically depending on LS voltage
|
||||
half_bridge_init(DT_PROP(DT_PATH(dcdc), pwm_frequency) / 1000,
|
||||
DT_PROP(DT_PATH(dcdc), pwm_deadtime), 12 / hs_voltage_max, 0.97);
|
||||
half_bridge_init(DT_PROP(DT_INST(0, half_bridge), frequency) / 1000,
|
||||
DT_PROP(DT_INST(0, half_bridge), deadtime), 12 / hs_voltage_max, 0.97);
|
||||
}
|
||||
|
||||
int Dcdc::perturb_observe_controller()
|
||||
|
||||
+10
-12
@@ -16,12 +16,15 @@
|
||||
#ifndef UNIT_TEST
|
||||
#include <soc.h>
|
||||
#include <pinmux/stm32/pinmux_stm32.h>
|
||||
|
||||
#define DT_DRV_COMPAT st_stm32_timers
|
||||
#endif
|
||||
|
||||
#if BOARD_HAS_DCDC
|
||||
|
||||
#define DT_DRV_COMPAT half_bridge
|
||||
|
||||
// Get address of used timer from board dts
|
||||
#define TIMER_ADDR DT_REG_ADDR(DT_PARENT(DT_DRV_INST(0)))
|
||||
|
||||
static uint16_t tim_ccr_min; // capture/compare register min/max
|
||||
static uint16_t tim_ccr_max;
|
||||
static uint16_t tim_dt_clocks = 0;
|
||||
@@ -42,16 +45,13 @@ static uint16_t clamp_ccr(uint16_t ccr_target)
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
|
||||
// Get address of used timer from board dts
|
||||
#define PWM_TIMER_ADDR DT_REG_ADDR(DT_PHANDLE(DT_PATH(dcdc), timer))
|
||||
static const struct soc_gpio_pinctrl tim_pinctrl[] = ST_STM32_DT_INST_PINCTRL(0, 0);
|
||||
|
||||
#if PWM_TIMER_ADDR == TIM3_BASE
|
||||
|
||||
static const struct soc_gpio_pinctrl tim_pinctrl[] = ST_STM32_DT_PINCTRL(timers3, 0);
|
||||
#if TIMER_ADDR == TIM3_BASE
|
||||
|
||||
static void tim_init_registers(int freq_kHz)
|
||||
{
|
||||
stm32_dt_pinctrl_configure(tim_pinctrl, ARRAY_SIZE(tim_pinctrl), PWM_TIMER_ADDR);
|
||||
stm32_dt_pinctrl_configure(tim_pinctrl, ARRAY_SIZE(tim_pinctrl), TIMER_ADDR);
|
||||
|
||||
// Enable TIM3 clock
|
||||
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
|
||||
@@ -124,13 +124,11 @@ bool half_bridge_enabled()
|
||||
return TIM3->CCER & TIM_CCER_CC3E;
|
||||
}
|
||||
|
||||
#elif PWM_TIMER_ADDR == TIM1_BASE
|
||||
|
||||
static const struct soc_gpio_pinctrl tim_pinctrl[] = ST_STM32_DT_PINCTRL(timers1, 0);
|
||||
#elif TIMER_ADDR == TIM1_BASE
|
||||
|
||||
static void tim_init_registers(int freq_kHz)
|
||||
{
|
||||
stm32_dt_pinctrl_configure(tim_pinctrl, ARRAY_SIZE(tim_pinctrl), PWM_TIMER_ADDR);
|
||||
stm32_dt_pinctrl_configure(tim_pinctrl, ARRAY_SIZE(tim_pinctrl), TIMER_ADDR);
|
||||
|
||||
// Enable TIM1 clock
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
|
||||
|
||||
Reference in New Issue
Block a user