Commit Graph
14 Commits
Author SHA1 Message Date
Martin JägerandClaude Opus 5.5 a428892916 app: convert device status to C struct
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>
2026-11-01 15:21:57 +01:00
Martin JägerandClaude Opus 5.5 3cc24411b5 app: convert power port to C
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>
2026-11-01 15:12:51 +01:00
Martin JägerandClaude Opus 5.5 93f142d32d app: remove SoC-specific code
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>
2026-11-01 14:50:56 +01:00
Martin JägerandClaude Opus 5.5 b1cd0b6922 app: dcdc: fix fuse destruction in case of shorted HS MOSFET
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>
2026-10-21 08:58:35 +02:00
Martin JägerandClaude Opus 5.5 6c2251e2c8 app: use half-bridge driver for DC/DC converter
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>
2026-10-20 21:02:57 +02:00
Martin Jäger b59cede24f Switch to ThingSet SDK 2026-03-09 08:18:21 +01:00
Martin Jäger 167fc5d3ac Upgrade to Zephyr v4.3 and migrate boards
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
2026-03-08 06:25:56 +01:00
Martin Jäger 88467118be Upgrade to Zephyr v3.2 2023-01-13 20:34:38 +01:00
Martin Jäger 0087114020 DC/DC: Split P&O algorithm into buck and boost function
The previous combined function was hard to read and understand. Now using
a dedicated function for both power flow directions.
2022-02-10 17:39:57 +01:00
Martin Jäger d670f8bd6a DC/DC: Fix startup mode check
The allowed mode of the DC/DC is fixed at compile-time (in setup.cpp).

The start conditions have to match this mode.
2022-02-10 15:35:03 +01:00
Martin Jäger 923d536ae2 DC/DC: Add output_hvs_enable/disable calls
Without these calls the functions introduced in 6316dcd are useless.

Remark: These functions are currently only used on a prototype for testing.
2022-02-08 18:43:12 +01:00
Martin Jäger b4272ce7de DC/DC: Fix HS MOSFET short detection
Previously, the first_time_detected variable was never
reset after the error was detected once.
2022-02-08 18:32:08 +01:00
Martin Jäger 5bdbecf19d Add Clang-Format file and apply it
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.
2022-01-26 13:56:31 +01:00
Martin Jäger 8ab8ea244a Move to standard Zephyr T2 workspace structure (star topology)
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.
2021-12-12 14:09:05 +01:00