diff --git a/.travis.yml b/.travis.yml index 547bf20..7607ad1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,8 +30,8 @@ addons: script: - cp src/config.h_template src/config.h # - platformio ci --lib="lib/Adafruit_GFX" --lib="lib/ThingSet" --project-conf=platformio.ini -e libresolar_0_10,libresolar_0_05 - - platformio run -e libresolar_0_10 -e libresolar_0_05 -e cloudsolar_0_2 -e cloudsolar_0_4 -e pwm_0_2 - - platformio test -e unit_test_native + - platformio run -e mppt-2420-lc-v0.10 -e mppt-1210-hus-v0.2 -e mppt-1210-hus-v0.4 -e pwm-2420-lus-v0.2 + - platformio test -e unit-test-native - doxygen Doxyfile deploy: diff --git a/README.md b/README.md index 73ce397..051cbcd 100644 --- a/README.md +++ b/README.md @@ -8,22 +8,21 @@ Firmware based on ARM mbed framework for the Libre Solar MPPT/PWM solar charge c The software is configurable to support different charge controller PCBs with either STM32F072 (including CAN support) or low-power STM32L072/3 MCUs. -- [Libre Solar MPPT 20A with CAN (v0.10)](https://github.com/LibreSolar/MPPT-Charger_20A) -- [Libre Solar MPPT 12A (v0.5)](https://github.com/LibreSolar/MPPT-Charger_20A/tree/legacy-12A-version) -- [Libre Solar MPPT 10A with USB (v0.2 and v0.4)](https://github.com/LibreSolar/MPPT-Charger_10A) -- [Libre Solar PWM 20A (preliminary support)](https://github.com/LibreSolar/PWM-Charger_20A) +- [Libre Solar MPPT 12/24V 20A with CAN (v0.10)](https://github.com/LibreSolar/MPPT-2420-LC) +- [Libre Solar MPPT 12V 10A with USB (v0.2 and v0.4)](https://github.com/LibreSolar/MPPT-1210-HUS) +- [Libre Solar PWM 12/24V 20A](https://github.com/LibreSolar/PWM-2420-LUS) ## Toolchain and flashing instructions See the Libre Solar website for a detailed instruction how to [develop software](http://libre.solar/docs/toolchain) and [flash new firmware](http://libre.solar/docs/flashing). -**Remark:** Flashing the STM32L072 MCU (as used in the 10A MPPT and PWM charge controller) using OpenOCD with the standard settings from PlatformIO fails in many cases. Possible workarounds: +**Remark:** Flashing the STM32L072 MCU (as used in the MPPT 1210 HUS and the PWM charge controller) using OpenOCD with the standard settings from PlatformIO fails in many cases. Possible 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 following command: - st-flash write .pioenvs/cloudsolar_0_4/firmware.bin 0x08000000 + st-flash write .pioenvs/mppt-2420-lc-v0.10/firmware.bin 0x08000000 3. Use other debuggers and tools, e.g. Segger J-Link. @@ -41,7 +40,7 @@ The documentation auto-generated by Doxygen can be found [here](https://libre.so In order to run the unit tests, you need a PlatformIO Plus account. Run tests with the following command: - platformio test -e unit_test_native + platformio test -e unit-test-native ## Additional firmware documentation (docs folder) diff --git a/platformio.ini b/platformio.ini index e546458..7072911 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,14 +9,13 @@ # Select the charge controller hardware by uncommenting one of the following lines -#env_default = libresolar_0_05 -#env_default = libresolar_0_10 -#env_default = cloudsolar_0_2 -#env_default = cloudsolar_0_4 -#env_default = cloudsolar_0_6 -#env_default = pwm_0_1 -#env_default = pwm_0_2 -#env_default = unit_test_native +#env_default = mppt-2420-lc-v0.10 +#env_default = mppt-1210-hus-v0.2 +#env_default = mppt-1210-hus-v0.4 +#env_default = mppt-1210-hus-v0.6 +#env_default = pwm-2420-lus-v0.1 +#env_default = pwm-2420-lus-v0.2 +#env_default = unit-test-native [common] @@ -46,94 +45,82 @@ lib_ignore = USB, mbed-USBDevice, mbed-mbedtls #### BOARD DEFINITIONS ######################################################## -# https://github.com/LibreSolar/MPPT-Charger_20A/tree/0a19fcb8f3 -[env:libresolar_0_05] +# https://github.com/LibreSolar/MPPT-2420-LC/tree/5bc39183c8 +[env:mppt-2420-lc-v0.10] platform = ${common.platform} framework = mbed board = nucleo_f072rb upload_protocol = ${common.upload_protocol} monitor_speed = ${common.monitor_speed} build_flags = ${common.build_flags} - -D PCB_LS_005=1 + -D MPPT_2420_LC_0V10 lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -# https://github.com/LibreSolar/MPPT-Charger_20A/tree/5bc39183c8 -[env:libresolar_0_10] +# https://github.com/LibreSolar/MPPT-1210-HUS/tree/586626f3d8 +[env:mppt-1210-hus-v0.2] platform = ${common.platform} framework = mbed board = nucleo_f072rb upload_protocol = ${common.upload_protocol} monitor_speed = ${common.monitor_speed} build_flags = ${common.build_flags} - -D PCB_LS_010=1 + -D MPPT_1210_HUS_0V2 lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -# https://github.com/LibreSolar/MPPT-Charger_10A/tree/586626f3d8 -[env:cloudsolar_0_2] -platform = ${common.platform} -framework = mbed -board = nucleo_f072rb -upload_protocol = ${common.upload_protocol} -monitor_speed = ${common.monitor_speed} -build_flags = ${common.build_flags} - -D PCB_CS_02=1 -lib_deps = ${common.lib_deps} -lib_ignore = ${common.lib_ignore} - -# https://github.com/LibreSolar/MPPT-Charger_10A/tree/63e5842671 -[env:cloudsolar_0_4] +# https://github.com/LibreSolar/MPPT-1210-HUS/tree/63e5842671 +[env:mppt-1210-hus-v0.4] platform = ${common.platform} framework = mbed board = nucleo_l073rz upload_protocol = ${common.upload_protocol} monitor_speed = ${common.monitor_speed} build_flags = ${common.build_flags} - -D PCB_CS_04=1 + -D MPPT_1210_HUS_0V4 lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -[env:cloudsolar_0_6] +[env:mppt-1210-hus-v0.6] platform = ${common.platform} framework = mbed board = nucleo_l073rz upload_protocol = ${common.upload_protocol} monitor_speed = ${common.monitor_speed} build_flags = ${common.build_flags} - -D PCB_CS_06=1 + -D MPPT_1210_HUS_0V6 lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} # initial test version (obsolete) -[env:pwm_0_1] +[env:pwm-2420-lus-v0.1] platform = ${common.platform} framework = mbed board = nucleo_l073rz upload_protocol = ${common.upload_protocol} monitor_speed = ${common.monitor_speed} build_flags = ${common.build_flags} - -D PCB_PWM_01=1 + -D PWM_2420_LUS_0V1 lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -# https://github.com/LibreSolar/PWM-Charger_20A -[env:pwm_0_2] +# https://github.com/LibreSolar/PWM-2420-LUS +[env:pwm-2420-lus-v0.2] platform = ${common.platform} framework = mbed board = nucleo_l073rz upload_protocol = ${common.upload_protocol} monitor_speed = ${common.monitor_speed} build_flags = ${common.build_flags} - -D PCB_PWM_02=1 + -D PWM_2420_LUS_0V2 lib_deps = ${common.lib_deps} lib_ignore = ${common.lib_ignore} -[env:unit_test_native] +[env:unit-test-native] platform = native build_flags = -D LITTLE_ENDIAN -D UNIT_TEST # include src directory (otherwise unit-tests will only include lib directory) test_build_project_src = true -lib_ignore = USB, mbed-USBDevice, mbed-mbedtls, USBSerial, ESP32, Adafruit_GFX \ No newline at end of file +lib_ignore = USB, mbed-USBDevice, mbed-mbedtls, USBSerial, ESP32, Adafruit_GFX diff --git a/src/pcb.h b/src/pcb.h index 8ac6ccc..f429714 100644 --- a/src/pcb.h +++ b/src/pcb.h @@ -63,20 +63,18 @@ // specific board settings /////////////////////////////////////////////////////////////////////////////// -#if defined(PCB_LS_005) - #include "pcbs/pcb_ls_005.h" -#elif defined(PCB_LS_010) - #include "pcbs/pcb_ls_010.h" -#elif defined(PCB_CS_02) - #include "pcbs/pcb_cs_02.h" -#elif defined(PCB_CS_04) - #include "pcbs/pcb_cs_04.h" -#elif defined(PCB_CS_06) - #include "pcbs/pcb_cs_06.h" -#elif defined(PCB_PWM_01) - #include "pcbs/pcb_pwm_01.h" -#elif defined(PCB_PWM_02) - #include "pcbs/pcb_pwm_02.h" +#if defined(MPPT_2420_LC_0V10) + #include "pcbs/mppt_2420_lc_0v10.h" +#elif defined(MPPT_1210_HUS_0V2) + #include "pcbs/mppt_1210_hus_0v2.h" +#elif defined(MPPT_1210_HUS_0V4) + #include "pcbs/mppt_1210_hus_0v4.h" +#elif defined(MPPT_1210_HUS_0V6) + #include "pcbs/mppt_1210_hus_0v6.h" +#elif defined(PWM_2420_LUS_0V1) + #include "pcbs/pwm_2420_lus_0v1.h" +#elif defined(PWM_2420_LUS_0V2) + #include "pcbs/pwm_2420_lus_0v2.h" #elif defined(UNIT_TEST) #include "pcbs/pcb_stub.h" #else diff --git a/src/pcbs/pcb_cs_02.h b/src/pcbs/mppt_1210_hus_0v2.h similarity index 95% rename from src/pcbs/pcb_cs_02.h rename to src/pcbs/mppt_1210_hus_0v2.h index 0b28e35..2c452d2 100644 --- a/src/pcbs/pcb_cs_02.h +++ b/src/pcbs/mppt_1210_hus_0v2.h @@ -1,5 +1,5 @@ -/* LibreSolar MPPT charge controller firmware - * Copyright (c) 2016-2017 Martin Jäger (www.libre.solar) +/* LibreSolar charge controller firmware + * Copyright (c) 2016-2019 Martin Jäger (www.libre.solar) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __PCB_CS_02_H_ -#define __PCB_CS_02_H_ +#ifndef MPPT_1210_HUS_0V2_H +#define MPPT_1210_HUS_0V2_H #include "mbed.h" diff --git a/src/pcbs/pcb_cs_04.h b/src/pcbs/mppt_1210_hus_0v4.h similarity index 95% rename from src/pcbs/pcb_cs_04.h rename to src/pcbs/mppt_1210_hus_0v4.h index 3636472..13f0e87 100644 --- a/src/pcbs/pcb_cs_04.h +++ b/src/pcbs/mppt_1210_hus_0v4.h @@ -1,5 +1,5 @@ -/* LibreSolar MPPT charge controller firmware - * Copyright (c) 2016-2018 Martin Jäger (www.libre.solar) +/* LibreSolar charge controller firmware + * Copyright (c) 2016-2019 Martin Jäger (www.libre.solar) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __PCB_CS_04_H_ -#define __PCB_CS_04_H_ +#ifndef MPPT_1210_HUS_0V4_H +#define MPPT_1210_HUS_0V4_H #include "mbed.h" diff --git a/src/pcbs/pcb_cs_06.h b/src/pcbs/mppt_1210_hus_0v6.h similarity index 95% rename from src/pcbs/pcb_cs_06.h rename to src/pcbs/mppt_1210_hus_0v6.h index ea6cab6..828a469 100644 --- a/src/pcbs/pcb_cs_06.h +++ b/src/pcbs/mppt_1210_hus_0v6.h @@ -1,5 +1,5 @@ -/* LibreSolar MPPT charge controller firmware - * Copyright (c) 2016-2018 Martin Jäger (www.libre.solar) +/* LibreSolar charge controller firmware + * Copyright (c) 2016-2019 Martin Jäger (www.libre.solar) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __PCB_CS_06_H_ -#define __PCB_CS_06_H_ +#ifndef MPPT_1210_HUS_0V6_H +#define MPPT_1210_HUS_0V6_H #include "mbed.h" diff --git a/src/pcbs/pcb_ls_010.h b/src/pcbs/mppt_2420_lc_0v10.h similarity index 95% rename from src/pcbs/pcb_ls_010.h rename to src/pcbs/mppt_2420_lc_0v10.h index 35be0db..ff57dac 100644 --- a/src/pcbs/pcb_ls_010.h +++ b/src/pcbs/mppt_2420_lc_0v10.h @@ -1,5 +1,5 @@ -/* LibreSolar MPPT charge controller firmware - * Copyright (c) 2016-2017 Martin Jäger (www.libre.solar) +/* LibreSolar charge controller firmware + * Copyright (c) 2016-2019 Martin Jäger (www.libre.solar) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __CONFIG_LS_10_H_ -#define __CONFIG_LS_10_H_ +#ifndef MPPT_2420_LC_0V10_H +#define MPPT_2420_LC_0V10_H #include "mbed.h" diff --git a/src/pcbs/pcb_ls_005.h b/src/pcbs/pcb_ls_005.h deleted file mode 100644 index d96f7a0..0000000 --- a/src/pcbs/pcb_ls_005.h +++ /dev/null @@ -1,100 +0,0 @@ -/* LibreSolar MPPT charge controller firmware - * Copyright (c) 2016-2017 Martin Jäger (www.libre.solar) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __CONFIG_LS_05_H_ -#define __CONFIG_LS_05_H_ - -#include "mbed.h" - -// DC/DC converter settings -#define PWM_FREQUENCY 70 // kHz 70 = good compromise between output ripple and efficiency -#define PWM_TIM 1 // use TIM1 timer - -#define DCDC_CURRENT_MAX 12 // PCB maximum DCDC output current -#define LOAD_CURRENT_MAX 12 // PCB maximum load switch current - -#define PIN_UEXT_TX PA_2 -#define PIN_UEXT_RX PA_3 -#define PIN_UEXT_SCL PB_6 -#define PIN_UEXT_SDA PB_7 -#define PIN_UEXT_MISO PB_4 -#define PIN_UEXT_MOSI PB_5 -#define PIN_UEXT_SCK PB_3 -#define PIN_UEXT_SSEL PA_1 - -#define PIN_SWD_TX PB_10 -#define PIN_SWD_RX PB_11 -/* -#define PIN_LED_PWR PA_9 -#define PIN_LED_DCDC PA_10 -#define PIN_LED_LOAD PB_12 -*/ -#define PIN_LOAD_DIS PB_2 - -#define PIN_CAN_RX PB_8 -#define PIN_CAN_TX PB_9 - -enum pin_state_t { PIN_HIGH, PIN_LOW, PIN_FLOAT }; - -// assignment LED numbers on PCB to their meaning -#define NUM_LEDS 3 - -#define LED_PWR 0 // LED1 -#define LED_DCDC 1 // LED2 -#define LED_LOAD 2 // LED3 - -// LED pins and pin state configuration to switch above LEDs on -#define NUM_LED_PINS 3 -static const PinName led_pins[NUM_LED_PINS] = { - // PWR DCDC LOAD - PA_9, PA_10, PB_12 -}; -static const pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = { - { PIN_HIGH, PIN_LOW, PIN_LOW }, // LED1 - { PIN_LOW, PIN_HIGH, PIN_LOW }, // LED2 - { PIN_LOW, PIN_LOW, PIN_HIGH } // LED3 -}; - -// typical value for Semitec 103AT-5 thermistor: 3435 -#define NTC_BETA_VALUE 3435 - -#define ADC_GAIN_V_BAT (130.0 / 10 ) // battery voltage divider 120k + 10k -#define ADC_GAIN_V_SOLAR (156.8 / 6.8) // solar voltage divider: 150k + 6.kk -#define ADC_GAIN_I_LOAD (1000 / 5 / 50) // amp gain: 50, resistor: 5 mOhm -#define ADC_GAIN_I_DCDC (1000 / 5 / 50) - -// position in the array written by the DMA controller -enum { - ADC_POS_V_BAT, // ADC 4 (PA_4) - ADC_POS_V_SOLAR, // ADC 5 (PA_5) - ADC_POS_I_LOAD, // ADC 6 (PA_6) - ADC_POS_I_DCDC, // ADC 7 (PA_7) - ADC_POS_TEMP_MCU, // ADC 16 - ADC_POS_VREF_MCU, // ADC 17 - NUM_ADC_CH // trick to get the number of enums -}; - -// selected ADC channels (has to match with above enum) -#define ADC_CHSEL ( \ - ADC_CHSELR_CHSEL4 | \ - ADC_CHSELR_CHSEL5 | \ - ADC_CHSELR_CHSEL6 | \ - ADC_CHSELR_CHSEL7 | \ - ADC_CHSELR_CHSEL16 | \ - ADC_CHSELR_CHSEL17 \ -) - -#endif diff --git a/src/pcbs/pcb_stub.h b/src/pcbs/pcb_stub.h index 764878e..3cb4f44 100644 --- a/src/pcbs/pcb_stub.h +++ b/src/pcbs/pcb_stub.h @@ -1,5 +1,5 @@ -/* LibreSolar MPPT charge controller firmware - * Copyright (c) 2016-2018 Martin Jäger (www.libre.solar) +/* LibreSolar charge controller firmware + * Copyright (c) 2016-2019 Martin Jäger (www.libre.solar) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __PCB_PWM_02_H_ -#define __PCB_PWM_02_H_ +#ifndef PCB_STUB_H +#define PCB_STUB_H #define PWM_TIM 3 // use TIM3 timer diff --git a/src/pcbs/pcb_pwm_01.h b/src/pcbs/pwm_2420_lus_0v1.h similarity index 90% rename from src/pcbs/pcb_pwm_01.h rename to src/pcbs/pwm_2420_lus_0v1.h index caa47ac..82e7cc7 100644 --- a/src/pcbs/pcb_pwm_01.h +++ b/src/pcbs/pwm_2420_lus_0v1.h @@ -1,5 +1,5 @@ -/* LibreSolar MPPT charge controller firmware - * Copyright (c) 2016-2018 Martin Jäger (www.libre.solar) +/* LibreSolar charge controller firmware + * Copyright (c) 2016-2019 Martin Jäger (www.libre.solar) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __PCB_PWM_01_H_ -#define __PCB_PWM_01_H_ +#ifndef PWM_2420_LUS_0V1_H +#define PWM_2420_LUS_0V1_H #include "mbed.h" @@ -40,6 +40,7 @@ #define PIN_LOAD_DIS PB_2 #define PIN_USB_PWR_DIS PB_5 +#define PIN_I_LOAD_COMP PB_4 #define PIN_REF_I_DCDC PA_4 @@ -79,8 +80,8 @@ static const pin_state_t led_pin_setup[NUM_LEDS][NUM_LED_PINS] = { #define ADC_GAIN_V_BAT (132 / 12) #define ADC_GAIN_V_SOLAR (1 + 120/12 + 120/8.2) -#define ADC_GAIN_I_LOAD (1000 / 2 / (150/2.2)) // amp gain: 150/2.2, resistor: 2 mOhm -#define ADC_GAIN_I_SOLAR (1000 / 2 / (150/2.2)) +#define ADC_GAIN_I_LOAD (1000 / 2 / (68.0/2.2)) // amp gain: 150/2.2, resistor: 2 mOhm +#define ADC_GAIN_I_SOLAR (1000 / 2 / (68.0/2.2)) #define ADC_OFFSET_V_SOLAR (-120.0 / 8.2) // to be multiplied with VDDA to get absolute voltage offset diff --git a/src/pcbs/pcb_pwm_02.h b/src/pcbs/pwm_2420_lus_0v2.h similarity index 95% rename from src/pcbs/pcb_pwm_02.h rename to src/pcbs/pwm_2420_lus_0v2.h index 6033d2f..2b4b3f4 100644 --- a/src/pcbs/pcb_pwm_02.h +++ b/src/pcbs/pwm_2420_lus_0v2.h @@ -1,5 +1,5 @@ -/* LibreSolar MPPT charge controller firmware - * Copyright (c) 2016-2018 Martin Jäger (www.libre.solar) +/* LibreSolar charge controller firmware + * Copyright (c) 2016-2019 Martin Jäger (www.libre.solar) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __PCB_PWM_02_H_ -#define __PCB_PWM_02_H_ +#ifndef PWM_2420_LUS_0V2_H +#define PWM_2420_LUS_0V2_H #include "mbed.h"