516 Commits
Author SHA1 Message Date
Martin Jäger 98c1daa865 Enable CONFIG_I2C only if needed (e.g. for OLED or EEPROM) 2021-02-28 11:04:42 +01:00
Martin Jäger f8d7b25648 DCDC: Update HV output switch handling 2021-02-24 16:45:01 +01:00
Daniel Fanache 01ca3b4f15 Fix lv_terminal filtered current and add PWM filtered current.
The lv_terminal filtered current was in fact summing voltages.

Added a separate PWM switch low-pass filter current with more
responsive time constant.
2021-02-24 16:45:01 +01:00
Martin Jäger f6aeaa79db Fix hard faults in EEPROM CRC calculation
The hardware CRC calculation fails hard if a non-aligned memory pointer
is passed to it. This was leading to random issues when changing
unrelated parts in the firmware so that the compiler shuffled memory
locations.

Telling GCC that it should word-align the buffer fixes the issue.

Also renaming _lock to eeprom_buf_lock.
2021-02-05 20:58:16 +01:00
Martin Jäger 6aa015a140 Add basic HRTIM implementation for half_bridge 2021-02-05 18:12:31 +01:00
Martin Jäger fc71934010 Add Nucleo G474RE board for testing purposes 2021-02-05 17:51:10 +01:00
Martin Jäger c151213325 Compile EEPROM code only if enabled via Kconfig 2021-02-05 17:41:52 +01:00
Jordan Silverman a9b0a278ad EEPROM buffer mutex
Added a mutex locking system so that the EEPROM buffer cannot be
used by multiple functions at the same time.
2021-02-05 17:18:49 +01:00
Jordan Silverman a5c1d46d63 Consolidate eeprom buffers
We now use 1 statically allocated buffer for both eeprom_store and
eeprom_restore
2021-02-05 17:18:47 +01:00
Martin Jäger 35b390ff24 Battery voltage & current filtering to improve charging algorithm
For PWM charge controllers, the topping stage was sometimes very short
and the battery did not get fully charged.

This commit adds a voltage_filtered and current_filtered member variable
to DcBus and PowerPort classes which can hold measurements more heavily
filtered (initial time constant setting: 10 seconds). This should fix
above issues with the charging algorithm.
2021-02-04 17:28:52 +01:00
Martin Jäger 269ce762a0 Introduce new Zephyr board revisioning feature
This file layout allows to specify the revision using <board-name>@<revision>
during west build calls.
2021-02-04 17:28:52 +01:00
Martin Jäger ed29e54d20 Add reset for J-Link runner of STM32L0/F0 based boards
Otherwise they don't always wake up after flashing.
2021-02-04 17:28:52 +01:00
Martin Jäger bdf405fb7b Load: Clear ERR_LOAD_BUS_SRC_CURRENT if current is available again
Previously, the error was never cleared after it was set, which is obviously
a bad idea.
2021-02-04 17:28:52 +01:00
Martin Jäger 1b1ed838eb Fix log minimal mode Kconfig for Zephyr 2.5 2021-02-04 17:28:52 +01:00
Martin Jäger 2de110b0b7 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.
2021-02-04 17:28:52 +01:00
Martin Jäger 4eaf89154a Use BOARD_HAS_* macro to identify key hardware features
These macros replace the direct use of DT_ macros in many locations and make
the code more readable.
2021-02-04 17:28:52 +01:00
Martin Jäger 830315cda0 Use new ThingSet macros for CAN and ISO-TP fixed addressing 2021-02-04 17:28:52 +01:00
Martin Jäger 24742fefcb Fix CAN ISO-TP binding and CAN IDs
For the recv_ctx, the rx and tx addresses were swapped. In addition to that,
the binding has to be released before sending.
2021-02-04 17:28:52 +01:00
Martin Jäger fec60aacbb Enable CAN for MCUs with CAN-FD controller 2021-02-04 17:28:52 +01:00
Martin Jäger a352d6b98c Replace software watchdog with Zephyr task_wdt subsystem 2021-02-04 17:28:52 +01:00
Martin Jäger 941545ea7e Move to pinmux based on devicetree 2021-02-04 17:28:51 +01:00
Martin Jäger 0f109297e4 Use generic LL headers 2021-01-14 19:16:06 +01:00
Martin Jäger e63a2db9e5 Update west.yml and platformi.ini to track Zephyr v2.5
The v2.5-branch is based on upstream master until Zephyr v2.5 is released.

hal_stm32 needs to be overwritten with forked version to support new pinctrl
introduced in Zephyr 2.5.

Also fixing some CAN issues because of API changes to make it compile.
2021-01-14 19:11:59 +01:00
Jordan Silverman bcf54f6698 Add latching pgood function to USB power output 2021-01-14 19:07:19 +01:00
Martin Jäger 3653b88d25 Remove ADC/DAC dts nodes now present in upstream Zephyr 2020-12-15 10:47:29 +01:00
Martin Jäger e5b42ace72 Load: Use Zephyr PWM driver for charge pump 2020-12-15 10:47:14 +01:00
Daniel Fanache 9ba540ec8c Configurable log levels for all the modules using Zephyr's logging.
This allows us to enable e.g debug output for the CAN module with
CONFIG_CAN_LOG_LEVEL=4 without enabling the global
CONFIG_LOG_DEFAULT_LEVEL=4 and being swamped with debug output from
all of Zephyr's subsytems.
2020-12-13 11:06:02 +01:00
Martin Jäger 755e555611 Fix DC/DC debug print variables 2020-12-13 11:05:52 +01:00
Martin Jäger a2ab1ebd45 PWM switch: Improve overvoltage protection
In situations with full battery and sufficient solar panel power, the
battery could reach a high voltage directly after start of the PWM switch
and the control algorithm was not fast enough to limit the voltage (it
takes up to 18s to reach 5% duty cycle after starting at 95%).

This commit increases the step size in the direction of reduced power
and introduces an overvoltage flag that results in restart with 5% duty
cycle if the previous stop was caused by an overvoltage event.
2020-12-13 11:05:05 +01:00
Martin Jäger 4f4bdc70ae PWM switch: Clean up comments and add F suffixes 2020-12-13 11:04:56 +01:00
Martin Jäger 76ee3dc28f Doxygen: Disable preprocessing to include all classes 2020-12-11 22:19:23 +01:00
Martin Jäger 583924a9b9 Fix corrupted %f printf because of disabled heap
newlib requires malloc if printf is used with %f. Since PR 28486, the heap
space in RAM is only reserved if explicitly used by the application
(independent of the value of CONFIG_HEAP_MEM_POOL_SIZE) in order to free
some stack memory. As printf calls malloc internally, this commit forces
Zephyr to build with heap support enabled.
v20.0
2020-11-18 21:05:05 +01:00
Martin Jäger e5e27c10bc Add MPPT 2420 HC link to Readme 2020-11-18 21:05:05 +01:00
Martin Jäger cb4d4ea1d9 LEDs: Use GPIO flags from dts properly
The flags were always assumed to be ACTIVE_HIGH, which is now fixed.
2020-11-18 21:05:04 +01:00
Martin Jäger 47c1614ed0 Add MPPT 2420 HC board 2020-11-10 16:50:52 +01:00
Martin Jäger 5c3e227928 Add west.yml to use native Zephyr build system properly 2020-11-09 20:08:36 +01:00
Martin Jäger 3d9c4589cd Upgrade to Zephyr 2.4
- Make all struct device * constant
- Add additional argument to PWM nodes in devicetree
- Track customized LibreSolar/zephyr branch in platformio
- Update OLED submodule
2020-11-09 20:07:49 +01:00
Martin Jäger 62d28d9e5e Remove unneeded helper.cpp 2020-11-05 20:42:46 +01:00
Martin Jäger b63cdaa06d DC/DC: Use high/low DcBus instead of PowerPort for control
This makes more sense because the DC/DC converter actually connects two
DcBuses and does not need separate PowerPorts. Also makes the code look
more clean as variable access like dcdc.hvs->bus->voltage is avoided.

The DcBus pointers in the Dcdc are now called hvb and lvb for high-
voltage side bus and low-voltage side bus.
2020-11-05 20:42:34 +01:00
Martin Jäger 0756341b29 Rename src/sink_voltage_bound to _intercept
These variables define the voltage at zero current, which is the y axis
intercept of the droop curve (voltage vs. current).
As they do not always specifiy minimum or maximum boundary depending on
the sign of the droop resistance, intercept is a more suitable name.
2020-11-05 20:42:00 +01:00
Martin Jäger 7cd89bc04a PWM switch: Fix start voltage check
Previous statement didn't consider the series multiplier in case of 24V
battery.
2020-11-05 20:38:55 +01:00
Jordan Silverman 1a29aa1a6e Load NVM settings after data_nodes_init 2020-11-05 20:38:36 +01:00
Martin Jäger 1e64c253ac DAQ: Fix LV terminal current for DC/DC + PWM
Current calculation was wrong if both DC/DC and PWM ports are available
on the same device.
2020-11-05 20:38:03 +01:00
Martin Jäger 1e71ed043e DC/DC: Fix ls_voltage_max setting 2020-11-05 20:37:16 +01:00
Martin Jäger 42759947f8 DAQ: Add high-side overvoltage alert limit
Also rename the functions which set the alert limits to set_xx_limit
instead of set_xx_alert.
2020-11-05 20:37:03 +01:00
Martin Jäger c6709f8f00 Rename (Dcdc|PwmSwitch)::emergency_stop to stop
The stop functions can be used in a generic way, not only in an emergency
situation. The name was misleading.
2020-11-05 20:36:51 +01:00
Jordan Silverman 75e2969274 Update thingset lib commit 2020-11-05 20:36:51 +01:00
Martin Jäger 213e2e30b6 Increase control thread priority to -1
Set to lowest cooperative priority so that it cannot be interrupted by main
or other threads (only by ISRs).
2020-11-05 20:34:59 +01:00
Martin Jäger b40a419e3e Optimize timing of 1s loop in main.cpp
Previously, the interval was not exactly 1s, which could have a negative
impact on energy calculations.

This commit also moves the 1s interval tasks from control loop to the main
loop to avoid duplicated loops running at 1s interval.
2020-11-05 20:30:08 +01:00
Martin Jäger 62338711bc Fix ADC2 triggering for STM32G4 MCUs
When switching to edge-aligned PWM, the ADC measurement was accidentally
triggered at the beginning of the switching cycle.
Fixing this using TIM1 OC6, triggering at falling edge.
2020-10-14 10:04:05 +02:00