Replace the register-level timer code in pwm_switch_driver.c by the STM32 PWM power switch driver. The duty cycle steps of the control algorithm are kept at 100 us on-time per step, independent of the timer resolution of the driver. The rising edges of the PWM signal are only reported while the switch is on. Before, the overvoltage alert of the battery voltage was also inhibited periodically while the switch was off. The PWM switch is now a child node of the timer with the label pwm_switch instead of a child of the outputs node referencing a Zephyr PWM device. The unit tests use the emulated power switch, so that the dummy PWM binding is not needed anymore. The obsolete kconfig-flag and latching-pgood properties are removed from the outputs binding. Note for out-of-tree boards: The pwm_switch child of the outputs node must be converted to a libresolar,stm32-pwm-power-switch node below the st,stm32-timers node. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
147 lines
2.6 KiB
Plaintext
147 lines
2.6 KiB
Plaintext
/*
|
|
* Copyright (c) The Libre Solar Project Contributors
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/ {
|
|
/* delete conflicting nodes from Zephyr native_sim board */
|
|
/delete-node/ leds;
|
|
/delete-node/ aliases;
|
|
|
|
pcb {
|
|
compatible = "charge-controller";
|
|
|
|
type = "Native POSIX dummy";
|
|
version-str = "v0.1";
|
|
version-num = <1>;
|
|
|
|
hs-voltage-max = <80>;
|
|
ls-voltage-max = <32>;
|
|
dcdc-current-max = <20>;
|
|
};
|
|
|
|
chosen {
|
|
zephyr,console = &uart0;
|
|
zephyr,shell-uart = &uart0;
|
|
zephyr,flash = &flash0;
|
|
};
|
|
|
|
leds {
|
|
compatible = "charlieplexing-leds";
|
|
gpios = <&gpio0 6 GPIO_ACTIVE_LOW>, /* chg red */
|
|
<&gpio0 14 GPIO_ACTIVE_LOW>, /* chg green */
|
|
<&gpio0 9 GPIO_ACTIVE_LOW>, /* dis red */
|
|
<&gpio0 15 GPIO_ACTIVE_LOW>; /* dis green */
|
|
|
|
pwr {
|
|
states = <0 1 0 0>;
|
|
};
|
|
|
|
load {
|
|
states = <0 0 0 1>;
|
|
};
|
|
};
|
|
|
|
load_switch: load-switch {
|
|
compatible = "libresolar,gpio-power-switch";
|
|
gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
|
|
current-max = <20>;
|
|
};
|
|
|
|
outputs {
|
|
compatible = "outputs";
|
|
|
|
can_en {
|
|
gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
|
|
};
|
|
};
|
|
|
|
adc1: adc1 {
|
|
compatible = "zephyr,dummy-adc";
|
|
#io-channel-cells = <1>;
|
|
};
|
|
|
|
adc-inputs {
|
|
compatible = "libresolar,daq-emul";
|
|
|
|
v-low {
|
|
io-channels = <&adc1 12>;
|
|
multiplier = <105600>;
|
|
divider = <5600>;
|
|
};
|
|
|
|
v-high {
|
|
io-channels = <&adc1 15>;
|
|
multiplier = <102200>;
|
|
divider = <2200>;
|
|
};
|
|
|
|
v-pwm {
|
|
io-channels = <&adc1 4>;
|
|
multiplier = <25224>; // (12*8.2 + 120*8.2 + 120*12) * 10
|
|
divider = <984>; // (8.2*12) * 10
|
|
offset = <37414>; // 65536 / (1 + 8.2/120 + 8.2/12)
|
|
};
|
|
|
|
temp-fets {
|
|
io-channels = <&adc1 11>;
|
|
multiplier = <10000>; // 10k NTC series resistor
|
|
divider = <1>;
|
|
};
|
|
|
|
vref-mcu {
|
|
io-channels = <&adc1 18>;
|
|
multiplier = <1>;
|
|
divider = <1>;
|
|
};
|
|
|
|
temp-mcu {
|
|
io-channels = <&adc1 16>;
|
|
multiplier = <1>;
|
|
divider = <1>;
|
|
};
|
|
|
|
i-dcdc {
|
|
io-channels = <&adc1 1>;
|
|
// amp gain: 25, resistor: 2 mOhm
|
|
multiplier = <1000>; // 1000
|
|
divider = <50>; // 2*25
|
|
};
|
|
|
|
i-load {
|
|
io-channels = <&adc1 2>;
|
|
// amp gain: 25, resistor: 2 mOhm
|
|
multiplier = <1000>; // 1000
|
|
divider = <50>; // 2*25
|
|
};
|
|
|
|
i-pwm {
|
|
io-channels = <&adc1 5>;
|
|
// amp gain: 68/2.2, resistor: 2 mOhm
|
|
multiplier = <2200>; // 1000*2.2
|
|
divider = <136>; // 2*68
|
|
};
|
|
};
|
|
|
|
halfbridge: halfbridge {
|
|
compatible = "libresolar,half-bridge-emul";
|
|
clock-frequency = <24000000>;
|
|
frequency = <70000>;
|
|
deadtime-ns = <300>;
|
|
};
|
|
|
|
pwm_switch: pwm-switch {
|
|
compatible = "libresolar,power-switch-emul";
|
|
frequency = <50>;
|
|
current-max = <20>;
|
|
};
|
|
|
|
aliases {
|
|
uart-dbg = &uart0;
|
|
uart-uext = &uart0;
|
|
// spi-uext = &spi1;
|
|
// i2c-uext = &i2c1;
|
|
};
|
|
};
|