### Basic CMake and Zephyr Setup Source: https://github.com/libresolar/charge-controller-firmware/blob/main/tests/CMakeLists.txt Initializes the CMake build system and finds the Zephyr RTOS. This is a standard setup for Zephyr-based projects. ```cmake cmake_minimum_required(VERSION 3.13.1) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(libre_solar_charge_controller) ``` -------------------------------- ### Build and Run Unit Tests Source: https://github.com/libresolar/charge-controller-firmware/blob/main/docs/src/dev/unit_tests.md Navigate to the tests directory and build the firmware with the native POSIX board, then run the tests. ```bash cd tests west build -p -b native_posix -t run ``` -------------------------------- ### Initialize New West Workspace Source: https://github.com/libresolar/charge-controller-firmware/blob/main/docs/src/dev/workspace_setup.md Use these commands to create a new west workspace and clone the charge controller firmware repository. This sets up the initial project structure and downloads necessary files. ```bash # create a new west workspace and pull the charge controller firmware west init -m https://github.com/LibreSolar/charge-controller-firmware west-workspace cd west-workspace/charge-controller-firmware # pull Zephyr upstream repository and modules (may take a while) west update ``` -------------------------------- ### Navigate to Application Directory Source: https://github.com/libresolar/charge-controller-firmware/blob/main/docs/src/dev/building_flashing.md Change the current directory to the 'app' subfolder, which contains the application source files and CMake entry point. ```bash cd app ``` -------------------------------- ### Switch to Release Branch and Update West Source: https://github.com/libresolar/charge-controller-firmware/blob/main/docs/src/dev/building_flashing.md Before building, switch to a stable release branch and update the West workspace. This ensures you are working with tested code. ```bash git switch -branch west update ``` -------------------------------- ### Build Firmware for Specific Board Source: https://github.com/libresolar/charge-controller-firmware/blob/main/docs/src/dev/building_flashing.md Build the firmware, specifying the target board and its revision. The revision can be omitted if only one version is available or the default is desired. ```bash west build -b @ ``` -------------------------------- ### Clone Repository Source: https://github.com/libresolar/charge-controller-firmware/blob/main/CONTRIBUTING.md Clone the Libre Solar charge controller firmware repository to your local machine. Replace 'your-github-username' and 'repository-name' with your GitHub username and the repository name. ```bash git clone https://github.com/your-github-username/repository-name.git ``` -------------------------------- ### Run Conformance Tests Locally Source: https://github.com/libresolar/charge-controller-firmware/blob/main/docs/src/dev/unit_tests.md Execute the check script to perform local conformance checks before pushing changes. Use check.bat on Windows. ```bash ./scripts/check.sh # use check.bat on Windows ``` -------------------------------- ### Define Application Source Files in CMake Source: https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/CMakeLists.txt Lists the source files for the main application target. Ensure all necessary .c and .cpp files are included. ```cmake target_sources(app PRIVATE bat_charger.cpp daq.cpp daq_driver.c device_status.cpp dcdc.cpp half_bridge.c hardware.cpp oled.cpp leds.cpp load.cpp load_driver.c main.cpp power_port.cpp pwm_switch_driver.c pwm_switch.cpp setup.cpp ) ``` -------------------------------- ### Flash Firmware with Debug Probe Source: https://github.com/libresolar/charge-controller-firmware/blob/main/docs/src/dev/building_flashing.md Flash the built firmware to the target device using a specified debug probe, such as J-Link. ```bash west flash -r jlink ``` -------------------------------- ### Target Sources for Application Source: https://github.com/libresolar/charge-controller-firmware/blob/main/tests/CMakeLists.txt Lists the source files to be compiled for the application target. This includes Unity test files and main application logic. ```cmake target_sources(app PRIVATE ../../modules/unity/src/unity.c src/main.cpp src/tests_bat_charger.cpp src/tests_daq.cpp src/tests_dcdc.cpp src/tests_device_status.cpp src/tests_half_bridge.cpp src/tests_load.cpp src/tests_power_port.cpp ) ``` -------------------------------- ### Re-use Existing West Workspace Source: https://github.com/libresolar/charge-controller-firmware/blob/main/docs/src/dev/workspace_setup.md If you have an existing west workspace, you can add the charge controller firmware to it. This avoids duplicating Zephyr and module repositories. Remember to re-configure the manifest path when switching applications. ```bash # go to your workspace directory cd your-zephyr-workspace # pull the charge controller firmware git clone https://github.com/LibreSolar/charge-controller-firmware cd charge-controller-firmware # re-configure and update the workspace # (to be done each time you switch between applications in same workspace) west config manifest.path charge-controller-firmware west update ``` -------------------------------- ### Use Debug Serial for ThingSet Source: https://github.com/libresolar/charge-controller-firmware/blob/main/docs/src/dev/customization.md Configure the firmware to use the debug RX/TX pins instead of the UEXT connector for the ThingSet protocol. ```bash CONFIG_UEXT_SERIAL_THINGSET=n ``` -------------------------------- ### Add Customization Subdirectory in CMake Source: https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/CMakeLists.txt Includes a custom subdirectory for user-specific firmware customization. This allows for modular extensions to the firmware. ```cmake if(${CONFIG_CUSTOMIZATION}) add_subdirectory(custom build/custom) endif() ``` -------------------------------- ### Configure 12V LiFePO4 Battery Source: https://github.com/libresolar/charge-controller-firmware/blob/main/docs/src/dev/customization.md Add these lines to prj.conf or a board-specific .conf file to set up the firmware for 12V LiFePO4 batteries. ```bash CONFIG_BAT_TYPE_LFP=y CONFIG_BAT_NUM_CELLS=4 ``` -------------------------------- ### Adding Application Subdirectory Source: https://github.com/libresolar/charge-controller-firmware/blob/main/tests/CMakeLists.txt Includes the application source code from a subdirectory into the build. This is a common way to organize larger projects. ```cmake add_subdirectory(../app/src build/app) ``` -------------------------------- ### Automatic Firmware Versioning with Git Source: https://github.com/libresolar/charge-controller-firmware/blob/main/tests/CMakeLists.txt Determines the firmware version ID by executing a Git command. This allows for automatic versioning based on Git tags and commit hashes. ```cmake # determine git tag and commit hash for automatic firmware versioning find_package(Git) if(GIT_FOUND) execute_process( COMMAND ${GIT_EXECUTABLE} describe --long --dirty --tags OUTPUT_VARIABLE FIRMWARE_VERSION_ID OUTPUT_STRIP_TRAILING_WHITESPACE) else() set(FIRMWARE_VERSION_ID "unknown") endif() add_definitions(-DFIRMWARE_VERSION_ID="${FIRMWARE_VERSION_ID}") ``` -------------------------------- ### Unit Test Definitions Source: https://github.com/libresolar/charge-controller-firmware/blob/main/tests/CMakeLists.txt Adds preprocessor definitions for enabling and configuring unit testing. These flags are typically used during the build process for testing purposes. ```cmake add_definitions(-DUNIT_TEST=1) add_definitions(-DUNITY_OUTPUT_COLOR) add_definitions(-DUNITY_EXCLUDE_SETJMP) ``` -------------------------------- ### Create New Branch Source: https://github.com/libresolar/charge-controller-firmware/blob/main/CONTRIBUTING.md Create a new branch for your changes. This isolates your work from the main codebase. ```bash git switch -c branch-name ``` -------------------------------- ### Zephyr Include Directories Source: https://github.com/libresolar/charge-controller-firmware/blob/main/tests/CMakeLists.txt Specifies directories to be included by Zephyr's build system. This ensures that header files from various modules are accessible. ```cmake zephyr_include_directories(./src) zephyr_include_directories(../app/src) zephyr_include_directories(../../modules/thingset/src) zephyr_include_directories(../../modules/unity/src) ``` -------------------------------- ### Disable Default ThingSet Publication Source: https://github.com/libresolar/charge-controller-firmware/blob/main/docs/src/dev/customization.md Add this configuration to disable the regular one-second interval data publication on the ThingSet serial interface at startup. ```bash CONFIG_THINGSET_SERIAL_PUB_DEFAULT=n ``` -------------------------------- ### Add Changed Files to Staging Area Source: https://github.com/libresolar/charge-controller-firmware/blob/main/CONTRIBUTING.md Stage the files you have modified. This prepares them to be included in the next commit. ```bash git add your-changed-files ``` -------------------------------- ### Push Changes to Remote Repository Source: https://github.com/libresolar/charge-controller-firmware/blob/main/CONTRIBUTING.md Upload your committed changes to the remote repository on GitHub. ```bash git push origin branch-name ``` -------------------------------- ### Commit Changes Source: https://github.com/libresolar/charge-controller-firmware/blob/main/CONTRIBUTING.md Commit the staged changes with a descriptive message. Referencing an issue number (e.g., #123) is recommended. ```bash git commit -m "Short message to describe the changes" ``` -------------------------------- ### Conditional Source File Inclusion in CMake Source: https://github.com/libresolar/charge-controller-firmware/blob/main/app/src/CMakeLists.txt Conditionally includes source files based on configuration options. Use CONFIG_CUSTOM_DATA_OBJECTS_FILE to switch between default and custom data object implementations. ```cmake if(${CONFIG_CUSTOM_DATA_OBJECTS_FILE}) target_sources(app PRIVATE data_objects_custom.cpp) else() target_sources(app PRIVATE data_objects.cpp) endif() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.