From 7769e4063c418faafd5d2f98f8fbfaafcaaef3f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Thu, 4 Jun 2020 11:15:30 +0200 Subject: [PATCH] Allow more generic firmware customization This commit adds a new Kconfig setting CONFIG_CUSTOMIZATION. If enabled, the subdirectory src/custom is added to the build. It can contain an own CMakeLists.txt file to add several different C/C++ files. Readme has been updated to explain also DTS overlays and custom prj.conf files. --- README.md | 30 ++++++++++++++++++++++++++++++ boards/Kconfig | 26 ++++++++++++++++++++------ zephyr/CMakeLists.txt | 6 ++++++ 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a6ebe64..a2b862d 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,36 @@ st-flash 1.5.1 check the connection between the programmer (for example the ST-Link of the Nucleo board) and the charge controller. +## Firmware customization + +This firmware is developed to allow easy customization for individual use-cases. Below options based on the Zephyr devicetree and Kconfig systems try to allow customization without changing any of the files tracked by git, so that a `git pull` does not lead to conflicts with local changes. + +### Hardware-specific changes + +In Zephyr, all hardware-specific configuration is described in the [devicetree](https://docs.zephyrproject.org/latest/guides/dts/index.html). + +The file `boards/arm/board_name/board_name.dts` contains the default devicetree specification (DTS) for a board. It is based on the DTS of the used MCU, which is included from the main Zephyr repository. + +In order to overwrite the default configuration, so-called overlays can be used. An overlay file can be specified via the west command line. If it is stored as `board_name.overlay` in the `zephyr` subfolder, it will be recognized automatically when building the firmware for that board (also with PlatformIO). + +In order to support older board versions (e.g. with changed pins), some overlays with appended version numbers are already existing as a template. Remove the version number (e.g. `_0v4`) to "activate" them. + +### Application firmware configuration + +For configuration of the application-specific features, Zephyr uses the [Kconfig system](https://docs.zephyrproject.org/latest/guides/kconfig/index.html). + +The configuration can be changed using `west build -t menuconfig` command or manually by changing the prj.conf file. + +Similar to DTS overlays, the Kconfig can also be customized for each board. Copy the default `prj.conf` to a file `prj_board_name.conf` to use this file instead of `prj.conf`. Please not that, in contrast to overlays, the board-specific Kconfig files are not **added** to the default `prj.conf`, but they **replace** the default configuration instead. + +### Custom functions (separate C/C++ files) + +If you want experiment with some completely new functions for the charge controller, new files should be stored in a subfolder `src/custom`. + +To add the files to the firmware build, create an own CMakeLists.txt in the folder and enable the Kconfig option `CONFIG_CUSTOMIZATION`. + +If you think the customization could be relevant for others, please consider sending a pull request. Integrating features into the upstream charge controller firmware guarantees that the feature stays up-to-date and that it will not accidentally break after changes in the original firmware. + ## Bootloader Support (STM32L072 only) The custom linker script file STM32L072XZ.ld.link_script.ld needs to be updated before generating the application firmware binary. For each application, the flash start address and the maximum code size need to be updated in this file. Currently, the locations 0x08001000 and 0x08018000 are used for applications 1 & 2 respectively. diff --git a/boards/Kconfig b/boards/Kconfig index ea1a760..89a3908 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -19,12 +19,6 @@ config LIBRE_SOLAR_TYPE_ID help Numeric Libre Solar hardware type ID -config CUSTOM_DATA_NODES_FILE - bool - default n - help - Use the custom made data_nodes file - # # Visible (user-configurable) Kconfig symbols # @@ -183,3 +177,23 @@ config THINGSET_MAKER_PASSWORD default "maker456" endmenu + + +menuconfig CUSTOMIZATION + bool "Firmware customization" + help + Activating this option allows to overwrite existing firmware functions + or add customizations independent of the master branch. + Custom implementations should be stored in the + src/custom subdirectory. + +if CUSTOMIZATION + +config CUSTOM_DATA_NODES_FILE + bool "Use custom data nodes file" + default n + help + Use a custom file instead of default data_nodes.cpp for + ThingSet configuration. + +endif diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index eece7da..d97ec5d 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -40,6 +40,12 @@ target_sources(app PRIVATE ../src/ext/can_msg_queue.cpp ) +# Using this option enables user-specific customization of the firmware. The +# src/custom subfolder should have its own CMakeLists.txt file. +if(${CONFIG_CUSTOMIZATION}) + add_subdirectory(../src/custom build/custom) +endif() + add_subdirectory(../lib/thingset build/thingset) add_subdirectory(../lib/oled-display build/oled-display) #add_subdirectory_ifdef(CONFIG_EXT_OLED_DISPLAY ../lib/oled-display)