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:
Martin Jäger
2021-02-04 17:28:52 +01:00
parent 4eaf89154a
commit 2de110b0b7
15 changed files with 100 additions and 92 deletions
+8 -9
View File
@@ -21,14 +21,7 @@
hs-voltage-max = <40>;
ls-voltage-max = <16>;
};
dcdc {
compatible = "dcdc";
timer = <&timers3>;
pwm-frequency = <50000>;
pwm-deadtime = <230>;
current-max = <10>;
dcdc-current-max = <10>;
};
chosen {
@@ -186,7 +179,13 @@
&timers3 {
status = "okay";
pinctrl-0 = <&tim3_ch3_pb0 &tim3_ch4_pb1>;
halfbridge {
compatible = "half-bridge";
pinctrl-0 = <&tim3_ch3_pb0 &tim3_ch4_pb1>;
frequency = <50000>;
deadtime = <230>;
};
};
&eeprom {
+8 -9
View File
@@ -21,14 +21,7 @@
hs-voltage-max = <80>;
ls-voltage-max = <32>;
};
dcdc {
compatible = "dcdc";
timer = <&timers1>;
pwm-frequency = <70000>;
pwm-deadtime = <300>;
current-max = <20>;
dcdc-current-max = <20>;
};
chosen {
@@ -184,7 +177,13 @@
&timers1 {
status = "okay";
pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>;
halfbridge {
compatible = "half-bridge";
pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>;
frequency = <70000>;
deadtime = <300>;
};
};
/* TIM8 (CH2) used for charge pump */
+8 -9
View File
@@ -21,14 +21,7 @@
hs-voltage-max = <80>;
ls-voltage-max = <32>;
};
dcdc {
compatible = "dcdc";
timer = <&timers1>;
pwm-frequency = <70000>;
pwm-deadtime = <300>;
current-max = <20>;
dcdc-current-max = <20>;
};
chosen {
@@ -202,7 +195,13 @@
&timers1 {
status = "okay";
pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>;
halfbridge {
compatible = "half-bridge";
pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>;
frequency = <70000>;
deadtime = <300>;
};
};
/* TIM3 (CH2) used for PWM power switch */
+8 -9
View File
@@ -21,14 +21,7 @@
hs-voltage-max = <55>;
ls-voltage-max = <32>;
};
dcdc {
compatible = "dcdc";
timer = <&timers1>;
pwm-frequency = <70000>;
pwm-deadtime = <300>;
current-max = <20>;
dcdc-current-max = <20>;
};
chosen {
@@ -201,7 +194,13 @@
&timers1 {
status = "okay";
pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>;
halfbridge {
compatible = "half-bridge";
pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>;
frequency = <70000>;
deadtime = <300>;
};
};
&can1 {
+8 -9
View File
@@ -21,14 +21,7 @@
hs-voltage-max = <80>;
ls-voltage-max = <32>;
};
dcdc {
compatible = "dcdc";
timer = <&timers1>;
pwm-frequency = <70000>;
pwm-deadtime = <300>;
current-max = <20>;
dcdc-current-max = <20>;
};
chosen {
@@ -142,7 +135,13 @@
&timers1 {
status = "okay";
pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>;
halfbridge {
compatible = "half-bridge";
pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>;
frequency = <70000>;
deadtime = <300>;
};
};
&flash0 {
+1 -1
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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;
+5
View File
@@ -39,8 +39,13 @@
#define DT_PROP_BY_PHANDLE(node_id, ph, prop) \
DT_PROP_BY_PHANDLE_IDX(node_id, ph, 0, prop)
#define DT_HAS_COMPAT_STATUS_OKAY(compat) \
IS_ENABLED(DT_CAT(DT_COMPAT_HAS_OKAY_, compat))
/*
* Simplified mocks for certain macros from devicetree.h
*/
#define DT_INST(inst, compat) UTIL_CAT(DT_N_INST_, UTIL_CAT(inst, UTIL_CAT(_, compat)))
#define DT_PATH(node) UTIL_CAT(DT_N_S_, node)
+7 -4
View File
@@ -18,10 +18,13 @@
#define DT_N_S_pcb_P_mosfets_tj_max 120
#define DT_N_S_pcb_P_mosfets_tau_ja 5
#define DT_N_S_dcdc_EXISTS 1
#define DT_N_S_dcdc_P_pwm_frequency 70000
#define DT_N_S_dcdc_P_pwm_deadtime 300
#define DT_N_S_dcdc_P_current_max 20
#define DT_N_S_pcb_P_dcdc_current_max 20
#define DT_N_S_pcb_P_dcdc_current_max_EXISTS 1
#define DT_COMPAT_HAS_OKAY_half_bridge 1
#define DT_N_INST_0_half_bridge DT_N_S_soc_S_timers_40016800_S_halfbridge
#define DT_N_S_soc_S_timers_40016800_S_halfbridge_P_frequency 70000
#define DT_N_S_soc_S_timers_40016800_S_halfbridge_P_deadtime 300
#define DT_N_S_outputs_S_pwm_switch_EXISTS 1
#define DT_N_S_outputs_S_pwm_switch_P_current_max 20
+2 -2
View File
@@ -37,7 +37,7 @@ menu "Charge Controller Setup"
choice
prompt "High-voltage terminal"
depends on $(dt_compat_enabled,dcdc)
depends on $(dt_compat_enabled,half-bridge)
help
Select the device connected to the high-voltage
side terminal of the DC/DC converter.
@@ -443,7 +443,7 @@ config CUSTOM_DATA_NODES_FILE
config CUSTOM_DCDC_CONTROLLER
bool "Custom implementation of DC/DC controller"
depends on $(dt_compat_enabled,dcdc)
depends on $(dt_compat_enabled,half-bridge)
default n
help
Use a custom implementation instead of the default perturb & observe
@@ -26,6 +26,9 @@ properties:
type: int
required: true
description: Maximum voltage at low-side (typically battery) in volts
dcdc-current-max:
type: int
description: Maximum inductor current in amps (if existing in the charge controller)
internal-tref-max:
type: int
default: 50
-24
View File
@@ -1,24 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2020 Martin Jäger / Libre Solar
description: DC/DC converter as part of MPPT charge controllers
compatible: "dcdc"
properties:
timer:
type: phandle
required: true
description: Timer used for PWM signal generation
pwm-frequency:
type: int
required: true
description: PWM frequency in Hz
pwm-deadtime:
type: int
required: true
description: Dead time for synchronous PWM generation in nanoseconds
current-max:
type: int
required: true
description: Maximum inductor current in amps
+28
View File
@@ -0,0 +1,28 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2021 Martin Jäger / Libre Solar
description: Half bridge, consisting of two coupled PWM outputs
compatible: "half-bridge"
include: base.yaml
properties:
frequency:
type: int
required: true
description: PWM frequency in Hz
deadtime:
type: int
required: true
description: Dead time for synchronous PWM generation in nanoseconds
pinctrl-0:
type: phandles
required: false
description: |
GPIO pin configuration for PWM signal/s. We expect that the phandles
will reference pinctrl nodes, e.g.
pinctrl-0 = <&tim1_ch1_pwm_pa8 &tim1_ch2_pwm_pa9>;