Commit Graph
10 Commits
Author SHA1 Message Date
Martin JägerandClaude Opus 5.5 6ec3c6f312 drivers: sensor: add NTC thermistor driver using DAQ readings
Zephyr's NTC thermistor driver reads the ADC on demand, which is not
possible while the ADC is continuously sampled by the DAQ driver. The new
sensor driver calculates the temperature from the filtered reading of a
DAQ channel using the beta equation.

The DAQ channel is referenced via phandle, the pull-up resistor, the
nominal resistance and the beta value are configured in the devicetree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 14:47:03 +01:00
Martin JägerandClaude Opus 5.5 da59ab8276 drivers: power_switch: add PWM support
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>
2026-11-01 14:20:21 +01:00
Martin JägerandClaude Opus 5.5 01b48b26e1 drivers: power_switch: add power switch driver
Add a driver class for power switches, e.g. used for load and USB
outputs. Besides switching on and off, drivers may provide a power-good
feedback and report faults that were already handled in hardware.

Two backends are available:

- libresolar,gpio-power-switch: Switch driven by a GPIO with optional
  latching power-good feedback and charge pump PWM for high-side gate
  drivers. The latch time is handled by delayable work instead of
  blocking the caller.
- libresolar,stm32-lptim-power-switch: Switch driven by LPTIM1 of
  STM32L0, which is triggered by COMP2 to switch off within a few
  microseconds in case of a short circuit (PWM 2420 LUS).

The GPIO backend is tested on native_sim using the GPIO emulator and the
fake PWM driver.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 13:43:57 +01:00
Martin JägerandClaude Opus 5.5 82c5d1542d drivers: daq: add data acquisition driver
Add a Zephyr driver for the data acquisition (DAQ), i.e. continuous
sampling of all analog inputs with 1 kHz, low-pass filtering of the
readings and checking them against upper and lower limits. It is based
on the existing implementation in the application.

The driver consists of a common part (filtering, alerts, scaling and
calibration) and backends for the different ADC types:

- STM32 ADCs with a fixed channel sequence (STM32F0, STM32L0 and newly
  supported STM32G0)
- STM32 ADCs with a configurable channel sequence (STM32G4)
- Emulated DAQ for tests on native_sim

Compared to the application implementation, the position of the
readings in the DMA buffer is determined by the driver, so that the
inputs can be specified in any order in the devicetree. The factory
calibration values for the internal reference voltage and temperature
sensor are taken from the STM32 LL headers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 12:16:45 +01:00
Martin JägerandClaude Opus 5.5 7f83930ebb tests: drivers: half_bridge_loopback: detect floating outputs
Use pull-ups instead of pull-downs at the capture inputs, so that the
tests fail if the outputs are not actively driven low while the half
bridge is stopped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 00:04:23 +02:00
Martin JägerandClaude Opus 5.5 8213ec7383 tests: drivers: add half-bridge loop-back tests for Nucleo-G474RE
Verify the timing of the half-bridge outputs at the pins without
requiring a charge controller, where a wrong timer configuration could
destroy the power stage.

The outputs of the half bridge are wired to two input capture channels
of a 32-bit timer (TIM2 or TIM5) on a Nucleo-G474RE board. As both
channels share the same counter, the edges of the high-side and
low-side signals can be put into chronological order to measure:

- frequency and duty cycle (incl. duty cycle limits)
- dead time at both switching transitions of each period
- overlap of high-side and low-side on-time (shoot-through)
- output states when stopped and with forced low-side switch

The test covers the advtim (TIM1), gptim (TIM3) and HRTIM drivers with
separate overlays. It requires the half_bridge_loopback fixture, so it
is only built in CI and run with a twister hardware map on a board
with the loop-back wiring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 20:22:39 +02:00
Martin JägerandClaude Opus 5.5 427943994c drivers: half_bridge: add function to force low-side switch on
Add half_bridge_force_low_side() to switch the low-side switch
continuously on, bypassing the compare value limits. This is required
for safety measures like blowing the battery fuse in case of a shorted
high-side MOSFET.

Previously, this was attempted by setting a duty cycle of 0 and
starting the PWM. However, the STM32 timer drivers refuse to start with
a compare value of 0, so the low-side switch was never turned on.

The forced state is kept until half_bridge_stop() is called. Changes of
the compare value or its limits and start requests are rejected with
-EBUSY meanwhile, so that a concurrently running control loop can't
override it.

- advtim: Compare value 0 keeps OCxREF low, so that CHxN stays on. The
  output mode can't be changed, as it is locked during initialization.
- gptim: Compare value 0 for both channels, so that the low-side
  channel with inverted polarity stays on.
- HRTIM: Output 1 is reset by software and set events are removed, so
  that the complementary output 2 stays on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 08:43:53 +02:00
Martin JägerandClaude Opus 5.5 b271dc0aba tests: drivers: build half-bridge tests for STM32 boards and run in CI
Add a build-only twister scenario for boards using the STM32 TIM and
HRTIM half-bridge drivers. The tests are not run on hardware, as they
would switch the power stage.

The driver tests are run in CI with:

    west twister -T tests/drivers --integration

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 21:11:42 +02:00
Martin JägerandClaude Opus 5.5 8570d9d274 drivers: half_bridge: add STM32 timer driver
Add a half-bridge driver for STM32 timers (TIM), replacing the
register-level code for TIM1 and TIM3 in the application.

The timer and channels are configured via devicetree instead of being
derived from the timer base address. Two operating modes are supported:

- Complementary outputs CHx/CHxN of advanced-control timers (e.g. TIM1)
  with edge-aligned PWM and hardware dead time generation.
- Two independent channels of general-purpose timers (e.g. TIM3) with
  center-aligned PWM and dead time generated by shifting the compare
  value of the low-side channel.

Compared to the previous implementation, the timer clock is obtained
from the clock control driver instead of assuming SystemCoreClock, so
that APB prescalers are taken into account. The dead time register is
now encoded properly using __LL_TIM_CALC_DEADTIME instead of masking the
lowest 7 bits, which was wrong for more than 127 timer clocks.

The ADC trigger via OC6/TRGO2 (previously enabled for all STM32G4 MCUs)
must now be enabled explicitly with the adc-trigger property.

The period test of the driver test suite is skipped for non-emulated
devices so that the suite can also be built for STM32 boards.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 20:49:27 +02:00
Martin JägerandClaude Opus 5.5 749c84eee1 drivers: half_bridge: add emulated driver and tests
Add an emulated half-bridge driver for tests on native_sim. It behaves
like an edge-aligned STM32 timer, similar to the dummy registers used
in the unit tests so far.

The driver API is tested in a new ztest suite, which can be run with
twister:

    west twister -T tests/drivers -p native_sim

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 20:36:07 +02:00