Files
stm32-openinverter-teslacha…/include/param_prj.h
T
Bastian de Byl 307853bea8
Build Firmware / Build stm32-teslacharger (pull_request) Successful in 59s
feat: receive ChargeLimit_pct from VCU on CAN 0x212 (SKUDAK-516)
Pairs with stm32-hal-vcu PR #42. Adds a runtime "vcuchglim" param that
the VCU broadcasts every 200 ms; on receipt, the param's Change()
callback translates 20-100% to the charger's udcspnt (DC voltage
setpoint) using a linear cell-voltage ramp.

Without this, the teslacharger had no path for the user's app-set
charge limit to actually limit charging — udcspnt was effectively
a compile-time setpoint.

What's added
------------

- Param::vcuchglim in include/param_prj.h:
    PARAM_ENTRY(CAT_CHARGER, vcuchglim, "%", 20, 100, 80, 23)
  - Range 20-100 (matches VCU validation)
  - Default 80% if VCU never connects
  - ID 23 (next free per the comment, bumped to 24)
  - Saveable so a flashed charger paired with a silent VCU still
    behaves predictably across reboots

- can->AddRecv(Param::vcuchglim, 0x212, 0, 8, 1) registration in
  ChargerCAN::MapMessages() — libopeninv's CanMap dispatches to the
  Change() callback on each received frame.

- Param::Change(vcuchglim) handler in src/main.cpp:
    cell_target = 3.30 + (4.15 - 3.30) * (pct - 20) / 80
    udcspnt     = cell_target * 96
  Endpoints chosen to be safe across Tesla LDU / VW MEB / Volt2:
    20%  → 3.30 V/cell × 96 = 316.8 V (deep-cycle storage floor)
    80%  → 3.94 V/cell × 96 = 378.0 V (recommended daily ceiling)
    100% → 4.15 V/cell × 96 = 398.4 V (matches existing udclim default)
  Tuneable here as constants if a particular pack needs a tighter range.

- VER bump 1.19.R → 1.20.R. Combined with the pre-existing -S1 suffix
  the OI web UI shows "4=1.20.R-S1", visually distinct from upstream
  and from the previous Skudak build.

Build
-----

text=25288, links clean. The "RWX LOAD segment" linker warning is
pre-existing on this template, unrelated. No new warnings from this
change.

Version string in the binary verified as "4=1.20.R-S1".

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-09 22:38:01 -04:00

180 lines
7.0 KiB
C

/*
* This file is part of the stm32-template project.
*
* Copyright (C) 2020 Johannes Huebner <dev@johanneshuebner.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* This file contains all parameters used in your project
* See main.cpp on how to access them.
* If a parameters unit is of format "0=Choice, 1=AnotherChoice" etc.
* It will be displayed as a dropdown in the web interface
* If it is a spot value, the decimal is translated to the name, i.e. 0 becomes "Choice"
* If the enum values are powers of two, they will be displayed as flags, example
* "0=None, 1=Flag1, 2=Flag2, 4=Flag3, 8=Flag4" and the value is 5.
* It means that Flag1 and Flag3 are active -> Display "Flag1 | Flag3"
*
* Every parameter/value has a unique ID that must never change. This is used when loading parameters
* from flash, so even across firmware versions saved parameters in flash can always be mapped
* back to our list here. If a new value is added, it will receive its default value
* because it will not be found in flash.
* The unique ID is also used in the CAN module, to be able to recover the CAN map
* no matter which firmware version saved it to flash.
* Make sure to keep track of your ids and avoid duplicates. Also don't re-assign
* IDs from deleted parameters because you will end up loading some random value
* into your new parameter!
* IDs are 16 bit, so 65535 is the maximum
*/
//Define a version string of your firmware here
#define VER 1.20.R
/* Entries must be ordered as follows:
1. Saveable parameters (id != 0)
2. Temporary parameters (id = 0)
3. Display values
*/
//Next param id (increase when adding new parameter!): 24
//Next value Id: 2051
/* category name unit min max default id */
#define PARAM_LIST \
PARAM_ENTRY(CAT_CHARGER, idclim, "A", 0, 45, 45, 3 ) \
PARAM_ENTRY(CAT_CHARGER, iaclim, "A", 0, 72, 16, 10 ) \
PARAM_ENTRY(CAT_CHARGER, idcspnt, "A", 0, 45, 45, 9 ) \
PARAM_ENTRY(CAT_CHARGER, chargerena, CHARGERS, 1, 7, 7, 4 ) \
PARAM_ENTRY(CAT_CHARGER, udcspnt, "V", 50, 420, 403, 5 ) \
PARAM_ENTRY(CAT_CHARGER, udclim, "V", 50, 420, 398, 6 ) \
PARAM_ENTRY(CAT_CHARGER, timelim, "minutes", -1, 10000, -1, 16 ) \
PARAM_ENTRY(CAT_CHARGER, timedly, "minutes", -1, 10000, -1, 22 ) \
PARAM_ENTRY(CAT_CHARGER, inputype, INPUTS, 0, 5, 1, 17 ) \
PARAM_ENTRY(CAT_CHARGER, cancontrol, OFFON, 0, 1, 0, 14 ) \
PARAM_ENTRY(CAT_CHARGER, enablepol, POLARITIES,0, 1, 0, 18 ) \
PARAM_ENTRY(CAT_CHARGER, idckp, "", 0, 10000, 1, 20 ) \
PARAM_ENTRY(CAT_CHARGER, idcki, "", 0, 10000, 10, 21 ) \
PARAM_ENTRY(CAT_CHARGER, vcuchglim, "%", 20, 100, 80, 23 ) \
VALUE_ENTRY(state, STATES, 2043 ) \
VALUE_ENTRY(uptime, "s", 2048 ) \
VALUE_ENTRY(lasterr, errorListString, 2002 ) \
VALUE_ENTRY(uaux, "V", 2049 ) \
VALUE_ENTRY(aclim, "A", 2042 ) \
VALUE_ENTRY(cablelim, "A", 2038 ) \
VALUE_ENTRY(evselim, "A", 2039 ) \
VALUE_ENTRY(idc, "A", 2041 ) \
VALUE_ENTRY(udc, "V", 2047 ) \
VALUE_ENTRY(soc, "%", 2046 ) \
VALUE_ENTRY(proximity, OFFON, 2040 ) \
VALUE_ENTRY(enable, OFFON, 2005 ) \
VALUE_ENTRY(canenable, OFFON, 2045 ) \
VALUE_ENTRY(cpuload, "%", 2004 ) \
VALUE_ENTRY(version, VERSTR, 2001 ) \
VALUE_ENTRY(opmode, OPMODES, 2000 ) \
VALUE_ENTRY(hwaclim, "A", 2050 ) \
VALUE_ENTRY(c1stt, "", 2007 ) \
VALUE_ENTRY(c1flag, CHFLAGS, 2008 ) \
VALUE_ENTRY(c1tmp1, "°C", 2010 ) \
VALUE_ENTRY(c1tmp2, "°C", 2011 ) \
VALUE_ENTRY(c1tmpin, "°C", 2012 ) \
VALUE_ENTRY(c1uac, "V", 2013 ) \
VALUE_ENTRY(c1iac, "A", 2014 ) \
VALUE_ENTRY(c1udc, "V", 2015 ) \
VALUE_ENTRY(c1idc, "A", 2016 ) \
VALUE_ENTRY(c2stt, "", 2017 ) \
VALUE_ENTRY(c2flag, CHFLAGS, 2018 ) \
VALUE_ENTRY(c2tmp1, "°C", 2020 ) \
VALUE_ENTRY(c2tmp2, "°C", 2021 ) \
VALUE_ENTRY(c2tmpin, "°C", 2022 ) \
VALUE_ENTRY(c2uac, "V", 2023 ) \
VALUE_ENTRY(c2iac, "A", 2024 ) \
VALUE_ENTRY(c2udc, "V", 2025 ) \
VALUE_ENTRY(c2idc, "A", 2026 ) \
VALUE_ENTRY(c3stt, "", 2027 ) \
VALUE_ENTRY(c3flag, CHFLAGS, 2028 ) \
VALUE_ENTRY(c3tmp1, "°C", 2030 ) \
VALUE_ENTRY(c3tmp2, "°C", 2031 ) \
VALUE_ENTRY(c3tmpin, "°C", 2032 ) \
VALUE_ENTRY(c3uac, "V", 2033 ) \
VALUE_ENTRY(c3iac, "A", 2034 ) \
VALUE_ENTRY(c3udc, "V", 2035 ) \
VALUE_ENTRY(c3idc, "A", 2036 ) \
VALUE_ENTRY(test_time, "s", 3000 ) \
VALUE_ENTRY(test_timer_flag, "X", 3001 ) \
VALUE_ENTRY(test_timer_icvalue, "X", 3002 ) \
/***** Enum String definitions *****/
#define OPMODES "0=Off, 1=Run"
#define CHARGERS "1=Charger1, 2=Charger2, 4=Charger3"
#define OFFON "0=Off, 1=On"
#define CHFLAGS "0=None, 1=Enabled, 2=Fault, 4=CheckAlive"
#define STATES "0=Off, 1=WaitStart, 2=Enable, 3=Activate, 4=Run, 5=Stop"
#define INPUTS "0=Type2, 1=Type2-3P, 2=Type1, 3=Manual, 4=Manual-3P, 5=Type2-Auto"
#define POLARITIES "0=ActiveHigh, 1=ActiveLow"
#define CAT_TEST "Testing"
#define CAT_CHARGER "Charger"
#define CAT_COMM "Communication"
// SKUDAK customization suffix: bump on every Skudak-side change so the OpenInverter
// web UI shows a distinct version (e.g. "4=1.19.R-S1") and we can visually confirm
// the right firmware is flashed. Match the stm32-sine -S<N> convention.
#define VERSTR STRINGIFY(4=VER-S1)
/***** enums ******/
enum inputs
{
INP_TYPE2,
INP_TYPE2_3P,
INP_TYPE1,
INP_MANUAL,
INP_MANUAL_3P,
INP_TYPE2_AUTO
};
enum states
{
OFF,
WAITSTART,
ENABLE,
ACTIVATE,
EVSEACTIVATE,
STOP
};
enum _canspeeds
{
CAN_PERIOD_100MS = 0,
CAN_PERIOD_10MS,
CAN_PERIOD_LAST
};
enum _modes
{
MOD_OFF = 0,
MOD_RUN,
MOD_LAST
};
enum _chflags
{
FLAG_NONE = 0,
FLAG_ENABLED = 1,
FLAG_FAULT = 2,
FLAG_CHECK = 4
};
//Generated enum-string for possible errors
extern const char* errorListString;