Minor code improvements from CppCheck & README updates (#32)
* log.h: fix signature of log_update_min_max_values looks like it was changed in log.cpp, but not adjusted in log.h, somewhen in the past * adc_dma: only define variables if they are really required * reduce scope of variables in interface_can.cpp * `changed` was reassigned a value before the old one was used * README: reformat flashing troubleshooting section * README: punctuation fixes * README: add troubleshooting tip for bad connection between nucleo and MPPT
This commit is contained in:
@@ -16,7 +16,7 @@ The software is configurable to support different charge controller PCBs with ei
|
||||
|
||||
1. Select the correct board in `platformio.ini` by removing the comment before the board name under `[platformio]`
|
||||
2. Copy `src/config.h_template` to `src/config.h`, and adjust basic settings
|
||||
|
||||
|
||||
(`config.h` is ignored by git, so your changes are kept after software updates using `git pull`)
|
||||
|
||||
cp src/config.h_template src/config.h
|
||||
@@ -28,22 +28,44 @@ See the Libre Solar website for project-agnostic instructions on how to
|
||||
[develop software](http://libre.solar/docs/toolchain) and
|
||||
[flash new firmware](http://libre.solar/docs/flashing).
|
||||
|
||||
---
|
||||
**If flashing the STM32L072 MCU using OpenOCD fails**
|
||||
### Troubleshooting
|
||||
|
||||
... as seems to happen with the standard settings from PlatformIO.
|
||||
#### If flashing the STM32L072 MCU using OpenOCD fails
|
||||
|
||||
... as seems to happen with the standard settings from PlatformIO, then ...
|
||||
|
||||
*NOTE* This MCU is used in the MPPT 1210 HUS and the PWM charge controller, for example.
|
||||
|
||||
Try one of these workarounds:
|
||||
|
||||
1. Change OpenOCD settings to `set WORKAREASIZE 0x1000` in the file `~/.platformio/packages/tool-openocd/scripts/board/st_nucleo_l073rz.cfg`.
|
||||
2. Use ST-Link tools. For Windows there is a GUI tool. Under Linux use the following command:
|
||||
2. Use ST-Link tools. For Windows there is a GUI tool. Under Linux, use the following command:
|
||||
|
||||
st-flash write .pioenvs/mppt-2420-lc-v0.10/firmware.bin 0x08000000
|
||||
3. Use other debuggers and tools, e.g. Segger J-Link.
|
||||
|
||||
---
|
||||
#### If flashing fails like this ...
|
||||
|
||||
In PlatformIO:
|
||||
|
||||
```
|
||||
Error: init mode failed (unable to connect to the target)
|
||||
in procedure 'program'
|
||||
** OpenOCD init failed **
|
||||
shutdown command invoked
|
||||
```
|
||||
|
||||
or with ST-Link:
|
||||
|
||||
```bash
|
||||
$ st-flash write .pioenvs/mppt-1210-hus-v0.4/firmware.bin 0x08000000
|
||||
st-flash 1.5.1
|
||||
2019-06-21T18:13:03 INFO common.c: Loading device parameters....
|
||||
2019-06-21T18:13:03 WARN common.c: unknown chip id! 0x5fa0004
|
||||
```
|
||||
|
||||
check the connection between the board used for flashing
|
||||
(for example the Nucleo), and the MPPT.
|
||||
|
||||
## API documentation
|
||||
|
||||
|
||||
@@ -136,7 +136,9 @@ void update_measurements(dcdc_t *dcdc, charger_t *charger, dc_bus_t *hs, dc_bus_
|
||||
https://www.embeddedrelated.com/showarticle/91.php
|
||||
*/
|
||||
|
||||
#if defined PIN_ADC_TEMP_BAT || defined PIN_ADC_TEMP_FETS
|
||||
float v_temp, rts;
|
||||
#endif
|
||||
float bat_temp = 25.0;
|
||||
|
||||
#ifdef PIN_ADC_TEMP_BAT
|
||||
|
||||
@@ -241,7 +241,7 @@ ThingSet ts(
|
||||
|
||||
void data_objects_update_conf()
|
||||
{
|
||||
bool changed = false;
|
||||
bool changed;
|
||||
if (battery_conf_check(&bat_conf_user)) {
|
||||
printf("New config valid and activated.\n");
|
||||
battery_conf_overwrite(&bat_conf_user, &bat_conf, &charger);
|
||||
@@ -250,6 +250,7 @@ void data_objects_update_conf()
|
||||
else {
|
||||
printf("Check not passed, getting back old config.\n");
|
||||
battery_conf_overwrite(&bat_conf, &bat_conf_user);
|
||||
changed = false;
|
||||
}
|
||||
|
||||
// TODO: check also for changes in Load/USB EnDefault
|
||||
|
||||
@@ -66,7 +66,6 @@ void can_pub_msg(data_object_t data_obj)
|
||||
|
||||
int32_t value;
|
||||
uint32_t value_abs;
|
||||
uint8_t exponent_abs;
|
||||
|
||||
// CBOR byte order: most significant byte first
|
||||
switch (data_obj.type) {
|
||||
@@ -83,7 +82,6 @@ void can_pub_msg(data_object_t data_obj)
|
||||
if (data_obj.exponent == 0) {
|
||||
msg.len = 5;
|
||||
value = *((int*)data_obj.data);
|
||||
value_abs = abs(value);
|
||||
if (value >= 0) {
|
||||
msg.data[0] |= TS_T_POS_INT32;
|
||||
value_abs = abs(value);
|
||||
@@ -103,7 +101,7 @@ void can_pub_msg(data_object_t data_obj)
|
||||
msg.data[1] = 0x82; // array of length 2
|
||||
|
||||
// exponent in single byte value, valid: -24 ... 23
|
||||
exponent_abs = abs(data_obj.exponent);
|
||||
uint8_t exponent_abs = abs(data_obj.exponent);
|
||||
if (data_obj.exponent >= 0 && data_obj.exponent <= 23) {
|
||||
msg.data[2] = exponent_abs;
|
||||
}
|
||||
@@ -113,7 +111,6 @@ void can_pub_msg(data_object_t data_obj)
|
||||
|
||||
// value as positive or negative uint32
|
||||
value = *((int*)data_obj.data);
|
||||
value_abs = abs(value);
|
||||
if (value >= 0) {
|
||||
msg.data[3] = 0x1a; // positive int32
|
||||
value_abs = abs(value);
|
||||
|
||||
@@ -69,6 +69,6 @@ void log_update_energy(log_data_t *log_data, dc_bus_t *solar, dc_bus_t *bat, dc_
|
||||
|
||||
/** Updates the logged min/max values for voltages, power, temperatures etc.
|
||||
*/
|
||||
void log_update_min_max_values(log_data_t *log_data, dcdc_t *dcdc, charger_t *bat, load_output_t *load, dc_bus_t *bat_bus, dc_bus_t *solar, dc_bus_t *load_bus);
|
||||
void log_update_min_max_values(log_data_t *log_data, dcdc_t *dcdc, charger_t *charger, load_output_t *load, dc_bus_t *solar_bus, dc_bus_t *bat_bus, dc_bus_t *load_bus);
|
||||
|
||||
#endif /* LOG_H */
|
||||
|
||||
Reference in New Issue
Block a user