The Dcdc class becomes struct dcdc with prefixed functions. Private
member functions become static functions. dcdc_check_start_conditions()
and dcdc_control() are still weak, so they can be overridden by custom
implementations.
The constructor is replaced by dcdc_init(), which is called from a
SYS_INIT hook at application level in setup.cpp. This corresponds to the
time the global C++ objects were constructed before, so the unit tests
(which don't run main()) still get initialized objects. The remaining
objects will be moved to this hook when they are converted.
The global device status is declared in device_status.h instead of
setup.h, so that C modules don't need to include the C++ setup header.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DeviceStatus becomes struct device_status with prefixed functions. The
error flag helpers are static inline functions in the header.
The implementation stays in C++ for now, as it reads data from objects
which are not converted yet. The header doesn't include the headers of
these objects anymore.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DcBus and PowerPort become struct dc_bus and struct power_port with
prefixed functions instead of member functions.
The default member initializers are replaced by dc_bus_init() and
power_port_init(). The only non-zero default value is the series
multiplier of the bus, which is set to 1 by dc_bus_init() and in the
static initializers of the global buses.
The optional voltage parameter of the control voltage functions has to
be passed explicitly now, 0 still selects the voltage intercept of the
bus.
LoadOutput and PwmSwitch still inherit from the C struct until they are
converted, and initialize it with power_port_init().
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the design for the devicetree power model (step 2 of the migration
plan) and an intermediate step 1b converting the application from C++
to C, so that the power model can be implemented in C with static
initializers generated from the devicetree.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The STM32 bootloader entry function as well as the flash size and page
size variables were only used by ThingSet items of the DFU group, which
were removed with the switch to the ThingSet SDK. The unused code is
removed together with mcu.h and the obsolete HW_LOG_LEVEL option.
The USB-C dead battery pull-downs of the STM32G4 are already disabled by
the Zephyr SoC initialization if USB device support is not enabled, so
the register access in setup() is not necessary anymore.
The DC/DC duty cycle step size depending on the SoC series is moved from
the code to the new Kconfig option DCDC_DUTY_STEP_SIZE with the same
defaults.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the temperature calculation in daq.cpp by the DAQ NTC sensor
driver. Temperatures below -50 °C are still considered as a missing
sensor. A missing MOSFET temperature sensor keeps the previous value
instead of setting an implausible temperature.
The series resistor of the NTCs was specified as multiplier of the DAQ
channels before. It is moved to the pullup-ohm property of the new
ntc-fets and ntc-bat nodes and the gain of the DAQ channels is set to 1.
Note for out-of-tree boards: The temp-fets and temp-bat DAQ channels need
the labels daq_temp_fets and daq_temp_bat and a corresponding
libresolar,daq-ntc-thermistor node with the labels ntc_fets and ntc_bat.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
Extend the power switch API for switches driven by a PWM signal, as used
in PWM solar charge controllers:
- Set and get the duty cycle
- Check if the switch is currently conducting (momentary PWM state)
- Generic event callback replacing the fault callback, which also
reports the rising edges of the PWM signal
New backends:
- libresolar,stm32-pwm-power-switch: PWM signal generated by a channel
of an STM32 timer. The output is driven inactive while switched off
instead of disabling the channel, which left the pin floating.
- libresolar,power-switch-emul: Emulated switch for tests on native_sim
supporting all features of the API. Power-good failures and events
can be injected by the test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the function pointers for the load and USB switches by power
switch devices. The register-level code for the short-circuit comparator
of the PWM 2420 LUS moved to the STM32 LPTIM power switch driver, which
reports short circuits via the fault callback. load_driver.c is removed.
The load and USB switches are now standalone devicetree nodes with the
labels load_switch and usb_switch instead of children of the outputs
node. The separate charge_pump node is replaced by the charge-pump-pwms
property of the load switch.
The comparator interrupt now only clears its own EXTI pending flag
instead of all pending flags.
Note for out-of-tree boards and overlays: The load and usb-pwr children
of the outputs node must be converted to nodes with the compatible
libresolar,gpio-power-switch and the labels load_switch and usb_switch.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Enable NVS in flash for the ThingSet storage. As the STM32G0B1 doesn't
have an RNG, a timer-based number generator is used for the automatic
CAN node address assignment of ThingSet.
The board is added to the firmware build tests, as it is supported by
the DAQ driver now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the register-level ADC, DAC and DMA handling in daq_driver.c by
the new DAQ driver. The application only maps the measurements to the
power ports and DC buses and handles the alerts. The factory calibration
values are removed from mcu.h, as they are provided by the driver now.
All boards are migrated to the new libresolar,stm32-daq compatible. The
unit tests use the emulated DAQ.
The high-side overvoltage limit is now set after the DAQ setup. Before,
the limit was calculated before any reading of the internal reference
voltage was available, so that the alert never triggered on boards
without fixed reference voltage (STM32F0 and STM32L0).
Note for out-of-tree boards: The adc-inputs node must use the compatible
libresolar,stm32-daq instead of adc-inputs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the oled-display-library module by the upstream Zephyr
solomon,ssd1306 display driver and the character framebuffer (CFB)
subsystem, so that the external module can be removed from the
manifest.
- A new uext_oled shield adds the display to the UEXT I2C bus, which
gets a uext_i2c node label in all boards. The display is enabled
with -DSHIELD=uext_oled instead of CONFIG_UEXT_OLED_DISPLAY=y.
- The display uses deferred init, so the application can power the
UEXT port via the uext_en GPIO before initializing it.
- The classic Adafruit 5x7 font is ported to a CFB font to keep the
screen layout unchanged. The Libre Solar logo is shown for 2 seconds
after startup.
- CONFIG_UEXT_OLED_BRIGHTNESS is replaced by
CONFIG_SSD1306_DEFAULT_CONTRAST.
- The heap is enlarged for the CFB frame buffer.
- oled.cpp is fixed for boards with PWM port or without load output
and is only built if the display is enabled.
- A build-only twister scenario with the shield is added.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a build-only twister scenario for the application covering all
boards including non-default revisions, which were not built in CI so
far (e.g. the build for mppt_2420_hc@0.1.0 was broken unnoticed).
Additional boards or revisions only need to be added to app/sample.yaml.
The firmware can be built for all boards locally with:
west twister -T app --integration
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fuse destruction in case of a shorted high-side MOSFET was enabled
for all boards with DC/DC converter, even if the board doesn't have a
fuse at the low-side terminal (e.g. Nucleo G474RE).
Add an ls-fuse property to the charge-controller binding to describe
this hardware feature and make HS_MOSFET_FAIL_SAFE_PROTECTION depend on
it. The property is added to all MPPT boards, so the behavior does not
change for them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fuse destruction set a duty cycle of 0 and started the half bridge.
For the STM32 TIM drivers, this did not switch on the low-side MOSFET,
as starting is refused with a compare value of 0. Use the new function
half_bridge_force_low_side() instead.
In addition, the control loop running at 10 Hz could override the
forced state, because it saw an enabled half bridge and continued with
MPPT control. Now the control function returns early as soon as the HS
MOSFET short error is set.
The low-side switch is forced on again with each call in case the half
bridge was stopped in the meantime, e.g. by an ADC alert. The data is
only stored once to avoid unnecessary flash writes if the fuse does not
blow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The STM32 timer half-bridge driver supported two operating modes, which
only shared the clock, reset and pinctrl setup, but branched in every
API function. Split it into two drivers with separate compatibles:
- libresolar,stm32-advtim-half-bridge: Advanced-control timers (e.g.
TIM1) with complementary outputs and hardware dead time generation.
- libresolar,stm32-gptim-half-bridge: General-purpose timers (e.g. TIM3)
without dead time generator, using two independent channels with dead
time generated in software.
This allows the devicetree bindings to only contain the properties
valid for the respective timer type (e.g. adc-trigger only for advtim,
high-side-channel and low-side-channel required for gptim) and removes
most of the preprocessor conditionals for MCUs without advanced-control
timers. The common timer setup is moved to half_bridge_stm32_tim.c.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the register-level half_bridge.c module by the new half-bridge
drivers. The Dcdc class gets the half-bridge device injected via its
constructor, so that the emulated driver can be used in unit tests.
Board devicetrees are migrated to the new compatibles:
- TIM1 boards use libresolar,stm32-half-bridge with complementary
outputs on channel 1. The ADC trigger via OC6/TRGO2 is enabled for
the STM32G4 boards as before.
- MPPT 1210 HUS uses libresolar,stm32-half-bridge with TIM3 channel 3
(high side) and channel 4 (low side).
- Nucleo G474RE uses libresolar,stm32-hrtim-half-bridge. The HRTIM
node gets the timer clock source as second clock.
Instead of the half-bridge compatible, the halfbridge node label is now
used to detect if the board has a DC/DC converter.
The half-bridge unit tests are removed, as they are superseded by the
driver test suite in tests/drivers/half_bridge.
Note for out-of-tree boards: Nodes with "half-bridge" compatible must be
migrated to one of the new compatibles, and the deadtime property was
renamed to deadtime-ns.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Also use new Zephyr CI environment and compile all boards.
Board migration script example:
python ../zephyr/scripts/utils/board_v1_to_v2.py --board-root . \
-v libresolar -g libresolar -b pwm_2420_lus -s stm32l072xx
If the device received a command before the previous one was processed,
it could get stalled inside the ISR, as the rx fifo was never read and
the interrupts kept firing, while processing (in lower priority thread)
cannot happen.
The structure has been changed to match the new ThingSet v0.5 spec which
is more suitable to be used in mobile phone apps because the data is
structured based on logical subsystems (Battery, Load) and not on data type
(conf, input, etc.) anymore.
This required some updates in the ThingSet library aswell. Especially the
update mechanism for configuration data had to be changed.
The data_objects_parser script is now able to extract the units itself,
reducing the commenting effort.
All IDs have been kept the same, so previously stored settings in charge
controllers NVM should be compatible.
The format tries to maintain the previously used Libre Solar firmware coding
style as much as possible.
Applying the format fixed some issues and re-ordered some parts of the code.
https://docs.zephyrproject.org/latest/guides/west/workspaces.html
Previously, west manifest and CMake entry point were in zephyr subfolder
as required for PlatformIO. As PlatformIO support was dropped, we can
follow the default Zephyr folder structure more closely.
The application is built and flashed from app subfolder, where as unit
tests are run from tests subfolder.