diff --git a/.github/workflows/zephyr.yml b/.github/workflows/zephyr.yml index 46c3240..5774f7a 100644 --- a/.github/workflows/zephyr.yml +++ b/.github/workflows/zephyr.yml @@ -29,6 +29,11 @@ jobs: west update pip3 install -r rtos/scripts/requirements-base.txt + - name: Trailing whitespace check + working-directory: charge-controller-firmware + run: | + git diff --check `git rev-list --max-parents=0 HEAD`..HEAD + - name: Build firmware working-directory: charge-controller-firmware run: | diff --git a/README.md b/README.md index 3fa6ae4..a336593 100644 --- a/README.md +++ b/README.md @@ -35,25 +35,9 @@ git clone --recursive https://github.com/LibreSolar/charge-controller-firmware Unfortunately, the green GitHub "Clone or download" button does not include submodules. If you cloned the repository already and want to pull the submodules, run `git submodule update --init --recursive`. -### PlatformIO +Building the firmware requires the native Zephyr build system. -It is suggested to use Visual Studio Code and PlatformIO for firmware development, as it simplifies compiling and uploading the code a lot: - -1. Install Visual Studio Code and [PlatformIO](https://platformio.org/platformio-ide) to build the firmware. - -2. Adjust configuration in `zephyr/prj.conf` if necessary. - -3. Select the correct board in `platformio.ini` by removing the comment before the board name under `[platformio]` or create a file `custom.ini` with your personal settings. PlatformIO is configured for latest revision of the boards (see table above). For older revisions adjust `platformio.ini` and the `.json` files in `boards` folder manually or use native Zephyr environment. - -4. Connect the board via a programmer. See the Libre Solar website for [further project-agnostic instructions](http://libre.solar/docs/flashing). - -5. Press the upload button at the bottom left corner in VS Code. - -### Native Zephyr environment - -You can also use the Zephyr build system directly for advanced configuration with `menuconfig` or if you need more recently added features. - -This guide assumes you have already installed the Zephyr SDK and the west tool according to the [Zephyr documentation](https://docs.zephyrproject.org/latest/getting_started/). Also make sure that `west` is at least at version `0.8.0`. +This guide assumes you have already installed the Zephyr SDK and the west tool according to the [Zephyr documentation](https://docs.zephyrproject.org/latest/getting_started/). Now after you cloned the repository (see above), go into the root firmware directory and initialize a west workspace: @@ -162,12 +146,6 @@ Core functions of the firmware are covered by unit-tests (located in `tests` dir cd tests west build -p -b native_posix -t run -### Static code analysis - -PlatformIO integrates cppcheck and clangtidy. The following command is an example to run the checks for MPPT 1210 HUS charge controller code: - - platformio check -e mppt_1210_hus - ## Additional firmware documentation (docs folder) - [Charge controller basic concepts](docs/charger-concepts.md) @@ -182,28 +160,6 @@ The standard OpenOCD settings sometimes fail to flash firmware to this MCU, whic Try one of these workarounds: -1. Change OpenOCD settings to `adapter_khz 500` in line 70 in `~/.platformio/packages/tool-openocd/scripts/target/stm32l0.cfg`. +1. Change OpenOCD settings to `adapter_khz 500` in `openocd-path/scripts/target/stm32l0.cfg`. 2. Use other tools or debug probes such as [STM32CubeProgrammer](https://www.st.com/en/development-tools/stm32cubeprog.html) or [Segger J-Link](https://www.segger.com/products/debug-probes/j-link/). - -### Connection failures - -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 .pio/build/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 programmer (for example the ST-Link of the Nucleo board) and the charge controller. diff --git a/boards/README.md b/boards/README.md deleted file mode 100644 index 6d27284..0000000 --- a/boards/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# Configuration of supported boards - -## Zephyr board definition - -The definitions found in `boards/arm/my-board/` folders are used directly by Zephyr. - -More detiails can be found in Zephyr -[porting guide](https://docs.zephyrproject.org/latest/guides/porting/board_porting.html) and -[Kconfig description](https://docs.zephyrproject.org/latest/guides/kconfig/setting.html#the-initial-configuration). - -- `board.cmake`, `CMakeLists.txt`: CMake definitions for board, normally don't need to be touched. -- `Kconfig.board`: Defines the name of the board as used in DTS config. -- `Kconfig.defconfig`: Configuration of invisible Kconfig symbols, i.e. symbols that should not be adjustable by the user via menuconfig. -- `_defconfig`: Default configuration of the board (can be overwritten by prj.conf) -- `.dts`: Main board device tree specification. -- `.yaml`: -- `pinmux.c`: Defines which pins should be used for peripherals like SPI1, SPI2, SPI3 if selected by the user. - -## PlatformIO configuration - -PlatformIO needs an additional definition file for each board. It is stored as `boards/my-board.json` diff --git a/boards/mppt_1210_hus@0.7.json b/boards/mppt_1210_hus@0.7.json deleted file mode 100644 index b4e2b8f..0000000 --- a/boards/mppt_1210_hus@0.7.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "build": { - "cpu": "cortex-m0plus", - "extra_flags": "-DSTM32L072xx", - "f_cpu": "32000000L", - "framework_extra_flags": { - "arduino": "-D__CORTEX_SC=0" - }, - "mcu": "stm32l072rz", - "variant": "MPPT-1210-HUS" - }, - "debug": { - "default_tools": [ - "stlink" - ], - "jlink_device": "STM32L072RZ", - "onboard_tools": [ - "stlink" - ], - "openocd_board": "st_nucleo_l073rz", - "svd_path": "STM32L07x.svd" - }, - "frameworks": [ - "arduino", - "mbed", - "stm32cube", - "zephyr" - ], - "name": "Libre Solar MPPT 1210 HUS", - "upload": { - "maximum_ram_size": 20480, - "maximum_size": 196608, - "protocol": "stlink", - "protocols": [ - "jlink", - "stlink", - "blackmagic", - "mbed" - ] - }, - "url": "http://libre.solar/", - "vendor": "Libre Solar" -} diff --git a/boards/mppt_2420_hc@0.2.json b/boards/mppt_2420_hc@0.2.json deleted file mode 100644 index bf14c5a..0000000 --- a/boards/mppt_2420_hc@0.2.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "build": { - "cpu": "cortex-m4", - "extra_flags": "-DSTM32G4xx -DSTM32G431xx", - "f_cpu": "150000000L", - "mcu": "stm32g431rb", - "variant": "MPPT-2420-HC" - }, - "connectivity": [ - "can" - ], - "debug": { - "default_tools": [ - "jlink" - ], - "jlink_device": "STM32G431RB", - "onboard_tools": [ - "stlink" - ], - "openocd_board": "st_nucleo_g431rb", - "svd_path": "STM32G431xx.svd" - }, - "frameworks": [ - "arduino", - "stm32cube", - "zephyr" - ], - "name": "Libre Solar MPPT 2420 HC", - "upload": { - "maximum_ram_size": 32768, - "maximum_size": 131072, - "protocol": "jlink", - "protocols": [ - "jlink", - "stlink", - "blackmagic", - "mbed" - ] - }, - "url": "https://libre.solar/", - "vendor": "Libre Solar" -} diff --git a/boards/mppt_2420_hpx.json b/boards/mppt_2420_hpx.json deleted file mode 100644 index f3a9d32..0000000 --- a/boards/mppt_2420_hpx.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "build": { - "cpu": "cortex-m4", - "extra_flags": "-DSTM32G4xx -DSTM32G431xx", - "f_cpu": "150000000L", - "mcu": "stm32g431rb", - "variant": "MPPT-2420-HPX" - }, - "connectivity": [ - "can" - ], - "debug": { - "default_tools": [ - "jlink" - ], - "jlink_device": "STM32G431RB", - "onboard_tools": [ - "stlink" - ], - "openocd_board": "st_nucleo_g431rb", - "svd_path": "STM32G431xx.svd" - }, - "frameworks": [ - "arduino", - "stm32cube", - "zephyr" - ], - "name": "Libre Solar MPPT 2420 HPX", - "upload": { - "maximum_ram_size": 32768, - "maximum_size": 131072, - "protocol": "jlink", - "protocols": [ - "jlink", - "stlink", - "blackmagic", - "mbed" - ] - }, - "url": "http://libre.solar/", - "vendor": "Libre Solar" -} diff --git a/boards/mppt_2420_lc.json b/boards/mppt_2420_lc.json deleted file mode 100644 index a36a753..0000000 --- a/boards/mppt_2420_lc.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "build": { - "cpu": "cortex-m0", - "extra_flags": "-DSTM32F072xB", - "f_cpu": "48000000L", - "mcu": "stm32f072rbt6" - }, - "connectivity": [ - "can" - ], - "debug": { - "default_tools": [ - "stlink" - ], - "jlink_device": "STM32F072RB", - "onboard_tools": [ - "stlink" - ], - "openocd_board": "st_nucleo_f0", - "svd_path": "STM32F072x.svd" - }, - "frameworks": [ - "mbed", - "stm32cube", - "zephyr" - ], - "name": "Libre Solar MPPT 2420 LC", - "upload": { - "maximum_ram_size": 16384, - "maximum_size": 131072, - "protocol": "stlink", - "protocols": [ - "jlink", - "stlink", - "blackmagic", - "mbed" - ] - }, - "url": "http://libre.solar/", - "vendor": "Libre Solar" -} \ No newline at end of file diff --git a/boards/mppt_2420_rc.json b/boards/mppt_2420_rc.json deleted file mode 100644 index 3e8ca81..0000000 --- a/boards/mppt_2420_rc.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "build": { - "cpu": "cortex-m4", - "extra_flags": "-DSTM32G4xx -DSTM32G431xx", - "f_cpu": "150000000L", - "mcu": "stm32g431rb", - "variant": "MPPT-2420-RC" - }, - "connectivity": [ - "can" - ], - "debug": { - "default_tools": [ - "jlink" - ], - "jlink_device": "STM32G431RB", - "onboard_tools": [ - "stlink" - ], - "openocd_board": "st_nucleo_g431rb", - "svd_path": "STM32G431xx.svd" - }, - "frameworks": [ - "arduino", - "stm32cube", - "zephyr" - ], - "name": "Libre Solar MPPT 2420 RC", - "upload": { - "maximum_ram_size": 32768, - "maximum_size": 131072, - "protocol": "jlink", - "protocols": [ - "jlink", - "stlink", - "blackmagic", - "mbed" - ] - }, - "url": "http://libre.solar/", - "vendor": "Libre Solar" -} diff --git a/boards/nucleo_g474re.json b/boards/nucleo_g474re.json deleted file mode 100644 index 90012cd..0000000 --- a/boards/nucleo_g474re.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "build": { - "core": "stm32", - "cpu": "cortex-m4", - "extra_flags": "-DSTM32G4xx -DSTM32G474xx", - "f_cpu": "170000000L", - "mcu": "stm32g474ret6", - "product_line": "STM32G474xx", - "variant": "NUCLEO_G474RE" - }, - "connectivity": [ - "can" - ], - "debug": { - "jlink_device": "STM32G474RE", - "openocd_target": "stm32g4x", - "svd_path": "STM32G474xx.svd" - }, - "frameworks": [ - "arduino", - "cmsis", - "mbed", - "libopencm3", - "stm32cube", - "zephyr" - ], - "name": "Nucleo G474RE", - "upload": { - "maximum_ram_size": 131072, - "maximum_size": 524288, - "protocol": "mbed", - "protocols": [ - "jlink", - "stlink", - "cmsis-dap", - "blackmagic", - "mbed" - ] - }, - "url": "https://www.st.com/en/evaluation-tools/nucleo-g474re.html", - "vendor": "ST" -} diff --git a/boards/pwm_2420_lus@0.3.json b/boards/pwm_2420_lus@0.3.json deleted file mode 100644 index 93daa48..0000000 --- a/boards/pwm_2420_lus@0.3.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "build": { - "cpu": "cortex-m0plus", - "extra_flags": "-DSTM32L072xx", - "f_cpu": "32000000L", - "framework_extra_flags": { - "arduino": "-D__CORTEX_SC=0" - }, - "mcu": "stm32l072rz", - "variant": "PWM-2420-LUS" - }, - "debug": { - "default_tools": [ - "stlink" - ], - "jlink_device": "STM32L072RZ", - "onboard_tools": [ - "stlink" - ], - "openocd_board": "st_nucleo_l073rz", - "svd_path": "STM32L07x.svd" - }, - "frameworks": [ - "arduino", - "mbed", - "stm32cube", - "zephyr" - ], - "name": "Libre Solar PWM 2420 LUS", - "upload": { - "maximum_ram_size": 20480, - "maximum_size": 196608, - "protocol": "stlink", - "protocols": [ - "jlink", - "stlink", - "blackmagic", - "mbed" - ] - }, - "url": "http://libre.solar/", - "vendor": "Libre Solar" -} diff --git a/platformio.ini b/platformio.ini deleted file mode 100644 index 4b1df62..0000000 --- a/platformio.ini +++ /dev/null @@ -1,94 +0,0 @@ -# -# Project Configuration File -# -# A detailed documentation with the EXAMPLES is located here: -# http://docs.platformio.org/en/latest/projectconf.html -# - -[platformio] - -# Choose one of below charge controller board envs as default, e.g. mppt_2420_hc -default_envs = - -# Or create your own custom.ini file to overwrite settings in this file, e.g. for board selection. -# For further information see here: -# https://docs.platformio.org/en/latest/projectconf/section_platformio.html#extra-configs -extra_configs = - custom.ini - -[env] - -framework = zephyr - -#platform = https://github.com/platformio/platform-ststm32.git -platform = ststm32@~14.1.0 - -# Use customized Zephyr branch from Libre Solar repository -platform_packages = - toolchain-gccarmnoneeabi@1.90301.200702 -# framework-zephyr@https://github.com/LibreSolar/zephyr#v2.6-branch - -#upload_protocol = mbed -upload_protocol = stlink -#upload_protocol = jlink - -#debug_tool = jlink - -# Custom Serial Monitor baud rate -monitor_speed = 115200 - -# Compiler settings -build_flags = - -std=gnu++17 - -fsingle-precision-constant - -Wl,-Map,memory.map - -# Below flags are only valid for C++ and create warnings for C files, so we add them as -# CXXFLAGS in extra_script. -build_unflags = -Wno-register -fno-rtti -extra_scripts = scripts/platformio-extra.py - -check_tool = cppcheck, clangtidy -check_flags = - cppcheck: --enable=warning,style,performance,portability,information,missingInclude -j 7 --inline-suppr -# --addon=addons/misra.py --addon=addons/cert.py - clangtidy: --checks=-*,cert-*,clang-analyzer-*,bugprone-*,misc-*,performance-*,readability-*,-readability-magic-numbers,-cert-err58-cpp - -lib_deps = - https://github.com/LibreSolar/thingset-device-library.git - -#### BOARD DEFINITIONS ######################################################## - -# You can specify a specific version by adding e.g. @0.2 to the board name -# (see https://docs.zephyrproject.org/latest/guides/porting/board_porting.html for details) - -# PlatformIO requires a .json file with the same name in boards/ directory. If not existing for -# a particular board revision, just copy it from an existing different revision - -# https://github.com/LibreSolar/mppt-2420-lc -[env:mppt_2420_lc] -board = mppt_2420_lc - -# https://github.com/LibreSolar/mppt-2420-rc -[env:mppt_2420_rc] -board = mppt_2420_rc - -# https://github.com/LibreSolar/mppt-2420-hc -[env:mppt_2420_hc] -board = mppt_2420_hc@0.2 - -# https://github.com/LibreSolar/mppt-1210-hus -[env:mppt_1210_hus] -board = mppt_1210_hus@0.7 - -# https://github.com/LibreSolar/mppt-2420-hpx -[env:mppt_2420_hpx] -board = mppt_2420_hpx - -# https://github.com/LibreSolar/pwm-2420-lus -[env:pwm_2420_lus] -board = pwm_2420_lus@0.3 - -# Nucleo board for testing purposes -[env:nucleo_g474re] -board = nucleo_g474re diff --git a/scripts/check.bat b/scripts/check.bat index e354925..e540f96 100644 --- a/scripts/check.bat +++ b/scripts/check.bat @@ -2,12 +2,14 @@ :: This file performs continuous integration checks and should be run before pushing new commits echo "---------- Trailing whitespace check -------------" + :: check uncommitted changes git diff --check HEAD if errorlevel 1 ( echo Failure Reason is %errorlevel% exit /b %errorlevel% ) + :: check all commits starting from initial commit for /F %i in ('"git rev-list --max-parents=0 HEAD"') do git diff --check %i..HEAD if errorlevel 1 ( @@ -16,24 +18,51 @@ if errorlevel 1 ( ) echo "---------- Running compile check -------------" -platformio run -e mppt_2420_lc -e mppt_1210_hus -e mppt_2420_hc -e pwm_2420_lus + +cd zephyr + +west build -b mppt_2420_hc@0.2 if errorlevel 1 ( echo Failure Reason is %errorlevel% exit /b %errorlevel% ) +west build -b mppt_2420_lc +if errorlevel 1 ( + echo Failure Reason is %errorlevel% + exit /b %errorlevel% +) + +west build -b mppt_1210_hus@0.7 +if errorlevel 1 ( + echo Failure Reason is %errorlevel% + exit /b %errorlevel% +) + +west build -b pwm_2420_lus@0.3 +if errorlevel 1 ( + echo Failure Reason is %errorlevel% + exit /b %errorlevel% +) + +cd .. + echo "---------- Running unit-tests -------------" -platformio test -e unit_test -if errorlevel 1 ( - echo Failure Reason is %errorlevel% - exit /b %errorlevel% -) -echo "---------- Running static code checks -------------" -platformio check -e mppt_1210_hus -e pwm_2420_lus --skip-packages --fail-on-defect high +cd tests +west build -b native_posix -t run if errorlevel 1 ( echo Failure Reason is %errorlevel% exit /b %errorlevel% ) +cd .. + +:: echo "---------- Running static code checks -------------" + +:: platformio check -e mppt_1210_hus -e pwm_2420_lus --skip-packages --fail-on-defect high +:: if errorlevel 1 ( +:: echo Failure Reason is %errorlevel% +:: exit /b %errorlevel% +:: ) echo "---------- All tests passed -------------" diff --git a/scripts/check.sh b/scripts/check.sh index c8515bc..1de8e66 100755 --- a/scripts/check.sh +++ b/scripts/check.sh @@ -3,34 +3,37 @@ # This file performs continuous integration checks and should be run before pushing new commits # +# exit when any command fails +set -e + +# use board-specific directory +west config build.dir-fmt "build/{board}" + echo "---------- Trailing whitespace check -------------" + # check uncommitted changes git diff --check HEAD -if [ $? != 0 ]; then - exit 1; -fi + # check all commits starting from initial commit git diff --check `git rev-list --max-parents=0 HEAD`..HEAD -if [ $? != 0 ]; then - exit 1; -fi echo "---------- Running compile check -------------" -platformio run -e mppt_2420_lc -e mppt_1210_hus -e mppt_2420_hc -e pwm_2420_lus -if [ $? != 0 ]; then - exit 1; -fi + +cd zephyr +west build -b mppt_2420_hc@0.2 +west build -b mppt_2420_lc +west build -b mppt_1210_hus@0.7 +west build -b pwm_2420_lus@0.3 +cd .. echo "---------- Running unit-tests -------------" -platformio test -e unit_test -if [ $? != 0 ]; then - exit 1; -fi -echo "---------- Running static code checks -------------" -platformio check -e mppt_1210_hus -e pwm_2420_lus --skip-packages --fail-on-defect high -if [ $? != 0 ]; then - exit 1; -fi +cd tests +west build -b native_posix -t run +cd .. + +#echo "---------- Running static code checks -------------" + +#platformio check -e mppt_1210_hus -e pwm_2420_lus --skip-packages --fail-on-defect high echo "---------- All tests passed -------------" diff --git a/scripts/platformio-extra.py b/scripts/platformio-extra.py deleted file mode 100644 index 3a5d8de..0000000 --- a/scripts/platformio-extra.py +++ /dev/null @@ -1,8 +0,0 @@ - -# Custom settings, as referred to as "extra_script" in platformio.ini -# -# See http://docs.platformio.org/en/latest/projectconf.html#extra-script - -Import("env") - -env.Append( CXXFLAGS=[ "-Wno-register -fno-rtti" ] ) diff --git a/tests/src/tests.h b/tests/src/tests.h index 2ceb3e2..8ebea20 100644 --- a/tests/src/tests.h +++ b/tests/src/tests.h @@ -21,7 +21,6 @@ int device_status_tests(); int load_tests(); -// activate this via build_flags in platformio.ini or custom.ini -#ifdef CUSTOM_TESTS +#ifdef CONFIG_CUSTOM_TESTS int custom_tests(); #endif