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
This commit is contained in:
Martin Jäger
2026-03-08 06:25:56 +01:00
parent 5622cb97e6
commit 167fc5d3ac
92 changed files with 388 additions and 606 deletions
-12
View File
@@ -1,12 +0,0 @@
# custom DTS overlays
*.overlay
# custom project configuration per board
prj_*.conf
# alternative location for custom DTS overlays or conf files
boards*
# folders generated by west
build
-3
View File
@@ -1,9 +1,6 @@
# Copyright (c) The Libre Solar Project Contributors
# SPDX-License-Identifier: Apache-2.0
set(BOARD_ROOT ${CMAKE_SOURCE_DIR}/..)
set(DTS_ROOT ${CMAKE_SOURCE_DIR}/..)
cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
+159
View File
@@ -0,0 +1,159 @@
/*
* Copyright (c) 2019 STMicroelectronics.
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* This is a dummy charge controller board for testing new features using the STM32G474 MCU
*
* IMPORTANT: You have to remove the VREF jumper on the Nucleo board to make it work. Otherwise
* the MCU will get stuck while trying to generate a reference voltage at VREF+ pin.
*/
/ {
/* delete conflicting nodes from Zephyr board */
/delete-node/ leds;
/delete-node/ aliases;
pcb {
compatible = "charge-controller";
type = "Nucleo G474 dummy charge controller";
version-str = "v0.1";
version-num = <1>;
hs-voltage-max = <80>;
ls-voltage-max = <32>;
dcdc-current-max = <20>;
};
chosen {
zephyr,console = &lpuart1;
zephyr,shell-uart = &lpuart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,canbus = &fdcan1;
};
leds {
compatible = "charlieplexing-leds";
gpios = <&gpioa 5 GPIO_ACTIVE_HIGH>;
pwr {
states = <1>;
};
};
outputs {
compatible = "outputs";
can_en {
gpios = <&gpiob 11 GPIO_ACTIVE_LOW>;
};
};
adc-inputs {
compatible = "adc-inputs";
v-low {
io-channels = <&adc1 12>;
multiplier = <105600>;
divider = <5600>;
};
v-high {
io-channels = <&adc1 15>;
multiplier = <102200>;
divider = <2200>;
};
vref-mcu {
io-channels = <&adc1 18>;
multiplier = <1>;
divider = <1>;
};
temp-mcu {
io-channels = <&adc1 16>;
multiplier = <1>;
divider = <1>;
};
i-dcdc {
io-channels = <&adc2 1>;
// amp gain: 25, resistor: 2 mOhm
multiplier = <1000>; // 1000
divider = <50>; // 2*25
};
};
gpio_keys {
compatible = "gpio-keys";
user_button: button {
gpios = <&gpioc 13 GPIO_ACTIVE_LOW>;
};
};
aliases {
sw0 = &user_button;
uart-dbg = &lpuart1;
uart-uext = &usart1;
spi-uext = &spi1;
i2c-uext = &i2c1;
};
soc {
hrtim1: timers@40016800 {
compatible = "st,stm32-timers";
reg = <0x40016800 0x400>;
clocks = <&rcc STM32_CLOCK(APB2, 26)>;
resets = <&rctl STM32_RESET(APB2, 26)>;
interrupts = <67 0>, <68 0>, <69 0>, <70 0>,
<71 0>, <72 0>, <73 0>, <74 0>;
interrupt-names = "master", "tima", "timb", "timc",
"timd", "time", "flt", "timf";
st,prescaler = <0>;
status = "disabled";
};
};
};
&hrtim1 {
status = "okay";
halfbridge: halfbridge {
compatible = "half-bridge";
pinctrl-0 = <&hrtim1_cha1_pa8 &hrtim1_cha2_pa9>;
pinctrl-names = "default";
frequency = <70000>;
deadtime = <300>;
};
};
/*
// alternative to HRTIM
&timers1 {
status = "okay";
halfbridge: halfbridge {
compatible = "half-bridge";
pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch1n_pb13>;
pinctrl-names = "default";
frequency = <70000>;
deadtime = <300>;
};
};
*/
&adc1 {
pinctrl-0 = <&adc1_in1_pa0>;
pinctrl-names = "default";
status = "okay";
};
&fdcan1 {
bitrate = <500000>;
bitrate-data = <2000000>;
status = "okay";
};
+2
View File
@@ -19,6 +19,8 @@ CONFIG_REBOOT=y
CONFIG_HWINFO=y
CONFIG_CRC=y
CONFIG_CONSOLE_SUBSYS=y
CONFIG_CONSOLE_GETCHAR=y
+16 -13
View File
@@ -226,12 +226,12 @@ bool battery_conf_check(BatConf *bat_conf)
{ .func =
[bat_conf]() {
return bat_conf->load_reconnect_voltage
> (bat_conf->load_disconnect_voltage + 0.4);
> (bat_conf->load_disconnect_voltage + 0.4f);
},
.text = "Load Reconnect Voltage must be higher than Load Disconnect Voltage + 0.4" },
{ .func =
[bat_conf]() {
return bat_conf->recharge_voltage < (bat_conf->topping_voltage - 0.4);
return bat_conf->recharge_voltage < (bat_conf->topping_voltage - 0.4f);
},
.text = "Recharge Voltage must be lower than Topping Voltage - 0.4" },
{ .func =
@@ -241,28 +241,29 @@ bool battery_conf_check(BatConf *bat_conf)
.text = "Recharge Voltage must be higher than Load Disconnect Voltage + 1.0" },
{ .func =
[bat_conf]() {
return bat_conf->load_disconnect_voltage > (bat_conf->absolute_min_voltage + 0.4);
return bat_conf->load_disconnect_voltage
> (bat_conf->absolute_min_voltage + 0.4f);
},
.text = "Load Disconnecct Voltage must be higher than Absolute Min Voltage + 0.4" },
{ .func =
[bat_conf]() {
return bat_conf->internal_resistance
< bat_conf->load_disconnect_voltage * 0.1 / DISCHARGE_CURRENT_MAX;
< bat_conf->load_disconnect_voltage * 0.1f / DISCHARGE_CURRENT_MAX;
},
.text = "Internal Battery Resistance must not cause more than 10% drop at Max Discharge "
"Current" },
{ .func =
[bat_conf]() {
return bat_conf->wire_resistance
< bat_conf->topping_voltage * 0.03 / DISCHARGE_CURRENT_MAX;
< bat_conf->topping_voltage * 0.03f / DISCHARGE_CURRENT_MAX;
},
.text = "Wire Resistances must not cause more than 3% drop at Max Discharge Current" },
{ .func =
[bat_conf]() {
return bat_conf->topping_cutoff_current < (bat_conf->nominal_capacity / 10.0);
return bat_conf->topping_cutoff_current < (bat_conf->nominal_capacity / 10.0f);
},
.text = "Topping Cutoff Current must be less than 10% of Nominal Capacity (C/10)" },
{ .func = [bat_conf]() { return bat_conf->topping_cutoff_current > 0.01; },
{ .func = [bat_conf]() { return bat_conf->topping_cutoff_current > 0.01f; },
.text = "Topping Cutoff Current must be higher than 0.01A" },
{ .func =
[bat_conf]() {
@@ -355,10 +356,10 @@ void Charger::detect_num_batteries(BatConf *bat) const
&& port->bus->voltage < bat->absolute_max_voltage * 2)
{
port->bus->series_multiplier = 2;
printf("Detected two batteries (total %.2f V max)\n", bat->topping_voltage * 2);
printf("Detected two batteries (total %.2f V max)\n", (double)bat->topping_voltage * 2);
}
else {
printf("Detected single battery (%.2f V max)\n", bat->topping_voltage);
printf("Detected single battery (%.2f V max)\n", (double)bat->topping_voltage);
}
}
@@ -366,9 +367,9 @@ void Charger::update_soc(BatConf *bat_conf)
{
static int soc_filtered = 0; // SOC / 100 for better filtering
if (fabs(port->current) < 0.2) {
if (fabs(port->current) < 0.2f) {
int soc_new = (int)((port->bus->voltage - bat_conf->ocv_empty)
/ (bat_conf->ocv_full - bat_conf->ocv_empty) * 10000.0);
/ (bat_conf->ocv_full - bat_conf->ocv_empty) * 10000.0f);
if (soc_new > 500 && soc_filtered == 0) {
// bypass filter during initialization
@@ -452,7 +453,8 @@ void Charger::discharge_control(BatConf *bat_conf)
// discharging currently not allowed. should we allow it?
if (port->bus->voltage
>= port->bus->src_control_voltage(bat_conf->absolute_min_voltage + 0.1F)) {
>= port->bus->src_control_voltage(bat_conf->absolute_min_voltage + 0.1F))
{
dev_stat.clear_error(ERR_BAT_UNDERVOLTAGE);
}
@@ -463,7 +465,8 @@ void Charger::discharge_control(BatConf *bat_conf)
}
if (!dev_stat.has_error(ERR_BAT_UNDERVOLTAGE | ERR_BAT_DIS_OVERTEMP
| ERR_BAT_DIS_UNDERTEMP)) {
| ERR_BAT_DIS_UNDERTEMP))
{
// discharge current is stored as absolute value in bat_conf, but defined
// as negative current for power port
port->neg_current_limit = -bat_conf->discharge_current_max;
+6 -5
View File
@@ -91,7 +91,8 @@ static inline float ntc_temp(uint32_t channel, int32_t vref, float ntc_series_re
// resistance of NTC (Ohm)
float rts = ntc_series_resistor * v_temp / (vref - v_temp);
return 1.0 / (1.0 / (273.15 + 25) + 1.0 / NTC_BETA_VALUE * log(rts / 10000.0)) - 273.15; // °C
return 1.0f / (1.0f / (273.15f + 25.0f) + 1.0f / (float)NTC_BETA_VALUE * logf(rts / 10000.0f))
- 273.15f; // °C
}
void calibrate_current_sensors()
@@ -369,13 +370,13 @@ void prepare_adc_readings(AdcValues values)
{
adc_readings[ADC_POS(vref_mcu)] = (uint16_t)(1.224 / 3.3 * 4096) << 4;
adc_readings[ADC_POS(v_high)] =
(uint16_t)((values.solar_voltage / ADC_GAIN(v_high)) / 3.3 * 4096) << 4;
(uint16_t)((values.solar_voltage / ADC_GAIN(v_high)) / 3.3f * 4096) << 4;
adc_readings[ADC_POS(v_low)] =
(uint16_t)((values.battery_voltage / ADC_GAIN(v_low)) / 3.3 * 4096) << 4;
(uint16_t)((values.battery_voltage / ADC_GAIN(v_low)) / 3.3f * 4096) << 4;
adc_readings[ADC_POS(i_dcdc)] =
(uint16_t)((values.dcdc_current / ADC_GAIN(i_dcdc)) / 3.3 * 4096) << 4;
(uint16_t)((values.dcdc_current / ADC_GAIN(i_dcdc)) / 3.3f * 4096) << 4;
adc_readings[ADC_POS(i_load)] =
(uint16_t)((values.load_current / ADC_GAIN(i_load)) / 3.3 * 4096) << 4;
(uint16_t)((values.load_current / ADC_GAIN(i_load)) / 3.3f * 4096) << 4;
}
void prepare_adc_filtered()
+2
View File
@@ -1175,7 +1175,9 @@ void data_objects_init()
hwinfo_get_device_id(buf, sizeof(buf));
uint64_t id64 = crc32_ieee(buf, sizeof(buf));
#ifdef CONFIG_LIBRE_SOLAR_TYPE_ID
id64 += ((uint64_t)CONFIG_LIBRE_SOLAR_TYPE_ID) << 32;
#endif
uint64_to_base32(id64, device_id, sizeof(device_id), alphabet_crockford);
#endif
+2 -1
View File
@@ -12,6 +12,7 @@
#include "helper.h"
#include "mcu.h"
#include "thingset.h"
#include "zephyr/toolchain.h"
#include <stdio.h>
@@ -25,7 +26,7 @@ LOG_MODULE_REGISTER(nvs, CONFIG_DATA_STORAGE_LOG_LEVEL);
K_MUTEX_DEFINE(data_buf_lock);
// Buffer used by store and restore functions (must be word-aligned for hardware CRC calculation)
static uint8_t buf[512] __aligned(sizeof(uint32_t));
__maybe_unused static uint8_t buf[512] __aligned(sizeof(uint32_t));
extern ThingSet ts;
+16 -12
View File
@@ -69,7 +69,7 @@ void Dcdc::perturb_observe_buck()
power_good_timestamp = uptime();
}
if ((uptime() - power_good_timestamp > 10 || power < -10.0) && mode != DCDC_MODE_AUTO) {
if ((uptime() - power_good_timestamp > 10 || power < -10.0f) && mode != DCDC_MODE_AUTO) {
// switch off after 10s low power or negative power (if not in nanogrid mode)
pwm_direction = 0;
}
@@ -114,7 +114,7 @@ void Dcdc::perturb_observe_boost()
power_good_timestamp = uptime();
}
if ((uptime() - power_good_timestamp > 10 || -power < -10.0) && mode != DCDC_MODE_AUTO) {
if ((uptime() - power_good_timestamp > 10 || -power < -10.0f) && mode != DCDC_MODE_AUTO) {
// switch off after 10s low power or negative power (if not in nanogrid mode)
pwm_direction = 0;
}
@@ -166,7 +166,7 @@ __weak DcdcOperationMode Dcdc::check_start_conditions()
if (lvb->sink_current_margin > 0 && lvb->voltage < lvb->sink_control_voltage()
&& hvb->src_current_margin < 0 && hvb->voltage > hvb->src_control_voltage()
&& hvb->voltage * 0.85 > lvb->voltage)
&& hvb->voltage * 0.85f > lvb->voltage)
{
return DCDC_MODE_BUCK;
}
@@ -259,7 +259,8 @@ __weak void Dcdc::control()
half_bridge_start();
power_good_timestamp = uptime();
printf("DC/DC %s mode start (HV: %.2fV, LV: %.2fV, PWM: %.1f).\n", mode_name,
hvb->voltage, lvb->voltage, half_bridge_get_duty_cycle() * 100);
(double)hvb->voltage, (double)lvb->voltage,
(double)half_bridge_get_duty_cycle() * 100.0);
}
else {
startup_inhibit(true); // reset inhibit counter
@@ -275,7 +276,7 @@ __weak void Dcdc::control()
stop_reason = "disabled";
}
else {
if (mode == DCDC_MODE_BUCK || (mode == DCDC_MODE_AUTO && inductor_current > 0.1)) {
if (mode == DCDC_MODE_BUCK || (mode == DCDC_MODE_AUTO && inductor_current > 0.1f)) {
perturb_observe_buck();
}
else {
@@ -289,9 +290,10 @@ __weak void Dcdc::control()
LOG_DBG("P %.2fW, inductor %.2fA, HS: %.2fV, %.2fA margin, "
"LS: %.2fV (target %.2fV), %.2fA margin, "
"PWM: %.1f, dcdc_state: %d, pwm_direction: %d",
power, inductor_current, hvb->voltage, hvb->src_current_margin,
lvb->voltage, lvb->sink_voltage_intercept, lvb->sink_current_margin,
half_bridge_get_duty_cycle() * 100.0, state, pwm_direction);
(double)power, (double)inductor_current, (double)hvb->voltage,
(double)hvb->src_current_margin, (double)lvb->voltage,
(double)lvb->sink_voltage_intercept, (double)lvb->sink_current_margin,
(double)half_bridge_get_duty_cycle() * 100.0, state, pwm_direction);
}
else {
stop_reason = "low power";
@@ -316,7 +318,7 @@ void Dcdc::test()
stop_reason = "disabled";
}
else {
if (half_bridge_get_duty_cycle() > 0.50) {
if (half_bridge_get_duty_cycle() > 0.50f) {
half_bridge_set_ccr(half_bridge_get_ccr() - 1);
}
else {
@@ -337,8 +339,9 @@ void Dcdc::test()
half_bridge_set_duty_cycle(lvb->voltage / hvb->voltage);
half_bridge_start();
printf("DC/DC test mode start (HV: %.2fV, LV: %.2fV, PWM: %.1f).\n", hvb->voltage,
lvb->voltage, half_bridge_get_duty_cycle() * 100);
printf("DC/DC test mode start (HV: %.2fV, LV: %.2fV, PWM: %.1f).\n",
(double)hvb->voltage, (double)lvb->voltage,
(double)half_bridge_get_duty_cycle() * 100.0);
}
else {
startup_inhibit(true); // reset inhibit counter
@@ -394,6 +397,7 @@ void Dcdc::output_hvs_disable()
#else
Dcdc::Dcdc(DcBus *high, DcBus *low, DcdcOperationMode op_mode) {}
Dcdc::Dcdc(DcBus *high, DcBus *low, DcdcOperationMode op_mode)
{}
#endif /* BOARD_HAS_DCDC */
+11 -12
View File
@@ -33,7 +33,11 @@ extern ThingSet ts;
extern uint16_t can_node_addr;
extern Charger charger;
#if DT_NODE_EXISTS(DT_NODELABEL(can1))
static const struct device *can_dev = DEVICE_DT_GET(DT_NODELABEL(can1));
#elif DT_NODE_EXISTS(DT_NODELABEL(fdcan1))
static const struct device *can_dev = DEVICE_DT_GET(DT_NODELABEL(fdcan1));
#endif
#ifdef CONFIG_ISOTP
@@ -46,15 +50,13 @@ const struct isotp_fc_opts fc_opts = {
};
struct isotp_msg_id rx_addr = {
.id_type = CAN_EXTENDED_IDENTIFIER,
.use_ext_addr = 0, // Normal ISO-TP addressing (using only CAN ID)
.use_fixed_addr = 1, // enable SAE J1939 compatible addressing
// enable SAE J1939 compatible addressing
.flags = ISOTP_MSG_FIXED_ADDR | ISOTP_MSG_IDE,
};
struct isotp_msg_id tx_addr = {
.id_type = CAN_EXTENDED_IDENTIFIER,
.use_ext_addr = 0, // Normal ISO-TP addressing (using only CAN ID)
.use_fixed_addr = 1, // enable SAE J1939 compatible addressing
// enable SAE J1939 compatible addressing
.flags = ISOTP_MSG_FIXED_ADDR | ISOTP_MSG_IDE,
};
static struct isotp_recv_ctx recv_ctx;
@@ -146,10 +148,8 @@ CAN_MSGQ_DEFINE(sub_msgq, 10);
const struct can_filter ctrl_filter = {
.id = TS_CAN_TYPE_PUBSUB,
.rtr = CAN_DATAFRAME,
.id_type = CAN_EXTENDED_IDENTIFIER,
.id_mask = TS_CAN_TYPE_MASK,
.rtr_mask = 1,
.mask = TS_CAN_TYPE_MASK,
.flags = CAN_FILTER_IDE,
};
void can_pub_isr(const struct device *dev, int error, void *user_data)
@@ -160,9 +160,8 @@ void can_pub_isr(const struct device *dev, int error, void *user_data)
void can_pub_send(uint32_t can_id, uint8_t can_data[8], uint8_t data_len)
{
struct can_frame frame = { 0 };
frame.id_type = CAN_EXTENDED_IDENTIFIER;
frame.rtr = CAN_DATAFRAME;
frame.id = can_id;
frame.flags = CAN_FRAME_IDE;
memcpy(frame.data, can_data, 8);
if (data_len >= 0) {
+1 -1
View File
@@ -390,7 +390,7 @@ void half_bridge_init(int freq_kHz, int deadtime_ns, float min_duty, float max_d
void half_bridge_set_duty_cycle(float duty)
{
if (duty >= 0.0 && duty <= 1.0) {
if (duty >= 0.0f && duty <= 1.0f) {
half_bridge_set_ccr(half_bridge_get_arr() * duty);
}
}
+1 -1
View File
@@ -68,7 +68,7 @@ int main(void)
#endif
#if BOARD_HAS_USB_OUTPUT
usb_pwr.set_voltage_limits(bat_conf.load_disconnect_voltage - 0.1, // keep on longer than load
usb_pwr.set_voltage_limits(bat_conf.load_disconnect_voltage - 0.1f, // keep on longer than load
bat_conf.load_reconnect_voltage, bat_conf.absolute_max_voltage);
#endif