├── .checkpatch.conf ├── .clang-format ├── .clang-tidy ├── .githooks ├── post-commit ├── post-merge └── pre-commit ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .gitlab-ci.yml ├── .gitlab ├── issue_templates │ └── task.md └── merge_request_templates │ └── default.md ├── .pre-commit-config.yaml ├── CMakeLists.txt ├── CODEOWNERS ├── Kconfig ├── LICENSE ├── README.rst ├── VERSION ├── apps └── shell │ ├── CMakeLists.txt │ ├── README.md │ ├── boards │ ├── custom_board.repl │ ├── custom_board.resc │ └── native_posix.overlay │ ├── prj.conf │ ├── sample.yaml │ └── src │ └── main.c ├── boards ├── arm │ └── custom_board │ │ ├── Kconfig.board │ │ ├── Kconfig.defconfig │ │ ├── arduino_r3_connector.dtsi │ │ ├── board.cmake │ │ ├── custom_board.dts │ │ ├── custom_board.repl │ │ ├── custom_board.resc │ │ ├── custom_board.yaml │ │ ├── custom_board_1_0_0.conf │ │ ├── custom_board_1_0_0.overlay │ │ ├── custom_board_1_0_0.yaml │ │ ├── custom_board_defconfig │ │ ├── doc │ │ ├── debugging.rst │ │ ├── hardware.rst │ │ ├── img │ │ │ ├── nucleo_f401re.png │ │ │ ├── nucleo_f401re_arduino.png │ │ │ ├── nucleo_f401re_morpho.png │ │ │ └── testbench.jpg │ │ ├── index.rst │ │ ├── overview.rst │ │ ├── programming.rst │ │ ├── references.rst │ │ └── testing.rst │ │ └── support │ │ └── openocd.cfg └── index.rst ├── cmake ├── CMakeLists.txt ├── Kconfig ├── clang-tidy.cmake ├── rust │ ├── CMakeCargo.cmake │ ├── CMakeDetermineRustCompiler.cmake │ ├── CMakeRustCompiler.cmake.in │ ├── CMakeRustInformation.cmake │ ├── CMakeTestRustCompiler.cmake │ └── FindRust.cmake ├── version.cmake └── version.h.in ├── doc ├── CMakeLists.txt ├── _extensions │ └── interbreathe │ │ └── __init__.py ├── _scripts │ └── merge_search_indexes.py ├── _static │ ├── html │ │ └── index.html │ ├── images │ │ ├── logo-latex.pdf │ │ └── swelogo.svg │ └── latex │ │ ├── preamble.tex │ │ └── title.tex ├── _theme │ └── sphinx_swe_theme │ │ ├── __init__.py │ │ ├── footer.html │ │ ├── layout.html │ │ ├── search.html │ │ ├── searchbox.html │ │ ├── static │ │ ├── css │ │ │ ├── bootstrap.min.css │ │ │ └── swe.css │ │ ├── images │ │ │ ├── dropdown.svg │ │ │ ├── favicon.png │ │ │ ├── header-bg.svg │ │ │ ├── search.svg │ │ │ └── swelogo.svg │ │ └── js │ │ │ ├── bootstrap.bundle.min.js │ │ │ ├── swe.js │ │ │ └── theme.js │ │ ├── theme.conf │ │ └── versions.html ├── _utils │ └── utils.py ├── consulting.rst ├── develop │ ├── conf.py │ └── index.rst ├── img │ ├── cover.png │ ├── docker-demo.gif │ ├── sdk-overview.png │ ├── visualization.png │ └── zephyr-config.png ├── mcuboot │ ├── conf.py │ └── index.rst ├── renode-docs │ ├── conf.py │ └── logo-latex.pdf ├── sdk │ ├── conf.py │ ├── control │ │ └── index.rst │ ├── drivers │ │ ├── example │ │ │ ├── example_driver.rst │ │ │ ├── example_driver │ │ │ │ ├── api-reference.rst │ │ │ │ ├── description.rst │ │ │ │ ├── main-features.rst │ │ │ │ ├── usage.rst │ │ │ │ └── what-is-this.rst │ │ │ ├── example_sensor.rst │ │ │ └── example_sensor │ │ │ │ ├── api-reference.rst │ │ │ │ ├── description.rst │ │ │ │ ├── main-features.rst │ │ │ │ ├── usage.rst │ │ │ │ └── what-is-this.rst │ │ ├── gpio │ │ │ ├── index.rst │ │ │ ├── mcp23s17.rst │ │ │ └── mcp23s17 │ │ │ │ ├── api-reference.rst │ │ │ │ ├── description.rst │ │ │ │ ├── main-features.rst │ │ │ │ ├── usage.rst │ │ │ │ └── what-is-this.rst │ │ └── index.rst │ ├── img │ │ ├── cover.png │ │ ├── docker-demo.gif │ │ ├── sdk.drawio │ │ ├── sdk.svg │ │ ├── visualization.png │ │ └── zephyr-config.png │ ├── index-tex.rst │ ├── index.rst │ ├── introduction │ │ ├── community.rst │ │ ├── downloading.rst │ │ ├── further-reading.rst │ │ ├── index.rst │ │ ├── sdk-overview.drawio │ │ ├── sdk-overview.png │ │ ├── what-is-this.rst │ │ ├── why-we-need-it.rst │ │ └── windows.rst │ ├── known-warnings.txt │ ├── lib │ │ ├── example │ │ │ ├── api-reference.rst │ │ │ ├── description.rst │ │ │ ├── index.rst │ │ │ ├── main-features.rst │ │ │ ├── usage.rst │ │ │ └── what-is-this.rst │ │ └── index.rst │ ├── links.txt │ ├── release-notes │ │ ├── 0.33.0.rst │ │ └── index.rst │ ├── sdk.doxyfile.in │ ├── shortcuts.txt │ ├── simulation │ │ ├── img │ │ │ ├── cosimulation.drawio │ │ │ └── cosimulation.png │ │ ├── index.rst │ │ ├── main-features.rst │ │ └── what-is-this.rst │ ├── versions.txt │ └── workflow │ │ ├── debugging.rst │ │ ├── docker-build.rst │ │ ├── flashing.rst │ │ ├── img │ │ ├── gdb-dashboard.jpg │ │ └── hello-world-boardbench.png │ │ ├── index.rst │ │ ├── new-project.rst │ │ ├── offer.rst │ │ ├── pitfalls.rst │ │ ├── simulating.rst │ │ ├── testing.rst │ │ └── what-is-this.rst ├── testing │ ├── conf.py │ └── index.rst ├── userspace │ ├── conf.py │ └── index.rst ├── versions.json ├── zephyr.doxyfile.in └── zephyr │ └── conf.py ├── drivers ├── CMakeLists.txt ├── Kconfig ├── example │ ├── CMakeLists.txt │ ├── Kconfig │ ├── example_driver.c │ └── example_sensor.c └── gpio │ ├── CMakeLists.txt │ ├── Kconfig │ ├── Kconfig.mcp23s17 │ └── mcp23s17.c ├── dts └── bindings │ ├── example-driver.yaml │ ├── example-sensor.yaml │ ├── gpio │ └── microchip,mcp23s17.yaml │ └── vendor-prefixes.txt ├── include ├── drivers │ ├── example │ │ └── example_driver.h │ └── gpio │ │ └── gpio_utils.h └── example │ └── example.h ├── lib ├── CMakeLists.txt ├── Kconfig └── example │ ├── CMakeLists.txt │ ├── Kconfig │ └── example.c ├── platform-env.sh ├── renode ├── SharedLibraryPeripheral.cs ├── SocketPeripheral.cs ├── boards │ └── arm │ │ ├── custom_board.repl │ │ └── custom_board.robot ├── drivers │ ├── example │ │ └── ExampleSensor.cs │ └── gpio │ │ └── Mcp23S17.cs └── plugins.resc ├── samples ├── design-patterns │ ├── bridge │ │ ├── CMakeLists.txt │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ ├── rust │ │ │ ├── CMakeLists.txt │ │ │ └── lib.rs │ │ ├── sample.yaml │ │ └── src │ │ │ └── main.c │ ├── callback │ │ ├── CMakeLists.txt │ │ ├── prj.conf │ │ ├── sample.yaml │ │ └── src │ │ │ ├── button.c │ │ │ ├── button.h │ │ │ └── main.c │ ├── inheritance │ │ ├── CMakeLists.txt │ │ ├── Cargo.toml │ │ ├── rust │ │ │ ├── CMakeLists.txt │ │ │ └── lib.rs │ │ ├── sample.yaml │ │ └── src │ │ │ └── main.c │ ├── opaque │ │ ├── CMakeLists.txt │ │ ├── prj.conf │ │ ├── sample.yaml │ │ └── src │ │ │ ├── main.c │ │ │ ├── opaque.c │ │ │ └── opaque.h │ └── virtual-api │ │ ├── CMakeLists.txt │ │ ├── Cargo.toml │ │ ├── rust │ │ ├── CMakeLists.txt │ │ └── lib.rs │ │ ├── sample.yaml │ │ └── src │ │ ├── main.c │ │ ├── serial.c │ │ ├── serial.h │ │ ├── serial_impl.c │ │ ├── serial_impl.h │ │ └── serial_ops.h ├── drivers │ ├── example │ │ ├── example_driver │ │ │ ├── CMakeLists.txt │ │ │ ├── README.md │ │ │ ├── boards │ │ │ │ ├── custom_board.overlay │ │ │ │ └── native_posix.overlay │ │ │ ├── prj.conf │ │ │ ├── sample.yaml │ │ │ └── src │ │ │ │ └── main.c │ │ └── example_sensor │ │ │ ├── CMakeLists.txt │ │ │ ├── README.md │ │ │ ├── boards │ │ │ └── custom_board.overlay │ │ │ ├── doc │ │ │ └── img │ │ │ │ ├── example_sensor.drawio │ │ │ │ └── example_sensor.svg │ │ │ ├── prj.conf │ │ │ ├── sample.yaml │ │ │ └── src │ │ │ └── main.c │ └── gpio │ │ └── mcp23s17 │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── boards │ │ └── custom_board.overlay │ │ ├── doc │ │ ├── building.rst │ │ ├── img │ │ │ └── robotbench-run.jpg │ │ ├── index.rst │ │ ├── interaction.rst │ │ ├── main-features.rst │ │ ├── mcp23s17.drawio │ │ └── mcp23s17.svg │ │ ├── prj.conf │ │ ├── sample.yaml │ │ └── src │ │ └── main.c ├── hdl │ └── verilog │ │ ├── CMakeLists.txt │ │ ├── formal.sby.in │ │ ├── plc │ │ └── config.sby │ │ ├── prj.conf │ │ ├── sample.yaml │ │ ├── src │ │ ├── main.cpp │ │ └── plc.v │ │ └── yosys.cfg.in ├── index.rst ├── lib │ ├── control │ │ └── dcmotor │ │ │ ├── CMakeLists.txt │ │ │ ├── boards │ │ │ ├── custom_board.overlay │ │ │ ├── custom_board.repl │ │ │ └── custom_board.resc │ │ │ ├── design.m │ │ │ ├── doc │ │ │ └── screenshot.png │ │ │ ├── prj.conf │ │ │ ├── sample.yaml │ │ │ └── src │ │ │ └── main.c │ └── example │ │ └── example │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── prj.conf │ │ ├── sample.yaml │ │ └── src │ │ └── main.c ├── renode │ ├── interrupts │ │ ├── CMakeLists.txt │ │ ├── boards │ │ │ ├── custom_board.repl │ │ │ └── custom_board.resc │ │ ├── prj.conf │ │ ├── sample.yaml │ │ └── src │ │ │ └── main.c │ └── nativesimulation │ │ ├── CMakeLists.txt │ │ ├── boards │ │ ├── custom_board.repl │ │ └── custom_board.resc │ │ ├── doc │ │ └── index.rst │ │ ├── plugin │ │ └── peripheral.c │ │ ├── prj.conf │ │ └── src │ │ └── main.c └── rust │ └── basic │ ├── CMakeLists.txt │ ├── Cargo.toml │ ├── README.rst │ ├── prj.conf │ ├── rslib │ ├── CMakeLists.txt │ └── lib.rs │ ├── sample.yaml │ └── src │ └── main.c ├── scripts ├── build ├── build-doc ├── check ├── checkpatch │ └── typedefsfile ├── ci │ ├── check-file-sorted │ ├── check-links │ └── pylintrc ├── coverage ├── dockerize ├── init ├── release ├── requirements-doc.txt ├── run-clang-tidy ├── sort-codeowners ├── spdx │ └── find_git_commit_for_file_sha1 ├── spelling.txt ├── test ├── west-commands.yml └── west │ └── simulate.py ├── testbench ├── CMakeLists.txt ├── Kconfig ├── example_sensor │ ├── custom_board.resc │ └── run.robot ├── index.rst └── nucleo401re_mcp23s17 │ ├── CMakeLists.txt │ ├── doc │ ├── img │ │ └── testbench-demo.jpg │ └── index.rst │ ├── testbench.repl │ ├── testbench.resc │ ├── testbench.robot │ └── visualizer │ ├── application.js │ ├── css │ └── style.css │ ├── favicon │ ├── android-chrome-96x96.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── safari-pinned-tab.svg │ └── site.webmanifest │ ├── img │ ├── board.svg │ └── logo.svg │ ├── index.html │ ├── js │ ├── jquery.svg.js │ ├── jquery.svgdom.js │ └── svg-inject.js │ ├── plugin.py │ └── websocket_server.py ├── tests ├── Kconfig ├── drivers │ ├── example │ │ ├── example_driver │ │ │ ├── CMakeLists.txt │ │ │ ├── README.md │ │ │ ├── boards │ │ │ │ ├── custom_board.overlay │ │ │ │ └── native_posix.overlay │ │ │ ├── prj.conf │ │ │ ├── src │ │ │ │ ├── integration.c │ │ │ │ └── unit.c │ │ │ └── testcase.yaml │ │ └── example_sensor │ │ │ ├── CMakeLists.txt │ │ │ ├── README.md │ │ │ ├── boards │ │ │ └── custom_board.overlay │ │ │ ├── prj.conf │ │ │ ├── src │ │ │ ├── integration.c │ │ │ └── unit.c │ │ │ └── testcase.yaml │ └── gpio │ │ └── mcp23s17 │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── boards │ │ ├── custom_board.overlay │ │ ├── custom_board.repl │ │ └── custom_board.resc │ │ ├── prj.conf │ │ ├── src │ │ ├── integration.c │ │ └── unit.c │ │ └── testcase.yaml └── lib │ └── example │ └── example │ ├── CMakeLists.txt │ ├── README.md │ ├── prj.conf │ ├── src │ ├── integration.c │ └── unit.c │ └── testcase.yaml ├── west.yml └── zephyr └── module.yml /.checkpatch.conf: -------------------------------------------------------------------------------- 1 | --emacs 2 | --summary-file 3 | --show-types 4 | --max-line-length=100 5 | --min-conf-desc-length=1 6 | --typedefsfile=scripts/checkpatch/typedefsfile 7 | 8 | --ignore PREFER_ALIGNED 9 | --ignore PREFER_PACKED 10 | --ignore C99_COMMENTS 11 | --ignore BRACES 12 | --ignore PRINTK_WITHOUT_KERN_LEVEL 13 | --ignore SPLIT_STRING 14 | --ignore VOLATILE 15 | --ignore SPACING 16 | --ignore CONFIG_EXPERIMENTAL 17 | --ignore PREFER_KERNEL_TYPES 18 | --ignore PREFER_SECTION 19 | --ignore AVOID_EXTERNS 20 | --ignore NETWORKING_BLOCK_COMMENT_STYLE 21 | --ignore DATE_TIME 22 | --ignore MINMAX 23 | --ignore CONST_STRUCT 24 | --ignore FILE_PATH_CHANGES 25 | --ignore C99_COMMENT_TOLERANCE 26 | --ignore REPEATED_WORD 27 | --ignore UNDOCUMENTED_DT_STRING 28 | --ignore DT_SPLIT_BINDING_PATCH 29 | --ignore DT_SCHEMA_BINDING_PATCH 30 | --ignore TRAILING_SEMICOLON 31 | --ignore COMPLEX_MACRO 32 | --ignore MULTISTATEMENT_MACRO_USE_DO_WHILE 33 | --ignore ENOSYS 34 | --ignore IS_ENABLED_CONFIG 35 | --exclude testbench/nucleo401re_mcp23s17/visualizer/js 36 | --exclude testbench/nucleo401re_mcp23s17/visualizer/img 37 | --exclude .githooks 38 | --exclude patches 39 | --exclude include/renode/renode_imports_generated.h 40 | -------------------------------------------------------------------------------- /.githooks/post-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: unknown 3 | command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-commit.\n"; exit 2; } 4 | git lfs post-commit "$@" 5 | -------------------------------------------------------------------------------- /.githooks/post-merge: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # SPDX-License-Identifier: unknown 3 | command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/post-merge.\n"; exit 2; } 4 | git lfs post-merge "$@" 5 | -------------------------------------------------------------------------------- /.githooks/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | git diff --cached | ./scripts/checkpatch.pl --no-tree || { 4 | echo "" 5 | echo "###################################################" 6 | echo "#### Checkpatch failed - commit aborted #####" 7 | echo "###################################################" 8 | echo "" 9 | exit 1 10 | } 11 | 12 | ./scripts/ci/check-links 13 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | tags: [ 'v*' ] 7 | pull_request: 8 | branches: [ main ] 9 | 10 | concurrency: 11 | group: ${{ github.ref }} 12 | cancel-in-progress: true 13 | 14 | jobs: 15 | build: 16 | name: Build 17 | runs-on: ubuntu-20.04 18 | container: 19 | image: docker.io/swedishembedded/build:v0.24.6 20 | steps: 21 | - name: Prepare 22 | run: | 23 | apt-get update 24 | apt-get install -qy tex-gyre 25 | - name: Configure git to trust the workspace despite the different owner 26 | run: | 27 | git config --global --add safe.directory "$GITHUB_WORKSPACE" 28 | - name: Checkout 29 | uses: actions/checkout@v2 30 | with: 31 | fetch-depth: 0 32 | lfs: true 33 | - name: Build everything 34 | run: | 35 | ./scripts/init 36 | # for some reason with github we must do this 37 | /opt/toolchains/zephyr-sdk-0.15.1/setup.sh -t all -h -c 38 | ./scripts/gen-tags cscope 39 | ./scripts/check 40 | ./scripts/build-doc --sdk-only 41 | ./scripts/build 42 | ./scripts/test 43 | robot post-build 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore build artifacts 2 | /build*/ 3 | /release/ 4 | /twister-out*/ 5 | /html*/ 6 | /latex*/ 7 | /CMakeCache.txt 8 | /doc/_build/ 9 | /samples/**/build/ 10 | /.cache/ 11 | *.so 12 | *.elf 13 | 14 | # Ignore test artifacts 15 | /log.html 16 | /report.html 17 | /output.xml 18 | 19 | # Ignore output of compliance checks 20 | /Codeowners.txt 21 | /Gitlint.txt 22 | /Identity.txt 23 | /Kconfig.txt 24 | /KconfigBasic.txt 25 | /Nits.txt 26 | /checkpatch.txt 27 | /compliance.xml 28 | /Codeowners.txt 29 | /pylint.txt 30 | 31 | # Ignore gdb history 32 | /.gdb_history 33 | 34 | # Ignore editor swap files (vim, emacs etc) 35 | *.swp 36 | *~ 37 | 38 | # Ignore python environment 39 | .venv 40 | __pycache__/ 41 | 42 | # Ignore generated west config 43 | /.west/config 44 | 45 | # CScope & Tags 46 | /cscope.files 47 | /cscope.out* 48 | /TAGS 49 | 50 | # VSCode 51 | /.vscode 52 | 53 | # Robot framework files 54 | /logs/ 55 | /results*.robot.xml 56 | /robot_output.xml 57 | /snapshots/ 58 | -------------------------------------------------------------------------------- /.gitlab/issue_templates/task.md: -------------------------------------------------------------------------------- 1 | ## What needs to be added 2 | 3 | Describe what needs to be done 4 | 5 | ## What checks need to pass 6 | 7 | Describe in words or in RobotFramework syntax what items need to be completed 8 | and verified. 9 | 10 | ## Additional information 11 | 12 | Links to documentation, pages and other resources that help with 13 | implementation. 14 | -------------------------------------------------------------------------------- /.gitlab/merge_request_templates/default.md: -------------------------------------------------------------------------------- 1 | ## What has been done 2 | 3 | Describe what has been done and what problems are being solved by this MR. 4 | 5 | %{first_commit} 6 | 7 | ## Proof 8 | 9 | Proof in form of screenshots or commands that can be executed to prove that 10 | this mr is correct (for example for running specific unit/integration tests) 11 | 12 | ## Known issues/limitations 13 | 14 | * Are there any known issues? 15 | 16 | * Is there anything else that needs to be done that is not included in this MR? 17 | Make sure you create tickets for any outstanding tasks and paste links to 18 | these tasks here. 19 | 20 | Closes #xxx or Related to #xxx 21 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | repos: 6 | - repo: https://github.com/pre-commit/mirrors-clang-format 7 | rev: v13.0.1 8 | hooks: 9 | - id: clang-format 10 | - repo: https://github.com/cheshirekow/cmake-format-precommit 11 | rev: v0.6.10 12 | hooks: 13 | - id: cmake-format 14 | - id: cmake-lint 15 | - repo: https://github.com/psf/black 16 | rev: 23.7.0 17 | hooks: 18 | - id: black 19 | - repo: local 20 | hooks: 21 | - id: check 22 | name: Check this patch 23 | entry: ./scripts/check 24 | language: system 25 | pass_filenames: false 26 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | /.clang-format @mkschreder 2 | /.clang-tidy @mkschreder 3 | /.githooks/ @mkschreder 4 | /.github/ @mkschreder 5 | /.gitlab-ci.yml @mkschreder 6 | /.gitlab/ @mkschreder 7 | /CMakeLists.txt @mkschreder 8 | /CODEOWNERS @mkschreder 9 | /Kconfig @mkschreder 10 | /LICENSE @mkschreder 11 | /README.rst @mkschreder 12 | /apps/ @mkschreder 13 | /boards/ @mkschreder 14 | /boards/arm/custom_board/ @mkschreder 15 | /cmake/ @mkschreder 16 | /doc/ @mkschreder 17 | /drivers/ @mkschreder 18 | /dts/ @mkschreder 19 | /include/ @mkschreder 20 | /integrity/ @mkschreder 21 | /lib/ @mkschreder 22 | /platform-env.sh @mkschreder 23 | /post-build/ @mkschreder 24 | /renode/ @mkschreder 25 | /samples/ @mkschreder 26 | /scripts/ @mkschreder 27 | /testbench/ @mkschreder 28 | /tests/ @mkschreder 29 | /west.yml @mkschreder 30 | /zephyr/ @mkschreder 31 | -------------------------------------------------------------------------------- /Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | rsource "cmake/Kconfig" 7 | rsource "drivers/Kconfig" 8 | rsource "lib/Kconfig" 9 | rsource "testbench/Kconfig" 10 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | VERSION_MAJOR=0 2 | VERSION_MINOR=37 3 | VERSION_PATCH=0 4 | -------------------------------------------------------------------------------- /apps/shell/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # ~~~ 3 | # Copyright (c) 2021 Antmicro 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | # ~~~ 7 | 8 | cmake_minimum_required(VERSION 3.13.1) 9 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 10 | project(shell) 11 | 12 | target_sources(app PRIVATE src/main.c) 13 | -------------------------------------------------------------------------------- /apps/shell/boards/custom_board.repl: -------------------------------------------------------------------------------- 1 | using "platforms/cpus/stm32f4.repl" 2 | -------------------------------------------------------------------------------- /apps/shell/boards/custom_board.resc: -------------------------------------------------------------------------------- 1 | :SPDX-License-Identifier: Apache 2.0 2 | :Consulting: https://swedishembedded.com/go 3 | :Training: https://swedishembedded.com/tag/training 4 | 5 | :name: Shell application on custom_board 6 | :description: Default application specific simulation 7 | 8 | using sysbus 9 | 10 | mach create 11 | machine LoadPlatformDescription $ORIGIN/custom_board.repl 12 | 13 | showAnalyzer sysbus.usart2 14 | 15 | logLevel 3 16 | logLevel 0 sysbus.usart2 17 | 18 | macro reset 19 | """ 20 | sysbus LoadELF $bin 21 | """ 22 | 23 | runMacro $reset 24 | -------------------------------------------------------------------------------- /apps/shell/boards/native_posix.overlay: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | / { 9 | example_driver { 10 | compatible = "example-driver"; 11 | custom-variable = <1>; 12 | status = "okay"; 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /apps/shell/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | CONFIG_SHELL=y 7 | CONFIG_EXAMPLE_LIBRARY=y 8 | -------------------------------------------------------------------------------- /apps/shell/sample.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | sample: 7 | name: Example shell application 8 | tests: 9 | apps.shell.release: 10 | build_only: true 11 | platform_allow: custom_board 12 | integration_platforms: 13 | - native_posix 14 | - custom_board 15 | -------------------------------------------------------------------------------- /apps/shell/src/main.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright (c) 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | 10 | #include 11 | 12 | void main(void) 13 | { 14 | struct example_object _ex; 15 | 16 | if (example_object_init(&_ex) != 0) { 17 | printk("Could not initialize example object\n"); 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /boards/arm/custom_board/Kconfig.board: -------------------------------------------------------------------------------- 1 | # NUCLEO-64 F401RE board configuration 2 | 3 | # Copyright (c) 2016 Linaro Limited. 4 | # SPDX-License-Identifier: Apache-2.0 5 | 6 | config BOARD_CUSTOM_NUCLEO_F401RE 7 | bool "Custom NUCLEO-64 F401RE Development Board" 8 | depends on SOC_STM32F401XE 9 | -------------------------------------------------------------------------------- /boards/arm/custom_board/Kconfig.defconfig: -------------------------------------------------------------------------------- 1 | # Custom NUCLEO-64 F401RE board configuration 2 | 3 | # Copyright (c) 2016 Linaro Limited. 4 | # Copyright (c) 2019 Centaur Analytics, Inc 5 | # SPDX-License-Identifier: Apache-2.0 6 | 7 | if BOARD_CUSTOM_NUCLEO_F401RE 8 | 9 | config BOARD 10 | default "custom_nucleo_f401re" 11 | 12 | config SPI_STM32_INTERRUPT 13 | default y 14 | depends on SPI 15 | 16 | endif # BOARD_CUSTOM_NUCLEO_F401RE 17 | -------------------------------------------------------------------------------- /boards/arm/custom_board/arduino_r3_connector.dtsi: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Linaro Limited 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | / { 8 | arduino_header: connector { 9 | compatible = "arduino-header-r3"; 10 | #gpio-cells = <2>; 11 | gpio-map-mask = <0xffffffff 0xffffffc0>; 12 | gpio-map-pass-thru = <0 0x3f>; 13 | gpio-map = <0 0 &gpioa 0 0>, /* A0 */ 14 | <1 0 &gpioa 1 0>, /* A1 */ 15 | <2 0 &gpioa 4 0>, /* A2 */ 16 | <3 0 &gpiob 0 0>, /* A3 */ 17 | <4 0 &gpioc 1 0>, /* A4 */ 18 | <5 0 &gpioc 0 0>, /* A5 */ 19 | <6 0 &gpioa 3 0>, /* D0 */ 20 | <7 0 &gpioa 2 0>, /* D1 */ 21 | <8 0 &gpioa 10 0>, /* D2 */ 22 | <9 0 &gpiob 3 0>, /* D3 */ 23 | <10 0 &gpiob 5 0>, /* D4 */ 24 | <11 0 &gpiob 4 0>, /* D5 */ 25 | <12 0 &gpiob 10 0>, /* D6 */ 26 | <13 0 &gpioa 8 0>, /* D7 */ 27 | <14 0 &gpioa 9 0>, /* D8 */ 28 | <15 0 &gpioc 7 0>, /* D9 */ 29 | <16 0 &gpiob 6 0>, /* D10 */ 30 | <17 0 &gpioa 7 0>, /* D11 */ 31 | <18 0 &gpioa 6 0>, /* D12 */ 32 | <19 0 &gpioa 5 0>, /* D13 */ 33 | <20 0 &gpiob 9 0>, /* D14 */ 34 | <21 0 &gpiob 8 0>; /* D15 */ 35 | }; 36 | }; 37 | 38 | arduino_i2c: &i2c1 {}; 39 | arduino_spi: &spi1 {}; 40 | -------------------------------------------------------------------------------- /boards/arm/custom_board/board.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # ~~~ 3 | # Copyright Nordic Semiconductor 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | # ~~~ 7 | 8 | board_runner_args(jlink "--device=STM32F401RE" "--speed=4000") 9 | 10 | include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake) 11 | include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) 12 | 13 | set(SUPPORTED_EMU_PLATFORMS robotbench) 14 | -------------------------------------------------------------------------------- /boards/arm/custom_board/custom_board.repl: -------------------------------------------------------------------------------- 1 | using "platforms/cpus/stm32f4.repl" 2 | -------------------------------------------------------------------------------- /boards/arm/custom_board/custom_board.resc: -------------------------------------------------------------------------------- 1 | :name: STM32F401RE Nucleo Board 2 | :description: Default board simulation 3 | 4 | using sysbus 5 | 6 | mach create 7 | machine LoadPlatformDescription $ORIGIN/custom_board.repl 8 | 9 | logLevel 3 10 | cpu PerformanceInMips 168 11 | 12 | showAnalyzer sysbus.usart2 13 | logLevel 0 sysbus.usart2 14 | 15 | macro reset 16 | """ 17 | sysbus LoadELF $bin 18 | """ 19 | 20 | runMacro $reset 21 | -------------------------------------------------------------------------------- /boards/arm/custom_board/custom_board.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright Nordic Semiconductor 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | identifier: custom_board 7 | name: Custom ST Nucleo F401RE 8 | type: mcu 9 | arch: arm 10 | toolchain: 11 | - zephyr 12 | - gnuarmemb 13 | - xtools 14 | supported: 15 | - arduino_gpio 16 | - arduino_i2c 17 | - arduino_spi 18 | - pwm 19 | - counter 20 | - gpio 21 | - i2c 22 | - spi 23 | - adc 24 | - watchdog 25 | ram: 96 26 | flash: 512 27 | simulation: renode 28 | -------------------------------------------------------------------------------- /boards/arm/custom_board/custom_board_1_0_0.conf: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Martin Schröder 2 | -------------------------------------------------------------------------------- /boards/arm/custom_board/custom_board_1_0_0.overlay: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | -------------------------------------------------------------------------------- /boards/arm/custom_board/custom_board_1_0_0.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | identifier: custom_board@1.0.0 7 | name: Custom Version ST Nucleo F401RE 8 | type: mcu 9 | arch: arm 10 | toolchain: 11 | - zephyr 12 | - gnuarmemb 13 | - xtools 14 | supported: 15 | - arduino_gpio 16 | - arduino_i2c 17 | - arduino_spi 18 | - pwm 19 | - counter 20 | - gpio 21 | - i2c 22 | - spi 23 | - adc 24 | - watchdog 25 | ram: 96 26 | flash: 512 27 | -------------------------------------------------------------------------------- /boards/arm/custom_board/custom_board_defconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | CONFIG_SOC_SERIES_STM32F4X=y 4 | CONFIG_SOC_STM32F401XE=y 5 | 6 | # Enable MPU 7 | CONFIG_ARM_MPU=y 8 | 9 | # Enable HW stack protection 10 | CONFIG_HW_STACK_PROTECTION=y 11 | 12 | CONFIG_SERIAL=y 13 | 14 | # console 15 | CONFIG_CONSOLE=y 16 | CONFIG_UART_CONSOLE=y 17 | 18 | # enable GPIO 19 | CONFIG_GPIO=y 20 | 21 | # enable SPI 22 | CONFIG_SPI=y 23 | 24 | # clock configuration 25 | CONFIG_CLOCK_CONTROL=y 26 | 27 | # enable pin controller 28 | CONFIG_PINCTRL=y 29 | -------------------------------------------------------------------------------- /boards/arm/custom_board/doc/debugging.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Debugging 7 | ********* 8 | 9 | Debugging can be done both using the physical board and inside a simulation. 10 | 11 | To debug the physical board use: 12 | 13 | .. zephyr-app-commands:: 14 | :zephyr-app: apps/shell 15 | :board: nucleo_f401re 16 | :maybe-skip-config: 17 | :goals: debug 18 | 19 | To debug inside a simulation use: 20 | 21 | .. code-block:: console 22 | 23 | west -t boardbench_debugserver 24 | 25 | Then connect to the debugserver using GDB. 26 | -------------------------------------------------------------------------------- /boards/arm/custom_board/doc/hardware.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Hardware 7 | ******** 8 | 9 | This board shares hardware with the original NucleoF401RE board. Refer to the 10 | `documentation for that board`_ for more info. 11 | 12 | .. _documentation for that board: 13 | http://www.st.com/en/evaluation-tools/nucleo-f401re.html 14 | -------------------------------------------------------------------------------- /boards/arm/custom_board/doc/img/nucleo_f401re.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/boards/arm/custom_board/doc/img/nucleo_f401re.png -------------------------------------------------------------------------------- /boards/arm/custom_board/doc/img/nucleo_f401re_arduino.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/boards/arm/custom_board/doc/img/nucleo_f401re_arduino.png -------------------------------------------------------------------------------- /boards/arm/custom_board/doc/img/nucleo_f401re_morpho.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/boards/arm/custom_board/doc/img/nucleo_f401re_morpho.png -------------------------------------------------------------------------------- /boards/arm/custom_board/doc/img/testbench.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/boards/arm/custom_board/doc/img/testbench.jpg -------------------------------------------------------------------------------- /boards/arm/custom_board/doc/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | NucleoF401RE Custom Board 7 | ######################### 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Guides 12 | 13 | overview.rst 14 | hardware.rst 15 | programming.rst 16 | debugging.rst 17 | testing.rst 18 | references.rst 19 | -------------------------------------------------------------------------------- /boards/arm/custom_board/doc/overview.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Overview 7 | ******** 8 | 9 | The main custom board is based on Nucleo F401RE board. 10 | 11 | It has all of the features of the original Nucleo F401RE board, with the added 12 | possibility to simulate this board and debug it in simulation. 13 | 14 | For more details about this board, visit `Nucleo F401RE website`_. 15 | 16 | This board was the first board to be added to the SDK and so it is a bit of a 17 | "demo" board. Many examples build for this board and the main testbench is based 18 | on this board. 19 | 20 | .. _Nucleo F401RE website: 21 | http://www.st.com/en/evaluation-tools/nucleo-f401re.html 22 | -------------------------------------------------------------------------------- /boards/arm/custom_board/doc/programming.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Programming 7 | *********** 8 | 9 | You can run applications on this board both physically and through simulation. 10 | 11 | Flashing 12 | ======== 13 | 14 | To flash the example shell application to this board, run: 15 | 16 | .. code-block:: bash 17 | 18 | west build -p -b custom_board apps/shell -t flash 19 | 20 | You can connect to the Nucleo F401RE to your host computer using the USB port: 21 | 22 | .. code-block:: console 23 | 24 | $ picocom /dev/ttyACM0 25 | 26 | Simulation 27 | ========== 28 | 29 | In the Swedish Embedded SDK this board supports simulation: 30 | 31 | .. code-block:: console 32 | 33 | west build -t boardbench 34 | 35 | This runs the default board testbench. 36 | 37 | To connect to the onboard uart use this in the simulation monitor: 38 | 39 | .. code-block:: console 40 | 41 | (machine-0) uart_connect sysbus.usart2 42 | -------------------------------------------------------------------------------- /boards/arm/custom_board/doc/references.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Datasheets 7 | ********** 8 | 9 | - `Zephyr documentation for NucleoF401RE`_ 10 | 11 | .. _Zephyr documentation for NucleoF401RE: 12 | https://github.com/zephyrproject-rtos/zephyr/blob/main/boards/arm/nucleo_f401re/doc/index.rst_ 13 | -------------------------------------------------------------------------------- /boards/arm/custom_board/doc/testing.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Testing 7 | ******* 8 | 9 | This board does support a testbench. This testbench supports simulated mcp23s17 10 | peripheral connected to the board. 11 | 12 | You can run the testbench example as follows: 13 | 14 | .. code-block:: console 15 | 16 | west build -p -b custom_board samples/drivers/gpio/mcp23s17 -t testbench 17 | 18 | Then point your browser to localhost:8000 to view the testbench interface. 19 | 20 | .. image:: img/testbench.jpg 21 | 22 | To interact with the USART use "uart_connect sybus.usart2" in the monitor 23 | window. 24 | -------------------------------------------------------------------------------- /boards/arm/custom_board/support/openocd.cfg: -------------------------------------------------------------------------------- 1 | source [find board/st_nucleo_f4.cfg] 2 | 3 | $_TARGETNAME configure -event gdb-attach { 4 | echo "Debugger attaching: halting execution" 5 | reset halt 6 | gdb_breakpoint_override hard 7 | } 8 | 9 | $_TARGETNAME configure -event gdb-detach { 10 | echo "Debugger detaching: resuming execution" 11 | resume 12 | } 13 | -------------------------------------------------------------------------------- /boards/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Boards 7 | ###### 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Boards 12 | 13 | arm/custom_board/doc/index.rst 14 | -------------------------------------------------------------------------------- /cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # ~~~ 3 | # Copyright 2022 Martin Schröder 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | # ~~~ 7 | 8 | include(version.cmake) 9 | include(clang-tidy.cmake) 10 | include(CMakeCargo) 11 | -------------------------------------------------------------------------------- /cmake/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache 2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | config CHECK_CLANG_TIDY 7 | bool "Check sources using clang-tidy" 8 | default y 9 | -------------------------------------------------------------------------------- /cmake/clang-tidy.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # ~~~ 3 | # Copyright 2022 Martin Schröder 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | # ~~~ 7 | 8 | find_program( 9 | CLANG_TIDY 10 | NAMES "clang-tidy-15" "clang-tidy-12" "clang-tidy" 11 | DOC "Path to clang-tidy executable") 12 | 13 | # Enable clang-tidy for target 14 | function(check_clang_tidy target) 15 | # Add a custom script that will run after the target was built 16 | add_custom_command( 17 | TARGET ${target} 18 | POST_BUILD 19 | COMMAND $ENV{PROJECT_BASE}/scripts/run-clang-tidy --build-dir 20 | ${CMAKE_BINARY_DIR} 21 | COMMENT "Running static analysis") 22 | endfunction() 23 | -------------------------------------------------------------------------------- /cmake/rust/CMakeDetermineRustCompiler.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT 2 | # ~~~ 3 | # Copyright (c) 2018 Andrew Gaspar 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | # ~~~ 7 | 8 | if(NOT CMAKE_Rust_COMPILER) 9 | find_package(Rust) 10 | if(_RUST_FOUND) 11 | set(CMAKE_Rust_COMPILER "${RUSTC_EXECUTABLE}") 12 | set(CMAKE_Rust_COMPILER_ID "Rust") 13 | set(CMAKE_Rust_COMPILER_VERSION "${RUST_VERSION}") 14 | set(CMAKE_Rust_PLATFORM_ID "Rust") 15 | endif() 16 | endif() 17 | 18 | message(STATUS "Cargo Home: ${CARGO_HOME}") 19 | message(STATUS "Rust Compiler Version: ${RUSTC_VERSION}") 20 | 21 | mark_as_advanced(CMAKE_Rust_COMPILER) 22 | 23 | if(CMAKE_Rust_COMPILER) 24 | set(CMAKE_Rust_COMPILER_LOADED 1) 25 | endif(CMAKE_Rust_COMPILER) 26 | 27 | configure_file( 28 | ${CMAKE_CURRENT_LIST_DIR}/CMakeRustCompiler.cmake.in 29 | "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/\ 30 | ${CMAKE_VERSION}/CMakeRustCompiler.cmake" IMMEDIATE @ONLY) 31 | 32 | set(CMAKE_Rust_COMPILER_ENV_VAR "RUSTC") 33 | -------------------------------------------------------------------------------- /cmake/rust/CMakeRustCompiler.cmake.in: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT 2 | # ~~~ 3 | # Copyright (c) 2018 Andrew Gaspar 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | # ~~~ 7 | 8 | set(CMAKE_Rust_COMPILER "@CMAKE_Rust_COMPILER@") 9 | set(CMAKE_Rust_COMPILER_ID "@CMAKE_Rust_COMPILER_ID@") 10 | set(CMAKE_Rust_COMPILER_VERSION "@CMAKE_Rust_COMPILER_VERSION@") 11 | set(CMAKE_Rust_COMPILER_LOADED @CMAKE_Rust_COMPILER_LOADED@) 12 | set(CMAKE_Rust_PLATFORM_ID "@CMAKE_Rust_PLATFORM_ID@") 13 | 14 | SET(CMAKE_Rust_SOURCE_FILE_EXTENSIONS rs) 15 | SET(CMAKE_Rust_LINKER_PREFERENCE 40) 16 | SET(CMAKE_STATIC_LIBRARY_PREFIX_Rust "") 17 | SET(CMAKE_STATIC_LIBRARY_SUFFIX_Rust .a) 18 | 19 | set(CMAKE_Rust_COMPILER_ENV_VAR "RUSTC") 20 | 21 | -------------------------------------------------------------------------------- /cmake/rust/CMakeTestRustCompiler.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT 2 | # ~~~ 3 | # Copyright (c) 2018 Andrew Gaspar 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | # ~~~ 7 | 8 | set(CMAKE_Rust_COMPILER_WORKS 1 "") 9 | -------------------------------------------------------------------------------- /cmake/version.h.in: -------------------------------------------------------------------------------- 1 | #ifndef PROJECT_VERSION_H_ 2 | #define PROJECT_VERSION_H_ 3 | 4 | #cmakedefine PROJECT_VERSION_CODE @PROJECT_VERSION_CODE@ 5 | #define PROJECT_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) 6 | 7 | #define PROJECT_VERSION_NUMBER @PROJECT_VERSION_NUMBER@ 8 | #define PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ 9 | #define PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@ 10 | #define PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCHLEVEL@ 11 | #define PROJECT_VERSION_STRING @PROJECT_VERSION_STRING@ 12 | 13 | #define PROJECT_BUILD_VERSION @PROJECT_BUILD_VERSION@ 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /doc/_extensions/interbreathe/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # SPDX-License-Identifier: Apache-2.0 3 | # 4 | # Copyright (c) 2020 Nordic Semiconductor ASA 5 | # 6 | 7 | from sphinx.transforms.post_transforms import SphinxPostTransform 8 | from sphinx import addnodes 9 | 10 | 11 | __version__ = "0.1.0" 12 | 13 | 14 | class DoxygenIdentifierReferenceResolver(SphinxPostTransform): 15 | # must run before sphinx ReferenceResolver 16 | default_priority = 5 17 | # only resolve identifier xrefs for these domains 18 | domains = set(["c", "cpp"]) 19 | 20 | def run(self, **kwargs): 21 | for node in self.document.traverse(addnodes.pending_xref): 22 | if node["reftype"] != "identifier": 23 | continue 24 | 25 | if "refdomain" not in node or node["refdomain"] not in self.domains: 26 | continue 27 | 28 | # skip when information required by intersphinx is available already 29 | if "refdoc" in node: 30 | continue 31 | 32 | nodecopy = node.deepcopy() 33 | contnode = node[0].deepcopy() 34 | 35 | # 'refdoc' is used by intersphinx to correctly adjust relative 36 | # paths when resolving external references 37 | nodecopy["refdoc"] = self.env.docname 38 | 39 | newnode = self.app.emit_firstresult( 40 | "missing-reference", self.env, nodecopy, contnode 41 | ) 42 | if newnode is not None: 43 | node.replace_self(newnode) 44 | 45 | 46 | def setup(app): 47 | app.add_post_transform(DoxygenIdentifierReferenceResolver) 48 | 49 | return { 50 | "version": __version__, 51 | "parallel_read_safe": True, 52 | "parallel_write_safe": True, 53 | } 54 | -------------------------------------------------------------------------------- /doc/_static/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /doc/_static/images/logo-latex.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/_static/images/logo-latex.pdf -------------------------------------------------------------------------------- /doc/_static/latex/preamble.tex: -------------------------------------------------------------------------------- 1 | % LaTeX documentation preamble 2 | % 3 | % Copyright (c) 2021 Nordic Semiconductor ASA 4 | % SPDX-License-Identifier: Apache-2.0 5 | 6 | \usepackage[some]{background} 7 | \usepackage{sectsty} 8 | 9 | \definecolor{bg-color}{HTML}{333f67} 10 | 11 | \setcounter{tocdepth}{2} 12 | 13 | \addto\captionsenglish{\renewcommand{\contentsname}{Table of contents}} 14 | 15 | \allsectionsfont{\color{bg-color}} -------------------------------------------------------------------------------- /doc/_static/latex/title.tex: -------------------------------------------------------------------------------- 1 | % LaTeX documentation title page 2 | % 3 | % Copyright (c) 2021 Nordic Semiconductor ASA 4 | % SPDX-License-Identifier: Apache-2.0 5 | 6 | \makeatletter 7 | \newgeometry{top=3cm,left=0cm,right=0cm,bottom=2.5cm} 8 | 9 | \backgroundsetup{ 10 | scale=2.3, 11 | contents={}, 12 | opacity=0.2, 13 | angle=0, 14 | position={0.25\textwidth,-0.4\textheight} 15 | } 16 | 17 | \BgThispage 18 | 19 | \begin{minipage}{2cm} 20 | \color{bg-color} \rule{2cm}{1.7cm} 21 | \end{minipage} 22 | \hspace{0.2cm} 23 | \begin{minipage}{3cm} 24 | \sphinxlogo 25 | \end{minipage} 26 | \hspace{0.2cm} 27 | \begin{minipage}{15cm} 28 | \Huge \textbf{\@title}\\ 29 | \LARGE \py@release\releaseinfo 30 | \end{minipage} 31 | 32 | \vspace{21cm} 33 | 34 | \begin{flushright} 35 | \begin{minipage}{7cm} 36 | \large \@author\\\@date 37 | \end{minipage} 38 | \begin{minipage}{1.5cm} 39 | \color{bg-color} \rule{1.5cm}{1.3cm} 40 | \end{minipage} 41 | \end{flushright} 42 | 43 | \restoregeometry 44 | \makeatother 45 | -------------------------------------------------------------------------------- /doc/_theme/sphinx_swe_theme/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | import os 4 | 5 | __version__ = "1.0.0" 6 | 7 | 8 | def setup(app): 9 | app.add_html_theme("sphinx_swe_theme", os.path.dirname(os.path.abspath(__file__))) 10 | return {"parallel_read_safe": True, "parallel_write_safe": True} 11 | -------------------------------------------------------------------------------- /doc/_theme/sphinx_swe_theme/search.html: -------------------------------------------------------------------------------- 1 | {% extends "sphinx_rtd_theme/search.html" %} 2 | {% block body %} 3 |
4 |

Tip

5 |

6 | Search results include entries for all documentation sets. Each search 7 | result entry is prefixed with the name of the documentation set in which 8 | the result is found. For example, the search result "Swedish Embedded SDK 9 | » Introduction" refers to the Introduction page from the "Swedish 10 | Embedded SDK" documentation set. 11 |

12 |
13 | {{ super() }} 14 | {% endblock %} 15 | 16 | -------------------------------------------------------------------------------- /doc/_theme/sphinx_swe_theme/searchbox.html: -------------------------------------------------------------------------------- 1 | {%- if builder != 'singlehtml' %} 2 | 11 | 12 | {%- endif %} 13 | -------------------------------------------------------------------------------- /doc/_theme/sphinx_swe_theme/static/images/dropdown.svg: -------------------------------------------------------------------------------- 1 | 2 | 16 | 18 | 19 | 21 | image/svg+xml 22 | 24 | 25 | 26 | 27 | 29 | 49 | 54 | 55 | -------------------------------------------------------------------------------- /doc/_theme/sphinx_swe_theme/static/images/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/_theme/sphinx_swe_theme/static/images/favicon.png -------------------------------------------------------------------------------- /doc/_theme/sphinx_swe_theme/static/images/search.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 13 | 14 | 15 | Page-1 16 | 17 | path2 18 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /doc/_theme/sphinx_swe_theme/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = sphinx_rtd_theme 3 | stylesheet = css/swe.css 4 | pygments_style = default 5 | 6 | [options] 7 | canonical_url = 8 | analytics_id = 9 | collapse_navigation = True 10 | sticky_navigation = True 11 | navigation_depth = 4 12 | includehidden = True 13 | titles_only = 14 | logo_only = 15 | display_version = True 16 | prev_next_buttons_location = bottom 17 | style_external_links = False 18 | vcs_pageview_mode = 19 | docset = 20 | docsets = 21 | standalone = False 22 | -------------------------------------------------------------------------------- /doc/_theme/sphinx_swe_theme/versions.html: -------------------------------------------------------------------------------- 1 | {# Add rst-badge after rst-versions for small badge style. #} 2 | {%- if theme_docsets %} 3 |
4 | 5 | {{ project }} 6 | 7 | 8 |
9 | {%- for name, config in theme_docsets.items() %} 10 | {%- set css_class = name %} 11 |
12 | {{ config[0] }} 13 |
14 | {%- endfor %} 15 |
16 |
17 | {%- endif %} 18 | -------------------------------------------------------------------------------- /doc/consulting.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | If you need urgent consulting help `click here `_ 7 | -------------------------------------------------------------------------------- /doc/develop/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | .. _mcuboot_index: 7 | 8 | Swedish Embedded Docker Image 9 | ############################# 10 | 11 | This documentation covers the `Swedish Embedded Docker Image 12 | `_ that is used for running all CI 13 | pipelines and local builds. 14 | 15 | 16 | -------------------------------------------------------------------------------- /doc/img/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/img/cover.png -------------------------------------------------------------------------------- /doc/img/docker-demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/img/docker-demo.gif -------------------------------------------------------------------------------- /doc/img/sdk-overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/img/sdk-overview.png -------------------------------------------------------------------------------- /doc/img/visualization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/img/visualization.png -------------------------------------------------------------------------------- /doc/img/zephyr-config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/img/zephyr-config.png -------------------------------------------------------------------------------- /doc/mcuboot/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | .. _mcuboot_index: 7 | 8 | MCUboot Bootloader Documentation 9 | ################################ 10 | 11 | This documentation is based on the official `MCUboot `_ 12 | documentation, but focuses on the use of MCUboot in the Swedish Embedded SDK. 13 | 14 | .. toctree:: 15 | :maxdepth: 1 16 | :caption: Contents 17 | 18 | release-notes.md 19 | design.md 20 | encrypted_images.md 21 | imgtool.md 22 | ecdsa.md 23 | signed_images.md 24 | readme-zephyr.md 25 | testplan-zephyr.md 26 | release.md 27 | SECURITY.md 28 | SubmittingPatches.md 29 | -------------------------------------------------------------------------------- /doc/renode-docs/logo-latex.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/renode-docs/logo-latex.pdf -------------------------------------------------------------------------------- /doc/sdk/control/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Control Systems Toolbox 7 | ####################### 8 | 9 | This SDK includes a complete control systems toolbox written in C and Octave. 10 | This toolbox is included as a module through west and resides in its own 11 | `separate repository`_ (when you initialize the SDK you get access to it 12 | automatically just like all the other modules!). 13 | 14 | .. _separate repository: https://github.com/swedishembedded/control 15 | 16 | The control systems toolbox gives you a fairly complete set of tools to design 17 | advanced control algorithms (including model based controllers that use kalman 18 | filters) in pure C such that they can be used as part of a fast control path 19 | where every cycle counts. 20 | 21 | There is more documentation at the moment on the control systems toolbox github 22 | page, as well as in the doc section of that repository. 23 | -------------------------------------------------------------------------------- /doc/sdk/drivers/example/example_driver.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Example Driver 7 | ############## 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Drivers 12 | 13 | example_driver/what-is-this.rst 14 | example_driver/main-features.rst 15 | example_driver/description.rst 16 | example_driver/usage.rst 17 | example_driver/api-reference.rst 18 | -------------------------------------------------------------------------------- /doc/sdk/drivers/example/example_driver/api-reference.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | API Reference 7 | ************* 8 | 9 | If you want to include api reference in your documentation, use the doxygengroup 10 | tag to do so: 11 | 12 | .. doxygengroup:: example-driver-api 13 | -------------------------------------------------------------------------------- /doc/sdk/drivers/example/example_driver/description.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Functional Description 7 | ********************** 8 | 9 | This driver does not support any public APIs. It simply shows how to create a 10 | minimal standalone driver. 11 | -------------------------------------------------------------------------------- /doc/sdk/drivers/example/example_driver/main-features.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Main Features 7 | ************* 8 | 9 | This driver currently supports only automatic initialization. 10 | -------------------------------------------------------------------------------- /doc/sdk/drivers/example/example_driver/usage.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Usage 7 | ***** 8 | 9 | Enable this driver in prj.conf by setting "CONFIG_EXAMPLE_DRIVER=y" in your 10 | application. 11 | -------------------------------------------------------------------------------- /doc/sdk/drivers/example/example_driver/what-is-this.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Simple driver example 7 | ********************* 8 | 9 | This is a simple example driver that shows how to implement the simplest driver 10 | interface. For more complete examples check out the "zephyr" folder under your 11 | workspace. 12 | -------------------------------------------------------------------------------- /doc/sdk/drivers/example/example_sensor.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Example Sensor 7 | ############## 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Drivers 12 | 13 | example_sensor/what-is-this.rst 14 | example_sensor/main-features.rst 15 | example_sensor/description.rst 16 | example_sensor/usage.rst 17 | example_sensor/api-reference.rst 18 | -------------------------------------------------------------------------------- /doc/sdk/drivers/example/example_sensor/api-reference.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | API Reference 7 | ************* 8 | 9 | This section shows how to reference C functions in your documentation that are 10 | documented using doxygen comments. 11 | 12 | This driver implements standard sensor API functions :c:func:`sensor_sample_fetch` 13 | and :c:func:`sensor_channel_get`. 14 | -------------------------------------------------------------------------------- /doc/sdk/drivers/example/example_sensor/description.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Functional Description 7 | ********************** 8 | 9 | This driver implements the sensor interface which allows you to access the 10 | simulated device over SPI. 11 | 12 | This driver also has a simulation counterpart which you can enable as follows: 13 | 14 | exampleSensor: Sensors.ExampleSensor @ spi1 15 | Interrupt -> gpioPortA@4 16 | 17 | See "renode/drivers/example/ExampleSensor.cs" for details. 18 | 19 | Also we need to wire the CS pin to sensor GPIO 0: 20 | 21 | gpioPortB: 22 | 6 -> exampleSensor@0 23 | 24 | Then from renode you can run: 25 | 26 | sysbus.spi1.exampleSensor Temperature 25 27 | 28 | This will simulate a new reading being ready and raise the sensor interrupt 29 | which will be detected by the Zephyr driver and new value will be retrieved. 30 | -------------------------------------------------------------------------------- /doc/sdk/drivers/example/example_sensor/main-features.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Main Features 7 | ************* 8 | 9 | - Simulated temperature sensing. 10 | - Interrupt support when reading is ready 11 | -------------------------------------------------------------------------------- /doc/sdk/drivers/example/example_sensor/usage.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Usage 7 | ***** 8 | 9 | Enable this driver in prj.conf by setting "CONFIG_EXAMPLE_SENSOR=y" in your 10 | application. 11 | 12 | .. code-block:: text 13 | 14 | example_sensor { 15 | compatible = "example-sensor"; 16 | label = "EXAMPLE_SENSOR"; 17 | gpios = <&gpioa 4 GPIO_ACTIVE_LOW>; 18 | status = "okay"; 19 | }; 20 | 21 | Then in code you can start a new measurement using: 22 | 23 | .. code-block:: text 24 | 25 | const struct device *dev = device_get_binding("EXAMPLE_DRIVER") 26 | sensor_sample_fetch(dev); 27 | sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP); 28 | -------------------------------------------------------------------------------- /doc/sdk/drivers/example/example_sensor/what-is-this.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Example Sensor Driver 7 | ********************* 8 | 9 | This is an example SPI sensor driver which also includes a renode simulation 10 | counterpart. 11 | -------------------------------------------------------------------------------- /doc/sdk/drivers/gpio/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | GPIO 7 | #### 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Drivers 12 | 13 | mcp23s17.rst 14 | -------------------------------------------------------------------------------- /doc/sdk/drivers/gpio/mcp23s17.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | MPC23S17 7 | ######## 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Drivers 12 | 13 | mcp23s17/what-is-this.rst 14 | mcp23s17/main-features.rst 15 | mcp23s17/description.rst 16 | mcp23s17/usage.rst 17 | mcp23s17/api-reference.rst 18 | -------------------------------------------------------------------------------- /doc/sdk/drivers/gpio/mcp23s17/api-reference.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | API Reference 7 | ************* 8 | 9 | This driver implements the standard Zephyr GPIO interface. 10 | -------------------------------------------------------------------------------- /doc/sdk/drivers/gpio/mcp23s17/description.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Description 7 | *********** 8 | 9 | The driver implements Zephyr GPIO interface which means that it can be used in 10 | the application just like any GPIO device and controlled entirely through the 11 | standard Zephyr GPIO functions. 12 | 13 | The typical usage pattern is as follows: 14 | 15 | Define a device tree node where you configure the device. This has to be placed 16 | under the SPI device that will be managing this driver: 17 | 18 | .. code-block:: 19 | 20 | &spi1 { 21 | pinctrl-0 = <&spi1_sck_pa5 &spi1_miso_pa6 &spi1_mosi_pa7>; 22 | pinctrl-names = "default"; 23 | cs-gpios = < 24 | &gpiob 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP) 25 | >; 26 | status = "okay"; 27 | 28 | mcp23s17: mcp23s17@1 { 29 | compatible = "microchip,mcp23s17v2"; 30 | gpio-controller; 31 | #gpio-cells = <2>; 32 | ngpios = <16>; 33 | reg = <0>; 34 | spi-max-frequency = <10000000>; 35 | inta-gpios = < 36 | &gpiob 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP) 37 | >; 38 | intb-gpios = < 39 | &gpiob 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP) 40 | >; 41 | label = "GPIO_E0"; 42 | status = "okay"; 43 | }; 44 | }; 45 | 46 | If you do not specify "inta-gpios" or "intb-gpios" then that interrupt will not 47 | be available. 48 | 49 | -------------------------------------------------------------------------------- /doc/sdk/drivers/gpio/mcp23s17/main-features.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Main Features 7 | ************* 8 | 9 | The chip supports following main functions: 10 | 11 | - **16 GPIO Pins**: with configurable pullups when in input mode. 12 | 13 | - **Pin interrupt support**: with comparison either against a preset value or 14 | against the previous value of the input pin. Two interrupt pins are available 15 | that can be configured in either active-low or active-high mode. 16 | 17 | - **SPI communication**: up to 10Mhz clock speed. 18 | -------------------------------------------------------------------------------- /doc/sdk/drivers/gpio/mcp23s17/usage.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Usage 7 | ***** 8 | 9 | Once device instance has been defined in DTS or overlay and you have enabled the 10 | driver in your prj.conf, you can now get a handle to the device in your 11 | application: 12 | 13 | .. code-block:: 14 | 15 | const struct device *dev = device_get_binding("GPIO_E0"); 16 | 17 | You can now configure the pin as input or output using the 18 | :c:func:`gpio_pin_configure` function: 19 | 20 | .. code-block:: 21 | 22 | gpio_pin_configure(dev, pin, GPIO_INPUT); 23 | gpio_pin_configure(dev, pin, GPIO_OUTPUT); 24 | gpio_pin_configure(dev, pin, GPIO_OUTPUT | GPIO_PULL_UP); 25 | gpio_pin_configure(dev, pin, GPIO_OUTPUT | GPIO_ACTIVE_LOW); 26 | gpio_pin_configure(dev, pin, GPIO_OUTPUT | GPIO_ACTIVE_HIGH); 27 | 28 | You can combine any of these flags. 29 | 30 | It is also possible to configure interrupts on each pin individually by using 31 | the standard :c:func:`gpio_pin_interrupt_configure` function: 32 | 33 | .. code-block:: 34 | 35 | gpio_pin_interrupt_configure(dev, pin, GPIO_INT_EDGE_TO_ACTIVE); 36 | gpio_pin_interrupt_configure(dev, pin, GPIO_INT_EDGE_TO_INACTIVE); 37 | 38 | You can now add a callback for the interrupts by using the standard set of 39 | zephyr functions: 40 | 41 | .. code-block:: 42 | 43 | gpio_init_callback(&cb, _gpio_callback, pin_mask); 44 | gpio_add_callback(dev, &cb); 45 | -------------------------------------------------------------------------------- /doc/sdk/drivers/gpio/mcp23s17/what-is-this.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Introduction 7 | ************ 8 | 9 | MCP23S17 is a 16-Bit I/O Expander with serial interface. The 'S' version of the 10 | chip comes with an SPI interface. 11 | -------------------------------------------------------------------------------- /doc/sdk/drivers/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Drivers 7 | ####### 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Drivers 12 | 13 | gpio/index.rst 14 | example/example_driver.rst 15 | example/example_sensor.rst 16 | -------------------------------------------------------------------------------- /doc/sdk/img/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/sdk/img/cover.png -------------------------------------------------------------------------------- /doc/sdk/img/docker-demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/sdk/img/docker-demo.gif -------------------------------------------------------------------------------- /doc/sdk/img/sdk.drawio: -------------------------------------------------------------------------------- 1 | 5ZlPk9ogGMY/jTPtYWdCyD+P1d1urduT2+nsEYEYZklwCK7aT1+yEjUhO9ppNGovDjyQEH68eXgxPThMV48SzZMfglDecx2y6sH7nuv2g1D/FsJ6I4TQ2wgzychGAjthwn5TIzpGXTBC80pHJQRXbF4VscgyilVFQ1KKZbVbLHh11DmaUUuYYMRt9RcjKtmoke/s9G+UzZJyZOCYlhSVnY2QJ4iI5Z4EH3pwKIVQm1K6GlJesCu5bK77+kHr9sEkzdQxFzwuR46Pn9++j1OJkydMn/j4ztzlDfGFmbB5WLUuCUixyAgtbuL04GCZMEUnc4SL1qVecq0lKuW6BnQxZpwPBRfy/VpIfBoRT+u5kuKV7rVE7hQGgW4xD0CloqsPZwa2vHScUZFSJde6i7kABgaxiTEYmvpyt2IQGi3ZX62+EZGJktn23juQumBY/gVXt2WuLVCKDkNyw7NCghakgX4buECEys5x9au4fNfGBdwGXPBUtDyL1pjKrHDbyyLlRV2T8i1SUJI7PSG1fp8YftWunXfObbszXAy4wAL3IhayGGk+5wwjxUTWObZ6uDkNPuY3UAtPRS20qE3uxxYmPWFVZVHdEzOR0doGaiTE2SzTVawBaWOEgwKfXg3+xTSkjJBimEb41eVpgT+I/IMbSXDOqI0s/sORrk9YuuAmZJ1Pk3WuaKpLzzRX+efbXR7PO7zPg6Z9/mTrA2w//jcTqSWZcRy7GDclmSSYBn5bSWZ42HdAk+9sxdbB9i2uPzOmihOSjvFWERNEo7gRcYAjOo1bQlxLUT14nLOcDHB5CN0jPNIv+UyWtlKAthOJm/ESeMReC8BZvcQ+sF53zHt+DXG/65i3j67XTdhylc4J2+fe6yZsxXDnvm0fZK4w4/DhxWUcwD7rXHfo+t6lha59mvmvUg6/7iXdpxy3lmYH4MI2xPI/rpshbLlK54RvLW22Yvh0vq2ru4907217Xzrhwx8= -------------------------------------------------------------------------------- /doc/sdk/img/visualization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/sdk/img/visualization.png -------------------------------------------------------------------------------- /doc/sdk/img/zephyr-config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/sdk/img/zephyr-config.png -------------------------------------------------------------------------------- /doc/sdk/index-tex.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | :orphan: 7 | 8 | Swedish Embedded Firmware and Simulation Platform SDK Documentation 9 | ################################################################### 10 | 11 | 12 | .. toctree:: 13 | :maxdepth: 1 14 | :caption: Contents 15 | 16 | introduction/index.rst 17 | workflow/index.rst 18 | control/index.rst 19 | boards/index.rst 20 | drivers/index.rst 21 | lib/index.rst 22 | testbench/index.rst 23 | samples/index.rst 24 | simulation/index.rst 25 | release-notes/index.rst 26 | -------------------------------------------------------------------------------- /doc/sdk/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | .. 7 | Platform SDK documentation main file 8 | 9 | .. _zephyr-home: 10 | 11 | Swedish Embedded Platform SDK Documentation 12 | ########################################### 13 | 14 | .. only:: release 15 | 16 | Welcome to the Swedish Embedded Firmware And Simulation Platform SDK 17 | documentation version |version|. 18 | 19 | .. only:: (development or daily) 20 | 21 | **Welcome to the Swedish Embedded Firmware And Simulation Platform SDK 22 | documentation for main tree under development** (versoin |version|). 23 | 24 | Sections 25 | ******** 26 | 27 | .. toctree:: 28 | :maxdepth: 2 29 | :caption: Contents 30 | 31 | introduction/index.rst 32 | workflow/index.rst 33 | control/index.rst 34 | boards/index.rst 35 | drivers/index.rst 36 | lib/index.rst 37 | testbench/index.rst 38 | samples/index.rst 39 | simulation/index.rst 40 | release-notes/index.rst 41 | 42 | Indices and Tables 43 | ****************** 44 | 45 | * :ref:`genindex` 46 | 47 | .. _Apache 2.0 license: 48 | https://github.com/zephyrproject-rtos/zephyr/blob/main/LICENSE 49 | 50 | .. _GitLab repo: https://gitlab.com/swedishembedded/platform/sdk 51 | 52 | -------------------------------------------------------------------------------- /doc/sdk/introduction/community.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Discord Community 7 | ================= 8 | 9 | If you get stuck at any point while using this SDK, you can get help in the 10 | official discord community. Latest discord link is always available at 11 | https://swedishembedded.com/community. 12 | -------------------------------------------------------------------------------- /doc/sdk/introduction/further-reading.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | What else this manual contains 7 | ============================== 8 | 9 | This was a short introduction to the SDK. It is barely scratching the surface of 10 | what we can do. The next logical step for you to get accustomed with the 11 | workflow of developing applications using this SDK. This is covered in detail 12 | under the "workflow" section. 13 | -------------------------------------------------------------------------------- /doc/sdk/introduction/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Introduction 7 | ############ 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Contents 12 | 13 | what-is-this.rst 14 | why-we-need-it.rst 15 | downloading.rst 16 | windows.rst 17 | community.rst 18 | further-reading.rst 19 | -------------------------------------------------------------------------------- /doc/sdk/introduction/sdk-overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/sdk/introduction/sdk-overview.png -------------------------------------------------------------------------------- /doc/sdk/introduction/windows.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Working on Windows 7 | ================== 8 | 9 | The SDK should build and run fine on windows - although the process is not 10 | tested very often. 11 | 12 | To use the SDK and docker image on windows you will need two things: 13 | 14 | - **Windows subsystem for Linux v2 (WSL)**: this is an ubuntu setup that runs 15 | natively on windows. It gives you a fully ubuntu compatible terminal on 16 | windows. You can get it here: https://ubuntu.com/wsl 17 | 18 | - **Windows Docker Desktop**: this provides windows docker support. When you 19 | install docker desktop you will have access to the docker command from the WSL 20 | linux terminal. Get it here: https://docs.docker.com/desktop/windows/wsl/ 21 | 22 | Once installed, the rest of the instructions for setting up the SDK and using it 23 | are exactly the same. 24 | -------------------------------------------------------------------------------- /doc/sdk/known-warnings.txt: -------------------------------------------------------------------------------- 1 | # Each line should contain the regular expression of a known Sphinx warning 2 | # that should be filtered out 3 | -------------------------------------------------------------------------------- /doc/sdk/lib/example/api-reference.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | API Reference 7 | ************* 8 | 9 | You can reference library Doxygen documentation here in the same way as you do 10 | for the drivers: 11 | 12 | .. doxygengroup:: example-library-api 13 | -------------------------------------------------------------------------------- /doc/sdk/lib/example/description.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Description 7 | *********** 8 | 9 | This library basicly does nothing, but shows you how to add shared code to your 10 | project. 11 | -------------------------------------------------------------------------------- /doc/sdk/lib/example/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Example Library 7 | ############### 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Drivers 12 | 13 | what-is-this.rst 14 | main-features.rst 15 | description.rst 16 | usage.rst 17 | api-reference.rst 18 | -------------------------------------------------------------------------------- /doc/sdk/lib/example/main-features.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Main Features 7 | ************* 8 | 9 | This library currently has no features and serves purely as a very basic 10 | example. 11 | -------------------------------------------------------------------------------- /doc/sdk/lib/example/usage.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Usage 7 | ***** 8 | 9 | To use this library simply include example/example.h in your application. 10 | -------------------------------------------------------------------------------- /doc/sdk/lib/example/what-is-this.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Simple Example Library 7 | ********************** 8 | 9 | This is a very simple example library that shows how to add shared library code. 10 | -------------------------------------------------------------------------------- /doc/sdk/lib/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Libraries 7 | ######### 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Drivers 12 | 13 | example/index.rst 14 | -------------------------------------------------------------------------------- /doc/sdk/links.txt: -------------------------------------------------------------------------------- 1 | .. ### Source: zephyrproject.org 2 | 3 | .. _`Zephyr`: https://zephyrproject.org/ 4 | -------------------------------------------------------------------------------- /doc/sdk/release-notes/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Release Notes 7 | ############# 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Contents 12 | 13 | 0.33.0.rst 14 | -------------------------------------------------------------------------------- /doc/sdk/shortcuts.txt: -------------------------------------------------------------------------------- 1 | .. |SDK| replace:: Swedish Embedded SDK 2 | 3 | .. |release| replace:: v0.36.0 4 | -------------------------------------------------------------------------------- /doc/sdk/simulation/img/cosimulation.drawio: -------------------------------------------------------------------------------- 1 | 5Vldc5s4FP01fkwGIcD2Y+Ik3ew2U2+ddmcfBRKgqZBYIWJ7f/1KIGwT8NTtQNx18uCII3Gle+7RxxUTuMg2HyTK0yeBCZu4Dt5M4N3EdafA0b8G2FpgDmsgkRTXENgDK/ovsaB9LykpJkWroRKCKZq3wUhwTiLVwpCUYt1uFgvW7jVHCekAqwixLvoXxSqt0Znv7PHfCE3Spmfg2JoMNY0tUKQIi/UBBO8ncCGFUHUp2ywIM9w1vNTvPRyp3Q1MEq5OeQH/Pn0h2d9L7+PiT7T+DG5e0Ncra+UFsdI6/EQyIbcae0K5HbjaNmxIUXJMjEFnAm/XKVVklaPI1K51+DWWqozpJ6CLMWVsIZiQ1bswjkkQRRovlBTfyEENns5Dxxi0gyFSkc1RL8GOO605IjKiquHaF3Z0b189r/fRAw2WHkSuwZAVTLIzvedUFyytP0Cx26F49fwEDfQFSTUoxdgnM+z1UTxzQxgEI1Hsn5ti2KH4gcpsrT2auAHTvd+GUpcSU7qlHNkuh1N27B5RdhAG/kC0Bz/LejAW7d5RZT/TjMhLkPbs3NL2OxwvykKJTGPLrUoFNwVWJpQPK2mEp6hX0qEX+I43DN1wdoKmQQ/d/lh0B8f3wwzluWZT+0ckzVMiEbsAhUNwosK9sSifdlcRhThGTHC9fDv3GxKVCoWa4iHZDlE0w7CPbRd6no/HEXgv230CH43t+bsTeHBugTfxPVR4qv0xVH+koRz6OBICjGOnj2fgTOGcjCTtPp7fVNqgm8zst8hLkrR39jUbdJOaB8pIsS0UyYY+iMyx38cwIh7Qh81RxNzL8NuKuZvTdHg9YG13uWAYxqhId3QjRhOuy5GmQp/J4a0hikaI3diKjGJsLBobubGcbRJzlXNdX5+49X9j1pDjXBtRV9c7njHPhYpS29UQgfC/fyLsP3+PFohulvMeAgHmv1wguqlQk25+WD5+uoR1/dSjymjZJujmP18Kk8k7jzwvh72sivXfbNbHMQzgHI50Au/l+E1TTNCT8CwfNfAZYSouQcbzs8t49v9bs6VQSFFhjOrxj7Sd9qm/LzLjib+bf77PyLzeX88emaazVmTqy/MUNJfnDVLkiLeCFvxTiuqeHUXfkmrJuorq1ebGdMypojr1qgzYlo3J1ZpgWqS61X0WEoyrtHjJkIqFNLecq7s/XuVvzopmJatD4jqfclMompFp3+vBtQes4a4XP+BXLLi6Wts4GJc8+8HKYZSTq/SgppZS19GmD2PqeB9F9QXU2AEw3/QaukOUGSXFu28cDiYvhIk8I5VpxHG7WiuVxnpyWMqiysmwerG+ZItEljOiSGWXVhSIWNm3y4LypFKGpESZFiKumumJF5udyHW0BFOBi+sDums3O1E4ITivlgM9x1R7l2vvZty40N76LKT7iszQ4Z2/f3oWuZnI7rHdVGiyYlYtOqleQgivVoDDPXiA2e/7rck/7c59D/rdyQ9+It3Uj/tvzFXdwYd6eP8f -------------------------------------------------------------------------------- /doc/sdk/simulation/img/cosimulation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/sdk/simulation/img/cosimulation.png -------------------------------------------------------------------------------- /doc/sdk/simulation/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Renode Simulation 7 | ################# 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Drivers 12 | 13 | what-is-this.rst 14 | main-features.rst 15 | -------------------------------------------------------------------------------- /doc/sdk/simulation/main-features.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Simulation Interface 7 | #################### 8 | 9 | When you define a simulation platform in a repl file, it is also possible to 10 | define SocketPeripheral device: 11 | 12 | .. code-block:: text 13 | 14 | model: SocketPeripheral @ sysbus <0x70000000, +0x100> 15 | 16 | In your resc file you can then set the path to the executable which will 17 | actually be invoked as "handler" for this memory region. 18 | 19 | .. code-block:: text 20 | 21 | model PeripheralPath $ORIGIN/../peripheral/peripheral.elf 22 | 23 | It is this executable that requires this library in order to setup a connection 24 | back to the emulator and establish two way communication. 25 | -------------------------------------------------------------------------------- /doc/sdk/simulation/what-is-this.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Simulation 7 | ########## 8 | 9 | Renode co-simulation allows you to create testbenches and simulate your 10 | production firmware realistically. 11 | 12 | .. image:: img/cosimulation.png 13 | -------------------------------------------------------------------------------- /doc/sdk/versions.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/sdk/versions.txt -------------------------------------------------------------------------------- /doc/sdk/workflow/docker-build.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Building your code using docker 7 | =============================== 8 | 9 | Docker is by far the preferable way to build. You can create a bash function 10 | that you put into your .bashrc that looks like this: 11 | 12 | .. code-block:: bash 13 | 14 | function drun() { 15 | if [[ ! -d $PWD/../.west/ ]]; then 16 | echo "Run this command from a directory inside a west workspace!" 17 | exit 1 18 | fi 19 | docker run -ti -v /dev/bus/usb:/dev/bus/usb \ 20 | -v $(realpath $PWD/..):$(realpath $PWD/..) \ 21 | swedishembedded/develop:latest \ 22 | bash -c "cd $PWD && $*" 23 | } 24 | 25 | If you don't want to logout and then login again you can just source your bashrc 26 | and then you can use this function: 27 | 28 | .. code-block:: bash 29 | 30 | . ~/.bashrc 31 | drun west build -p -b custom_board apps/shell 32 | 33 | This will build your local source code inside docker. This type of docker usage 34 | is extremely powerful because you can setup a full environment inside docker and 35 | then use the docker image as your primary way of building code. In that 36 | environment you can specific versions of different tools that are compatible 37 | with your project. It becomes, in effect, a fully reproducible process. 38 | 39 | .. code-block:: bash 40 | 41 | drun make -C doc pdf 42 | 43 | This builds the documentation. 44 | 45 | Bash functions and aliases are extremely useful! 46 | -------------------------------------------------------------------------------- /doc/sdk/workflow/flashing.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Flashing on real hardware 7 | ========================= 8 | 9 | You can also flash the application on the real nucleo board. For this you will 10 | need to expose USB to the docker image so you can connect to your JTAG adapter. 11 | This can be done by running the docker image in privileged mode and mounting usb 12 | devices. On linux this can be done like this: 13 | 14 | .. code-block:: shell 15 | 16 | docker run -t -i --privileged -v /dev/bus/usb:/dev/bus/usb \ 17 | swedishembedded/develop:latest 18 | 19 | Now you should be able to flash a sample application like this: 20 | 21 | .. code-block:: shell 22 | 23 | west build -b stm32f429i_disc1 ../zephyr/samples/basic/blinky \ 24 | -t flash 25 | 26 | For a list of boards you can execute: 27 | 28 | .. code-block:: shell 29 | 30 | west boards 31 | 32 | Note that not all applications support all of the boards. Specially not ones 33 | that rely on external peripherals. This means that you may not be able to build 34 | them unless the app is configured to support the target board. 35 | -------------------------------------------------------------------------------- /doc/sdk/workflow/img/gdb-dashboard.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/sdk/workflow/img/gdb-dashboard.jpg -------------------------------------------------------------------------------- /doc/sdk/workflow/img/hello-world-boardbench.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/doc/sdk/workflow/img/hello-world-boardbench.png -------------------------------------------------------------------------------- /doc/sdk/workflow/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Workflow 7 | ######## 8 | 9 | .. contents:: 10 | :local: 11 | :depth: 2 12 | 13 | .. toctree:: 14 | :maxdepth: 1 15 | :caption: Workflow 16 | 17 | what-is-this.rst 18 | new-project.rst 19 | docker-build.rst 20 | flashing.rst 21 | testing.rst 22 | debugging.rst 23 | simulating.rst 24 | pitfalls.rst 25 | offer.rst 26 | -------------------------------------------------------------------------------- /doc/sdk/workflow/offer.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Further reading 7 | =============== 8 | 9 | - **SDK source code**: https://github.com/swedishembedded/sdk 10 | 11 | - **Training Workshops**: https://swedishembedded.com/training 12 | -------------------------------------------------------------------------------- /doc/sdk/workflow/pitfalls.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Getting help 7 | ============ 8 | 9 | If you run into any problems doing these steps, do not hesitate to ask for help 10 | in the community discord channel. The latest discord link is always available at 11 | https://swedishembedded.com/community. 12 | -------------------------------------------------------------------------------- /doc/sdk/workflow/what-is-this.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Development workflow 7 | #################### 8 | 9 | This section describes in detail the process of developing applications and 10 | verifying them using the tools provided by this SDK. 11 | 12 | Having a well defined workflow helps you stay organized and ensures that you do 13 | not forget important steps of the process. 14 | 15 | In this section we are going to cover the following important steps: 16 | 17 | - **Setting up a new project**: here we will setup a simple embedded application 18 | and run it inside the simulation. Very similar to what you have seen in the 19 | introduction - but here the details of the process are explained. 20 | - **Building your application for target platforms**: this section explains what 21 | you need to do in order to make your application support multiple platforms 22 | (such as multiple boards or multiple products). 23 | - **Debugging your application**: this section deals with the details of 24 | debugging. Here I show you how to get various debugging information from your 25 | running program and the tools that the SDK provides for this purpose. 26 | - **Simulating your application**: here we look at how the simulation framework 27 | is setup and how you can add new simulation environments to your application. 28 | 29 | After becoming familiar with the workflow you should be able to use this SDK to 30 | build, simulate and test your embedded application with ease. 31 | -------------------------------------------------------------------------------- /doc/testing/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | .. _testing_index: 7 | 8 | Test Infrastructure Documentation 9 | ################################# 10 | 11 | Swedish Embedded SDK and packages that depend on it rely on CMock and Unity for 12 | low level unit testing of code logic. 13 | 14 | This approach involves additional scripts and tools which are implemented in 15 | the `Testing`_ repository. 16 | 17 | This system predominantly works by generating mocks from existing zephyr files. 18 | You can check the `SDK tests`_ to get an idea how each test application is put 19 | together. 20 | 21 | The topics below are imported directly from CMock and Unity documentation: 22 | 23 | .. _Testing: https://github.com/swedishembedded/testing 24 | .. _SDK tests: https://github.com/swedishembedded/sdk/tree/main/tests 25 | 26 | .. toctree:: 27 | :maxdepth: 1 28 | :caption: Contents 29 | 30 | CMock_Summary.md 31 | UnityGettingStartedGuide.md 32 | UnityConfigurationGuide.md 33 | UnityAssertionsReference.md 34 | UnityHelperScriptsGuide.md 35 | -------------------------------------------------------------------------------- /doc/userspace/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | .. _mcuboot_index: 7 | 8 | Application Libraries And Utilities 9 | ################################### 10 | 11 | This section contains documentation for libraries and utilities that are 12 | included into the Swedish Embedded Platform SDK. You can use these libraries by 13 | simply enabling corresponding Kconfig option for your application that is built 14 | with this SDK. 15 | 16 | -------------------------------------------------------------------------------- /doc/versions.json: -------------------------------------------------------------------------------- 1 | { 2 | "VERSIONS": [ 3 | "latest", 4 | "0.36.0" 5 | ], 6 | "COMPONENTS_BY_VERSION": { 7 | "latest": { 8 | "zephyr": "3.1.99" 9 | }, 10 | "0.36.0": { 11 | "zephyr": "3.1.99" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /drivers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache 2.0 Copyright 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | # Add driver type directories here 6 | 7 | add_subdirectory(example) 8 | add_subdirectory(gpio) 9 | -------------------------------------------------------------------------------- /drivers/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache 2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | menu "Device Drivers" 7 | 8 | rsource "example/Kconfig" 9 | 10 | rsource "gpio/Kconfig" 11 | 12 | endmenu 13 | -------------------------------------------------------------------------------- /drivers/example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache 2.0 Copyright 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | zephyr_library() 6 | zephyr_library_property(ALLOW_EMPTY TRUE) 7 | zephyr_library_sources_ifdef(CONFIG_EXAMPLE_DRIVER example_driver.c) 8 | zephyr_library_sources_ifdef(CONFIG_EXAMPLE_SENSOR example_sensor.c) 9 | 10 | check_clang_tidy(..__sdk__drivers__example) 11 | -------------------------------------------------------------------------------- /drivers/example/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache 2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | config EXAMPLE_DRIVER 7 | bool "Example driver" 8 | help 9 | This is our example driver. 10 | 11 | config EXAMPLE_SENSOR 12 | bool "Example sensor" 13 | help 14 | This is our example sensor. 15 | -------------------------------------------------------------------------------- /drivers/example/example_driver.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | /** Device tree compatible */ 9 | #define DT_DRV_COMPAT example_driver 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | /** Create a logger */ 17 | LOG_MODULE_REGISTER(example_driver); 18 | 19 | /** Driver local data */ 20 | struct example_driver { 21 | // data goes here 22 | }; 23 | 24 | /** Driver configuration (from device tree) */ 25 | struct example_driver_config { 26 | /** a custom variable from dts */ 27 | int custom_variable; 28 | }; 29 | 30 | /** Driver initialization */ 31 | static int example_driver_init(const struct device *dev) 32 | { 33 | if (!dev) { 34 | return -EINVAL; 35 | } 36 | LOG_INF("Example driver initialized!"); 37 | return 0; 38 | } 39 | 40 | /** Macro to instantiate the driver */ 41 | #define EXAMPLE_DRIVER_INIT(n) \ 42 | static struct example_driver _example_##n; \ 43 | static const struct example_driver_config _example_config_##n = { \ 44 | .custom_variable = DT_INST_PROP(n, custom_variable), \ 45 | }; \ 46 | DEVICE_DT_INST_DEFINE(n, example_driver_init, NULL, &_example_##n, &_example_config_##n, \ 47 | POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY, NULL) 48 | 49 | /** Instantiate the driver */ 50 | DT_INST_FOREACH_STATUS_OKAY(EXAMPLE_DRIVER_INIT); 51 | -------------------------------------------------------------------------------- /drivers/gpio/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache 2.0 Copyright 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | zephyr_library() 6 | zephyr_library_property(ALLOW_EMPTY TRUE) 7 | zephyr_library_sources_ifdef(CONFIG_GPIO_MCP23S17V2 mcp23s17.c) 8 | 9 | check_clang_tidy(..__sdk__drivers__gpio) 10 | -------------------------------------------------------------------------------- /drivers/gpio/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache 2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | rsource "Kconfig.mcp23s17" 7 | -------------------------------------------------------------------------------- /drivers/gpio/Kconfig.mcp23s17: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache 2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | config GPIO_MCP23S17V2 7 | bool "MCP23S17 SPI-based GPIO chip" 8 | depends on SPI 9 | help 10 | Enable driver for MCP23S17 SPI-based GPIO chip. 11 | -------------------------------------------------------------------------------- /dts/bindings/example-driver.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | description: | 7 | Device tree bindings for the example driver. 8 | 9 | Example definition in devicetree: 10 | 11 | example_driver { 12 | compatible = "example-driver"; 13 | custom-variable = <1>; 14 | status = "okay"; 15 | }; 16 | 17 | compatible: "example-driver" 18 | 19 | include: base.yaml 20 | 21 | properties: 22 | custom-variable: 23 | type: int 24 | required: true 25 | description: A custom variable 26 | -------------------------------------------------------------------------------- /dts/bindings/example-sensor.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | description: | 7 | Device tree bindings for the example sensor. 8 | 9 | Example definition in devicetree: 10 | 11 | &spi1 { 12 | pinctrl-0 = <&spi1_sck_pa5 &spi1_miso_pa6 &spi1_mosi_pa7>; 13 | pinctrl-names = "default"; 14 | cs-gpios = <&gpiob 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; 15 | status = "okay"; 16 | 17 | example_sensor: example_sensor@0{ 18 | reg = <0>; 19 | compatible = "example-sensor"; 20 | label = "EXAMPLE_SENSOR"; 21 | gpios = <&gpioa 4 GPIO_ACTIVE_LOW>; 22 | spi-max-frequency = <1000000>; 23 | status = "okay"; 24 | }; 25 | }; 26 | 27 | compatible: "example-sensor" 28 | 29 | include: ["base.yaml", "spi-device.yaml"] 30 | 31 | properties: 32 | gpios: 33 | type: phandle-array 34 | required: true 35 | description: GPIO connected to the sensor 36 | -------------------------------------------------------------------------------- /dts/bindings/gpio/microchip,mcp23s17.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2020 Geanix ApS 3 | # Copyright (c) 2022 Swedish Embedded Group AB 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | 7 | description: | 8 | This is a representation of the Microchip MCP23S17 SPI Gpio Expander. 9 | 10 | compatible: "microchip,mcp23s17v2" 11 | 12 | include: [gpio-controller.yaml, spi-device.yaml] 13 | 14 | properties: 15 | "#gpio-cells": 16 | const: 2 17 | 18 | ngpios: 19 | type: int 20 | required: true 21 | const: 16 22 | description: Number of gpios supported 23 | inta-gpios: 24 | type: phandle-array 25 | description: Interrupt for PORTA 26 | intb-gpios: 27 | type: phandle-array 28 | description: Interrupt for PORTB 29 | 30 | gpio-cells: 31 | - pin 32 | - flags 33 | -------------------------------------------------------------------------------- /dts/bindings/vendor-prefixes.txt: -------------------------------------------------------------------------------- 1 | se Swedish Embedded Consulting Group AB 2 | -------------------------------------------------------------------------------- /include/drivers/example/example_driver.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | #pragma once 8 | 9 | /*! 10 | * @defgroup example-driver-api Example Driver API 11 | * @{ 12 | **/ 13 | 14 | /** 15 | * \brief Example driver public function 16 | * \param[in] dev reference to device 17 | * \returns error status 18 | * \retval -EINVAL invalid arguments 19 | * \retval 0 success 20 | **/ 21 | int example_driver_function(const struct device *dev); 22 | 23 | /*! 24 | * @} 25 | **/ 26 | -------------------------------------------------------------------------------- /include/example/example.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | /*! 14 | * @defgroup example-library-api Example Library API 15 | * @{ 16 | **/ 17 | 18 | /** Example object */ 19 | struct example_object { 20 | /** Dummy mutex for testing */ 21 | struct k_mutex mx; 22 | }; 23 | 24 | /** 25 | * \brief Initializes example object. 26 | * \param[in] self reference to object 27 | * \returns error status 28 | * \retval -EINVAL invalid arguments 29 | * \retval 0 success 30 | **/ 31 | int example_object_init(struct example_object *self); 32 | 33 | /*! 34 | * @} 35 | **/ 36 | -------------------------------------------------------------------------------- /lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache 2.0 Copyright 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | add_subdirectory(example) 6 | -------------------------------------------------------------------------------- /lib/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache 2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | rsource "example/Kconfig" 7 | -------------------------------------------------------------------------------- /lib/example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | zephyr_library() 6 | zephyr_library_property(ALLOW_EMPTY TRUE) 7 | zephyr_library_sources_ifdef(CONFIG_EXAMPLE_LIBRARY example.c) 8 | -------------------------------------------------------------------------------- /lib/example/Kconfig: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022 Martin Schröder 2 | # SPDX-License-Identifier: Apache-2.0 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | config EXAMPLE_LIBRARY 7 | bool "Example library" 8 | help 9 | Example library 10 | -------------------------------------------------------------------------------- /lib/example/example.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | int example_object_init(struct example_object *self) 13 | { 14 | if (!self) 15 | return -EINVAL; 16 | memset(self, 0, sizeof(*self)); 17 | printk("Example object initialized!\n"); 18 | 19 | k_mutex_init(&self->mx); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /platform-env.sh: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | export PLATFORM_BASE="$(realpath $(dirname $BASH_SOURCE))" 4 | 5 | . ${PLATFORM_BASE}/../zephyr/zephyr-env.sh 6 | -------------------------------------------------------------------------------- /renode/boards/arm/custom_board.repl: -------------------------------------------------------------------------------- 1 | using "platforms/cpus/stm32f4.repl" 2 | 3 | UserButton: Miscellaneous.Button @ gpioPortC 4 | -> gpioPortA@0 5 | 6 | UserLED: Miscellaneous.LED @ gpioPortD 7 | 8 | gpioPortD: 9 | 12 -> UserLED@0 10 | 11 | exampleSensor: Sensors.ExampleSensor @ spi1 12 | Interrupt -> gpioPortA@4 13 | 14 | gpioPortB: 15 | 6 -> exampleSensor@0 16 | -------------------------------------------------------------------------------- /renode/boards/arm/custom_board.robot: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | *** Settings *** 7 | Suite Setup Setup 8 | Suite Teardown Teardown 9 | Test Setup Reset Emulation 10 | Test Teardown Test Teardown 11 | Resource ${RENODEKEYWORDS} 12 | Variables ${CURDIR}/../../../scrum/variables.py 13 | 14 | *** Variables *** 15 | ${UART} sysbus.usart2 16 | 17 | *** Test Cases *** 18 | Run Shell Sample 19 | Execute Command set bin @${PROJECT_ROOT}/build-apps/custom_board/shell/apps.shell.release/zephyr/zephyr.elf 20 | Execute Command include @scripts/single-node/stm32f4_discovery.resc 21 | 22 | Execute Command showAnalyzer ${UART} 23 | Create Terminal Tester ${UART} 24 | 25 | Start Emulation 26 | 27 | Wait For Line On Uart Booting Zephyr OS 28 | -------------------------------------------------------------------------------- /renode/plugins.resc: -------------------------------------------------------------------------------- 1 | i $PROJECT_BASE/renode/SharedLibraryPeripheral.cs 2 | i $PROJECT_BASE/renode/SocketPeripheral.cs 3 | -------------------------------------------------------------------------------- /samples/design-patterns/bridge/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cmake_minimum_required(VERSION 3.20.0) 6 | 7 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 8 | project(sample) 9 | 10 | add_subdirectory(rust) 11 | 12 | target_sources(app PRIVATE src/main.c) 13 | target_link_libraries(app PRIVATE rust_lib) 14 | -------------------------------------------------------------------------------- /samples/design-patterns/bridge/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "rust_lib" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /samples/design-patterns/bridge/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_lib" 3 | version = "0.1.0" 4 | authors = ["Martin Schröder "] 5 | edition = "2021" 6 | 7 | [lib] 8 | path = "rust/lib.rs" 9 | crate-type = ["staticlib"] 10 | 11 | [dependencies] 12 | -------------------------------------------------------------------------------- /samples/design-patterns/bridge/rust/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cargo_build(NAME rust_lib) 6 | -------------------------------------------------------------------------------- /samples/design-patterns/bridge/sample.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | sample: 7 | name: Bridge Pattern 8 | tests: 9 | samples.patterns.bridge: 10 | platform_allow: qemu_cortex_m3 11 | build_only: true 12 | integration_platforms: 13 | - qemu_cortex_m3 14 | - qemu_x86_64 15 | -------------------------------------------------------------------------------- /samples/design-patterns/callback/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cmake_minimum_required(VERSION 3.20.0) 6 | 7 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 8 | project(sample) 9 | 10 | target_sources(app PRIVATE src/main.c src/button.c) 11 | -------------------------------------------------------------------------------- /samples/design-patterns/callback/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | CONFIG_ASSERT=y 7 | CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=128 8 | -------------------------------------------------------------------------------- /samples/design-patterns/callback/sample.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | sample: 7 | name: Opaque Pattern 8 | tests: 9 | samples.patterns.callback: 10 | platform_allow: qemu_cortex_m3 11 | build_only: true 12 | integration_platforms: 13 | - qemu_cortex_m3 14 | - qemu_x86_64 15 | -------------------------------------------------------------------------------- /samples/design-patterns/callback/src/button.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include "button.h" 9 | 10 | #include 11 | #include 12 | 13 | void button_init(struct button *self) 14 | { 15 | memset(self, 0, sizeof(*self)); 16 | } 17 | 18 | void button_deinit(struct button *self) 19 | { 20 | self->cb = NULL; 21 | } 22 | 23 | size_t button_size(void) 24 | { 25 | return sizeof(struct button); 26 | } 27 | 28 | void button_set_callback(struct button *self, struct button_callback *cb) 29 | { 30 | self->cb = cb; 31 | } 32 | 33 | void button_remove_callback(struct button *self, struct button_callback *cb) 34 | { 35 | self->cb = NULL; 36 | } 37 | 38 | void button_add_callback(struct button *self, struct button_callback *cb) 39 | { 40 | sys_slist_append(&self->callbacks, &cb->node); 41 | } 42 | 43 | void button_delete_callback(struct button *self, struct button_callback *cb) 44 | { 45 | sys_slist_find_and_remove(&self->callbacks, &cb->node); 46 | } 47 | 48 | void button_do_something(struct button *self) 49 | { 50 | // call the callback 51 | if (self->cb) 52 | self->cb->cb(self->cb); 53 | 54 | sys_snode_t *node; 55 | 56 | SYS_SLIST_FOR_EACH_NODE (&self->callbacks, node) { 57 | // once again we use container of here since we know node points to cb->node 58 | struct button_callback *cb = CONTAINER_OF(node, struct button_callback, node); 59 | 60 | cb->cb(cb); // call the callback 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /samples/design-patterns/callback/src/button.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | 11 | struct button { 12 | /** Alternative 1: single callback */ 13 | struct button_callback *cb; 14 | /** Alternative 2: multiple callbacks */ 15 | sys_slist_t callbacks; 16 | }; 17 | 18 | // this is a public callback definition 19 | struct button_callback { 20 | sys_snode_t node; 21 | void (*cb)(struct button_callback *cb); 22 | }; 23 | 24 | void button_init(struct button *self); 25 | void button_deinit(struct button *self); 26 | size_t button_size(void); 27 | void button_set_callback(struct button *self, struct button_callback *cb); 28 | void button_remove_callback(struct button *self, struct button_callback *cb); 29 | void button_add_callback(struct button *self, struct button_callback *cb); 30 | void button_delete_callback(struct button *self, struct button_callback *cb); 31 | void button_do_something(struct button *self); 32 | -------------------------------------------------------------------------------- /samples/design-patterns/callback/src/main.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "button.h" 14 | 15 | struct controller { 16 | /** Button instance */ 17 | struct button *btn; 18 | /** Button callback */ 19 | struct button_callback cb; // our callback 20 | }; 21 | 22 | static void controller_on_button_cb(struct button_callback *cb) 23 | { 24 | // this is how we can now get pointer to instance of B 25 | // notice that the callback is generic 26 | struct controller *self = CONTAINER_OF(cb, struct controller, cb); 27 | 28 | printk("Controller callback for button %p\n", self->btn); 29 | } 30 | 31 | void controller_init(struct controller *self, struct button *a) 32 | { 33 | self->btn = a; 34 | self->cb.cb = controller_on_button_cb; 35 | /* Alternative 1 */ 36 | button_set_callback(a, &self->cb); 37 | /* Alternative 2 */ 38 | button_add_callback(a, &self->cb); 39 | } 40 | 41 | void controller_deinit(struct controller *self) 42 | { 43 | /* Alternative 1 */ 44 | button_remove_callback(self->btn, &self->cb); 45 | /* Alternative 2 */ 46 | button_delete_callback(self->btn, &self->cb); 47 | } 48 | 49 | void main(void) 50 | { 51 | struct controller ctrl; 52 | struct button btn; 53 | 54 | button_init(&btn); 55 | controller_init(&ctrl, &btn); 56 | 57 | // this will call controller callback function 58 | button_do_something(&btn); 59 | 60 | controller_deinit(&ctrl); 61 | button_deinit(&btn); 62 | } 63 | -------------------------------------------------------------------------------- /samples/design-patterns/inheritance/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cmake_minimum_required(VERSION 3.20.0) 6 | 7 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 8 | project(sample) 9 | 10 | add_subdirectory(rust) 11 | 12 | target_sources(app PRIVATE src/main.c) 13 | target_link_libraries(app PRIVATE rust_lib) 14 | -------------------------------------------------------------------------------- /samples/design-patterns/inheritance/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_lib" 3 | version = "0.1.0" 4 | authors = ["Martin Schröder "] 5 | edition = "2021" 6 | 7 | [lib] 8 | path = "rust/lib.rs" 9 | crate-type = ["staticlib"] 10 | 11 | [dependencies] 12 | -------------------------------------------------------------------------------- /samples/design-patterns/inheritance/rust/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cargo_build(NAME rust_lib) 6 | -------------------------------------------------------------------------------- /samples/design-patterns/inheritance/rust/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | use core::panic::PanicInfo; 3 | 4 | extern "C" { 5 | fn serial_out(c: u8); 6 | } 7 | 8 | pub fn printk(msg: &str) { 9 | for c in msg.chars() { 10 | unsafe { 11 | serial_out(c as u8); 12 | } 13 | } 14 | } 15 | 16 | #[no_mangle] 17 | pub extern "C" fn rust_main() -> usize { 18 | printk("RUST main\n"); 19 | 20 | return 0; 21 | } 22 | 23 | #[panic_handler] 24 | pub fn panic_handler(_info: &PanicInfo) -> ! { 25 | loop {}; 26 | } 27 | -------------------------------------------------------------------------------- /samples/design-patterns/inheritance/sample.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | sample: 7 | name: Inheritance Pattern 8 | tests: 9 | samples.patterns.inheritance: 10 | platform_allow: qemu_cortex_m3 11 | build_only: true 12 | integration_platforms: 13 | - qemu_cortex_m3 14 | - qemu_x86_64 15 | -------------------------------------------------------------------------------- /samples/design-patterns/opaque/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cmake_minimum_required(VERSION 3.20.0) 6 | 7 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 8 | project(sample) 9 | 10 | target_sources(app PRIVATE src/main.c src/opaque.c) 11 | -------------------------------------------------------------------------------- /samples/design-patterns/opaque/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | CONFIG_ASSERT=y 7 | CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=128 8 | -------------------------------------------------------------------------------- /samples/design-patterns/opaque/sample.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | sample: 7 | name: Opaque Pattern 8 | tests: 9 | samples.patterns.opaque: 10 | platform_allow: qemu_cortex_m3 11 | build_only: true 12 | integration_platforms: 13 | - qemu_cortex_m3 14 | - qemu_x86_64 15 | -------------------------------------------------------------------------------- /samples/design-patterns/opaque/src/main.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "opaque.h" 13 | 14 | struct opaque *do_stack_allocation(void) 15 | { 16 | struct opaque *obj = alloca(opaque_size()); 17 | 18 | opaque_init(obj); 19 | opaque_set_data(obj, 123); 20 | printk("Stack allocated: obj = %p, data = %d\n", obj, opaque_get_data(obj)); 21 | opaque_deinit(obj); 22 | // at this point the opaque is discarded because the function returns 23 | // returning this variable is not valid! 24 | // This will generate compiler error: 25 | //return obj; 26 | return NULL; 27 | } 28 | 29 | struct opaque *do_heap_allocation(void) 30 | { 31 | struct opaque *obj = opaque_new(); 32 | 33 | __ASSERT(obj, "Memory allocation failed!"); 34 | opaque_init(obj); 35 | opaque_set_data(obj, 456); 36 | printk("Heap allocated: obj = %p, data = %d\n", obj, opaque_get_data(obj)); 37 | // returning this object is fine but caller must delete it! 38 | return obj; 39 | } 40 | 41 | void main(void) 42 | { 43 | do_stack_allocation(); 44 | struct opaque *heap = do_heap_allocation(); 45 | 46 | // now we can see what value this prints (remember it was stack allocated!) 47 | printk("Heap pointer data (should be 456): %d\n", opaque_get_data(heap)); 48 | 49 | opaque_deinit(heap); 50 | // we can free the pointer 51 | opaque_free(&heap); 52 | } 53 | -------------------------------------------------------------------------------- /samples/design-patterns/opaque/src/opaque.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include "opaque.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | // actual definition of the struct in private space of the c file 15 | struct opaque { 16 | uint32_t data; 17 | }; 18 | 19 | int opaque_init(struct opaque *self) 20 | { 21 | memset(self, 0, sizeof(*self)); 22 | return 0; 23 | } 24 | 25 | int opaque_deinit(struct opaque *self) 26 | { 27 | // free any internal resources 28 | self->data = 0; 29 | return 0; 30 | } 31 | 32 | size_t opaque_size(void) 33 | { 34 | return sizeof(struct opaque); 35 | } 36 | 37 | void opaque_set_data(struct opaque *self, uint32_t data) 38 | { 39 | self->data = data; 40 | } 41 | 42 | uint32_t opaque_get_data(struct opaque *self) 43 | { 44 | return self->data; 45 | } 46 | 47 | struct opaque *opaque_new(void) 48 | { 49 | return malloc(sizeof(struct opaque)); 50 | } 51 | 52 | void opaque_free(struct opaque **self) 53 | { 54 | free(*self); 55 | *self = NULL; 56 | } 57 | -------------------------------------------------------------------------------- /samples/design-patterns/opaque/src/opaque.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | 11 | struct opaque; // just a declaration 12 | 13 | // init and deinit 14 | int opaque_init(struct opaque *self); 15 | int opaque_deinit(struct opaque *self); 16 | 17 | // size 18 | size_t opaque_size(void); 19 | 20 | void opaque_set_data(struct opaque *self, uint32_t data); 21 | uint32_t opaque_get_data(struct opaque *self); 22 | 23 | // new and free 24 | struct opaque *opaque_new(void); 25 | void opaque_free(struct opaque **self); 26 | -------------------------------------------------------------------------------- /samples/design-patterns/virtual-api/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cmake_minimum_required(VERSION 3.20.0) 6 | 7 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 8 | project(sample) 9 | 10 | add_subdirectory(rust) 11 | 12 | target_sources(app PRIVATE src/main.c src/serial.c src/serial_impl.c) 13 | target_link_libraries(app PRIVATE rust_lib) 14 | -------------------------------------------------------------------------------- /samples/design-patterns/virtual-api/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_lib" 3 | version = "0.1.0" 4 | authors = ["Martin Schröder "] 5 | edition = "2021" 6 | 7 | [lib] 8 | path = "rust/lib.rs" 9 | crate-type = ["staticlib"] 10 | 11 | [dependencies] 12 | -------------------------------------------------------------------------------- /samples/design-patterns/virtual-api/rust/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cargo_build(NAME rust_lib) 6 | -------------------------------------------------------------------------------- /samples/design-patterns/virtual-api/rust/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | use core::panic::PanicInfo; 3 | 4 | extern "C" { 5 | fn serial_out(c: u8); 6 | } 7 | 8 | pub fn printk(msg: &str) { 9 | for c in msg.chars() { 10 | unsafe { 11 | serial_out(c as u8); 12 | } 13 | } 14 | } 15 | 16 | #[no_mangle] 17 | pub extern "C" fn rust_main() -> usize { 18 | printk("RUST main\n"); 19 | 20 | return 0; 21 | } 22 | 23 | #[panic_handler] 24 | pub fn panic_handler(_info: &PanicInfo) -> ! { 25 | loop {}; 26 | } 27 | -------------------------------------------------------------------------------- /samples/design-patterns/virtual-api/sample.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | sample: 7 | name: Virtual API Pattern 8 | tests: 9 | samples.patterns.virtualapi: 10 | platform_allow: qemu_cortex_m3 11 | build_only: true 12 | integration_platforms: 13 | - qemu_cortex_m3 14 | - qemu_x86_64 15 | -------------------------------------------------------------------------------- /samples/design-patterns/virtual-api/src/main.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "serial.h" 13 | #include "serial_impl.h" 14 | 15 | /** 16 | * \brief Output one character 17 | * \param ch character to print 18 | **/ 19 | void serial_out(uint8_t ch) 20 | { 21 | printk("%c", ch); 22 | } 23 | 24 | size_t rust_main(void); 25 | 26 | void main(void) 27 | { 28 | rust_main(); 29 | printk("--- C version ---\n"); 30 | 31 | // initialization of implementation (usually would be done separately from usage below) 32 | struct serial_impl serial; 33 | 34 | serial_impl_init(&serial); 35 | 36 | // get the handle that can be passed around and used with the generic api 37 | const struct serial_ops **handle = serial_impl_to_serial(&serial); 38 | 39 | const char *data = "Hello World!\n"; 40 | 41 | serial_write(handle, data, strlen(data)); 42 | } 43 | -------------------------------------------------------------------------------- /samples/design-patterns/virtual-api/src/serial.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | #include "serial_ops.h" 11 | 12 | /** 13 | * Generic serial device write 14 | * \param handle the handle to a serial device 15 | * \param data data to be written 16 | * \param size size of data to be written 17 | * \returns number of bytes written 18 | **/ 19 | int serial_write(const struct serial_ops **handle, const char *data, size_t size) 20 | { 21 | // here we DO have access to the api so we can use it directly 22 | return (*handle)->write(handle, data, size); 23 | } 24 | -------------------------------------------------------------------------------- /samples/design-patterns/virtual-api/src/serial.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | struct serial_ops; 13 | 14 | int serial_write(const struct serial_ops **handle, const char *data, size_t size); 15 | -------------------------------------------------------------------------------- /samples/design-patterns/virtual-api/src/serial_impl.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | #include "serial_ops.h" 11 | #include "serial_impl.h" 12 | 13 | static int serial_impl_write(const struct serial_ops **handle, const char *data, size_t size) 14 | { 15 | // simple implementation disregarding size 16 | printk("%s", data); 17 | return size; 18 | } 19 | 20 | static const struct serial_ops _ops = { .write = serial_impl_write }; 21 | 22 | void serial_impl_init(struct serial_impl *self) 23 | { 24 | memset(self, 0, sizeof(*self)); 25 | self->serial = &_ops; 26 | } 27 | 28 | const struct serial_ops **serial_impl_to_serial(struct serial_impl *self) 29 | { 30 | return &self->serial; 31 | } 32 | -------------------------------------------------------------------------------- /samples/design-patterns/virtual-api/src/serial_impl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #pragma once 9 | 10 | #include "serial_ops.h" 11 | 12 | struct serial_impl { 13 | const struct serial_ops *serial; 14 | }; 15 | 16 | void serial_impl_init(struct serial_impl *self); 17 | const struct serial_ops **serial_impl_to_serial(struct serial_impl *self); 18 | -------------------------------------------------------------------------------- /samples/design-patterns/virtual-api/src/serial_ops.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #pragma once 9 | 10 | #include 11 | 12 | /** Serial API */ 13 | struct serial_ops { 14 | int (*write)(const struct serial_ops **handle, const char *data, size_t size); 15 | }; 16 | 17 | // You can typedef it like this if you want: 18 | // typedef struct serial_api ** serial_t; 19 | -------------------------------------------------------------------------------- /samples/drivers/example/example_driver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # ~~~ 3 | # Copyright (c) 2022 Martin Schröder 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | # ~~~ 7 | 8 | cmake_minimum_required(VERSION 3.13.1) 9 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 10 | project(example_sensor) 11 | 12 | target_sources(app PRIVATE src/main.c) 13 | 14 | check_clang_tidy(app) 15 | -------------------------------------------------------------------------------- /samples/drivers/example/example_driver/README.md: -------------------------------------------------------------------------------- 1 | # Example driver sample 2 | This sample demonstrates use of example driver. 3 | 4 | ## Building 5 | 6 | This sample can be built and executed on renode as follows: 7 | 8 | ```bash 9 | west build -p -b native_posix samples/drivers/example/example_driver/ -t run 10 | ``` 11 | 12 | ## Running 13 | 14 | ```bash 15 | ./build/zephyr/zephyr.elf 16 | 17 | Example driver initialized! 18 | [00:00:00.000,000] example_driver: Example driver initialized! 19 | *** Booting Zephyr OS build zephyr-v3.0.0 *** 20 | Sample started (v0.0.1) 21 | ``` 22 | 23 | You should see "Example driver initialized" printed in the console. 24 | 25 | -------------------------------------------------------------------------------- /samples/drivers/example/example_driver/boards/custom_board.overlay: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | */ 7 | / { 8 | example_driver { 9 | compatible = "example-driver"; 10 | custom-variable = <1>; 11 | status = "okay"; 12 | }; 13 | }; 14 | -------------------------------------------------------------------------------- /samples/drivers/example/example_driver/boards/native_posix.overlay: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | */ 7 | 8 | / { 9 | example_driver { 10 | compatible = "example-driver"; 11 | custom-variable = <1>; 12 | status = "okay"; 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /samples/drivers/example/example_driver/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | CONFIG_SHELL=n 7 | CONFIG_LOG=y 8 | CONFIG_EXAMPLE_DRIVER=y 9 | CONFIG_EXAMPLE_LIBRARY=y 10 | -------------------------------------------------------------------------------- /samples/drivers/example/example_driver/sample.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | sample: 7 | name: Example sensor sample 8 | tests: 9 | samples.drivers.example.example_driver.release: 10 | build_only: true 11 | integration_platforms: 12 | - native_posix 13 | - custom_board 14 | -------------------------------------------------------------------------------- /samples/drivers/example/example_driver/src/main.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | void main(void) 16 | { 17 | printk("Sample started (v%s)\n", PROJECT_VERSION_STRING); 18 | }; 19 | -------------------------------------------------------------------------------- /samples/drivers/example/example_sensor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # ~~~ 3 | # Copyright (c) 2022 Swedish Embedded Group AB 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | # ~~~ 7 | 8 | cmake_minimum_required(VERSION 3.13.1) 9 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 10 | project(example_sensor) 11 | 12 | target_sources(app PRIVATE src/main.c) 13 | 14 | check_clang_tidy(app) 15 | -------------------------------------------------------------------------------- /samples/drivers/example/example_sensor/README.md: -------------------------------------------------------------------------------- 1 | # Example sensor sample 2 | This sample demonstrates use of example sensor which is implemented in Renode. 3 | 4 | ## Building 5 | 6 | This sample can be built and executed on renode as follows: 7 | 8 | ```bash 9 | ./scripts/build 10 | renode renode/samples/drivers/example/example_sensor/custom_board.resc 11 | ``` 12 | 13 | ## Running 14 | Once renode console is active, you can simulate new samples being available by 15 | executing: 16 | 17 | ```bash 18 | start 19 | sysbus.spi1.exampleSensor Temperature 12.0 20 | ``` 21 | 22 | The UART console should then print the temperature received by the sample. 23 | -------------------------------------------------------------------------------- /samples/drivers/example/example_sensor/boards/custom_board.overlay: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | */ 7 | &spi1 { 8 | pinctrl-0 = <&spi1_sck_pa5 &spi1_miso_pa6 &spi1_mosi_pa7>; 9 | pinctrl-names = "default"; 10 | cs-gpios = < 11 | &gpiob 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP) 12 | >; 13 | status = "okay"; 14 | 15 | example_sensor: example_sensor@0{ 16 | reg = <0>; 17 | compatible = "example-sensor"; 18 | gpios = <&gpioa 4 GPIO_ACTIVE_LOW>; 19 | spi-max-frequency = <1000000>; 20 | status = "okay"; 21 | }; 22 | }; 23 | -------------------------------------------------------------------------------- /samples/drivers/example/example_sensor/doc/img/example_sensor.drawio: -------------------------------------------------------------------------------- 1 | 3ZhNb6MwEIZ/DceVsB0+cmxotmVX2UbyYbVHN7iAajAyTiH769cppoBMN62SBokLMu/YZvzM2B5hoSCr7wQpkg2PKLOgHdUWurUg9BFUz6NwaARviRohFmnUSKATcPqXatHW6j6NaDnoKDlnMi2G4o7nOd3JgUaE4NWw2xNnw68WJKaGgHeEmervNJKJXpZjd/o9TeOk/TKwtSUjbWctlAmJeNWT0NpCgeBcNq2sDig7smu5NOO+v2N9c0zQXH5kwA+8YaGzgr9I6YXJH3sVpPU3HZ0XwvZ6wdpZeWgJCL7PI3qcxLbQqkpSSXFBdkdrpUKutERmTL0B1TSd0n6+UCFp3ZO0k3eUZ1SKg+qircjXwHTGwJZo1fEHLdSkzx5pkeiYx29zd1hUQ5P5BKWFQWm7cs8D9ZQyFnDGxetYFDnUjxZKL6Xgz7Rn8eEjct3LoF24Q7RoBO1ihCz8KrBgaZDF2xBcFC0FCq43hnbpeohcCC1ans7aq6KF5tbe3jgzSFqIpiaLRsjO4TiAztRkRw7aG28OZL2pyfqnL/pYcS3eXbwusMhj293+LBQHfOBid656sZvXz3nJRlga56otGudHUun/0TnNcjpWbfR6sAI8/d48F6hORjD1fQ2AgXddk6xQYKGNaV4qFpOXRefCbk+CkY1vX/U49AzYOPg5m2SevEJyDLybED/Mhu/kdZJr8n3A4Wz4fl21pF67Py6vtt5vK7T+Bw== -------------------------------------------------------------------------------- /samples/drivers/example/example_sensor/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Swedish Embedded Group AB 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | CONFIG_SHELL=n 7 | CONFIG_LOG=y 8 | CONFIG_SPI=y 9 | CONFIG_SPI_STM32_INTERRUPT=n 10 | CONFIG_EXAMPLE_SENSOR=y 11 | CONFIG_EXAMPLE_LIBRARY=y 12 | -------------------------------------------------------------------------------- /samples/drivers/example/example_sensor/sample.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | sample: 7 | name: Example sensor sample 8 | tests: 9 | samples.drivers.example.example_sensor.release: 10 | build_only: true 11 | integration_platforms: 12 | - native_posix 13 | - custom_board 14 | -------------------------------------------------------------------------------- /samples/drivers/example/example_sensor/src/main.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | void main(void) 16 | { 17 | printk("Sample started (v%s)\n", PROJECT_VERSION_STRING); 18 | 19 | while (true) { 20 | const struct device *dev = device_get_binding("EXAMPLE_SENSOR"); 21 | struct sensor_value val; 22 | 23 | printk("Fetching sample...\n"); 24 | sensor_sample_fetch(dev); 25 | if (sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &val) == 0) { 26 | printk("Temperature: %d.%d\n", val.val1, val.val2); 27 | } else { 28 | printk("Failed to read sensor\n"); 29 | } 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /samples/drivers/gpio/mcp23s17/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cmake_minimum_required(VERSION 3.13.1) 6 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 7 | project(sample) 8 | 9 | target_sources(app PRIVATE src/main.c) 10 | 11 | check_clang_tidy(app) 12 | -------------------------------------------------------------------------------- /samples/drivers/gpio/mcp23s17/README.md: -------------------------------------------------------------------------------- 1 | # MCP23S17 Sample 2 | This sample demonstrates use of example sensor which is implemented in Renode. 3 | 4 | ## Building 5 | 6 | This sample can be built and executed on renode as follows: 7 | 8 | ```bash 9 | ./scripts/build 10 | renode renode/samples/drivers/example/example_sensor/custom_board.resc 11 | ``` 12 | 13 | ## Running 14 | Once renode console is active, you can simulate new samples being available by 15 | executing: 16 | 17 | ```bash 18 | start 19 | sysbus.spi1.exampleSensor Temperature 12.0 20 | ``` 21 | 22 | The UART console should then print the temperature received by the sample. 23 | -------------------------------------------------------------------------------- /samples/drivers/gpio/mcp23s17/boards/custom_board.overlay: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | */ 7 | &spi1 { 8 | pinctrl-0 = <&spi1_sck_pa5 &spi1_miso_pa6 &spi1_mosi_pa7>; 9 | pinctrl-names = "default"; 10 | cs-gpios = < 11 | &gpiob 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP) 12 | >; 13 | status = "okay"; 14 | 15 | mcp23s17: mcp23s17@0 { 16 | compatible = "microchip,mcp23s17v2"; 17 | spi-max-frequency = <1000000>; 18 | reg = <0>; 19 | gpio-controller; 20 | #gpio-cells = <2>; 21 | ngpios = <16>; 22 | inta-gpios = < 23 | &gpiob 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP) 24 | >; 25 | intb-gpios = < 26 | &gpiob 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP) 27 | >; 28 | status = "okay"; 29 | }; 30 | }; 31 | -------------------------------------------------------------------------------- /samples/drivers/gpio/mcp23s17/doc/building.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Building the sample 7 | ------------------- 8 | 9 | Build and run the sample in the simulator like this: 10 | 11 | .. code-block:: 12 | 13 | west build -p -b custom_board -s \ 14 | samples/drivers/gpio/mcp23s17 15 | west build -t testbench 16 | 17 | This will run the main testbench which you can access through your browser at 18 | localhost:8000. 19 | 20 | You can also run the automatic robot framework test using: 21 | 22 | .. code-block:: 23 | 24 | west build -t robotbench 25 | 26 | This test runs fully on automatic and checks that the use case actually works 27 | (it is also run through CI) 28 | 29 | It uses simulation just like the test bench: 30 | 31 | .. image:: img/robotbench-run.jpg 32 | -------------------------------------------------------------------------------- /samples/drivers/gpio/mcp23s17/doc/img/robotbench-run.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/samples/drivers/gpio/mcp23s17/doc/img/robotbench-run.jpg -------------------------------------------------------------------------------- /samples/drivers/gpio/mcp23s17/doc/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | MCP23S17 GPIO Expander Sample 7 | ############################# 8 | 9 | This sample is used for running robot framework test cases to verify that the 10 | MCP23S17 has support for all use cases. 11 | 12 | .. toctree:: 13 | :maxdepth: 1 14 | :caption: Contents 15 | 16 | main-features.rst 17 | building.rst 18 | interaction.rst 19 | -------------------------------------------------------------------------------- /samples/drivers/gpio/mcp23s17/doc/main-features.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Main features 7 | ============= 8 | 9 | This sample shows how to use an SPI peripheral driver. Together with the 10 | nucleo401re_mcp23s17 testbench, it shows how to simulate and visualize a custom 11 | board setup. 12 | -------------------------------------------------------------------------------- /samples/drivers/gpio/mcp23s17/doc/mcp23s17.drawio: -------------------------------------------------------------------------------- 1 | 3Zldb5swFIZ/DZeTMOYjXBbWtXRKi8SkaZducAOaiZHjDLJfP6eYBGaiJCqJK24i+/UH9uNzOCfGgGFRPzBUZnOaYmJYZlob8KthWY5ni9+dsJWC7TXCkuVpI4GDkOR/sRRNqW7yFK97HTmlhOdlX1zQ1QoveE9DjNGq3+2Nkv5TS7TEipAsEFHVn3nKs0adOeZBf8T5MmufDEzZUqC2sxTWGUpp1ZHgvQFDRilvSkUdYrJj13Jpxn070rpfGMMrfs6Ap2ROIiewntHai7JfZhDm9RfLb6b5g8hG7liulm9bBIxuVinezWIaMKiynOOkRItdayXOXGgZL4ioAVGU02HGcX10oWC/fWE2mBaYs63oIgfAmSQmTQZCWa8OBwBaqlkHvis1JM98uZ/6gEUUJJlLKH1+SJZ5JqS9ODolR6EUB97HQL3lhISUUPY+FqYOnqW20Nec0d+40zKzXqHrjoPWdv9D66to7QGyVwMLVCdN4giMihYDAdcbQuu7HkQjoYX+aau9Kdp24p7RziZgtNDWTRYMkPWnQNbVTVYNR/GdMwGy1kCgvy1ZOEDWnQJZRzdZe4DsJJIDTzNZTwGrUF0KrOXRvct/Tui17W5eysQBp6M6cIaggGtRUR35Y7Z2luUcPx8V3Sk0wL8WGldBEyaf0hEvwSktT3umrobmeRhbMAHjvuvGytYvQdw6+4BvmzdlrPp29PzjbiomDHQn7kAN1YJvMBm+2tN3NWIn4fep4NWewqu3UPMoeZkKXu15vJo9zF+SaCp4dSfzrfd08D7E0bjWq+emb+gSfyS0onr4ivLe1vkUBe//AQ== -------------------------------------------------------------------------------- /samples/drivers/gpio/mcp23s17/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | CONFIG_SHELL=y 7 | CONFIG_GPIO_SHELL=y 8 | CONFIG_LOG=y 9 | CONFIG_SPI=y 10 | CONFIG_SPI_STM32_INTERRUPT=n 11 | CONFIG_GPIO_MCP23S17V2=y 12 | -------------------------------------------------------------------------------- /samples/drivers/gpio/mcp23s17/sample.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | sample: 7 | name: MCP23S17 8 | tests: 9 | samples.drivers.gpio.mcp23s17.release: 10 | platform_allow: custom_board 11 | build_only: true 12 | integration_platforms: 13 | - native_posix 14 | - custom_board 15 | extra_configs: 16 | - CONFIG_TESTBENCH_NUCLEO401RE_MCP23S17=y 17 | -------------------------------------------------------------------------------- /samples/drivers/gpio/mcp23s17/src/main.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | struct application { 18 | struct gpio_callback cb; 19 | }; 20 | 21 | static struct application app; 22 | 23 | static void irq_gpio(const struct device *dev, struct gpio_callback *cb, uint32_t pins) 24 | { 25 | (void)cb; 26 | for (unsigned int c = 0; c < 8; c++) { 27 | if (((1 << c) & pins) == 0) 28 | continue; 29 | int r = gpio_pin_get(dev, c); 30 | 31 | gpio_pin_set(dev, c + 8, r); 32 | printk("%s: PIN: %d, Value: %d\n", dev->name, c, r); 33 | } 34 | } 35 | 36 | void main(void) 37 | { 38 | printk("MCP23S17 Sample (v%s)\n", PROJECT_VERSION_STRING); 39 | 40 | const struct device *dev = device_get_binding("GPIO_E0"); 41 | 42 | if (!dev) { 43 | printk("No device\n"); 44 | return; 45 | } 46 | 47 | for (unsigned int c = 0; c < 8; c++) { 48 | if (gpio_pin_configure(dev, c, GPIO_INPUT) != 0) { 49 | printk("Error initializing INTA gpio\n"); 50 | return; 51 | } 52 | if (gpio_pin_interrupt_configure(dev, c, GPIO_INT_EDGE_TO_ACTIVE) != 0) { 53 | printk("Error configuring interrupt on INTA gpio\n"); 54 | return; 55 | } 56 | } 57 | 58 | for (unsigned int c = 8; c < 16; c++) { 59 | if (gpio_pin_configure(dev, c, GPIO_OUTPUT) != 0) { 60 | printk("Error initializing INTA gpio\n"); 61 | return; 62 | } 63 | } 64 | 65 | gpio_init_callback(&app.cb, irq_gpio, 0x00ff); 66 | if (gpio_add_callback(dev, &app.cb) != 0) { 67 | printk("Error setting callback for GPIO\n"); 68 | return; 69 | } 70 | }; 71 | -------------------------------------------------------------------------------- /samples/hdl/verilog/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # ~~~ 3 | # Copyright (c) 2022 Martin Schröder 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | # ~~~ 7 | 8 | cmake_minimum_required(VERSION 3.13.1) 9 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 10 | project(sample) 11 | 12 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/yosys.cfg.in 13 | ${CMAKE_CURRENT_BINARY_DIR}/yosys.cfg) 14 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/formal.sby.in 15 | ${CMAKE_CURRENT_BINARY_DIR}/formal.sby) 16 | execute_process( 17 | COMMAND yosys-config --datdir 18 | OUTPUT_STRIP_TRAILING_WHITESPACE 19 | OUTPUT_VARIABLE YOSYS_DATA_DIR) 20 | message(${YOSYS_DATA_DIR}/include) 21 | zephyr_include_directories(${YOSYS_DATA_DIR}/include) 22 | 23 | add_custom_command( 24 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zephyr/include/generated/plc.hpp 25 | COMMENT "Generating C++ code from HDL..." 26 | COMMAND yosys -s ${CMAKE_CURRENT_BINARY_DIR}/yosys.cfg) 27 | 28 | add_custom_target( 29 | formal 30 | COMMENT "Generating C++ code from HDL..." 31 | COMMAND sby -f ${CMAKE_CURRENT_BINARY_DIR}/formal.sby) 32 | 33 | target_sources( 34 | app PRIVATE src/main.cpp 35 | ${CMAKE_CURRENT_BINARY_DIR}/zephyr/include/generated/plc.hpp) 36 | 37 | add_dependencies(app formal) 38 | -------------------------------------------------------------------------------- /samples/hdl/verilog/formal.sby.in: -------------------------------------------------------------------------------- 1 | [options] 2 | mode prove 3 | depth 10 4 | 5 | [engines] 6 | smtbmc 7 | 8 | [script] 9 | read -formal ${CMAKE_CURRENT_SOURCE_DIR}/src/plc.v 10 | prep -top plc 11 | 12 | [files] 13 | ${CMAKE_CURRENT_SOURCE_DIR}/src/plc.v 14 | -------------------------------------------------------------------------------- /samples/hdl/verilog/plc/config.sby: -------------------------------------------------------------------------------- 1 | [options] 2 | mode prove 3 | depth 10 4 | 5 | [engines] 6 | smtbmc 7 | 8 | [script] 9 | read -formal src/plc.v 10 | prep -top src/plc 11 | 12 | [files] 13 | src/plc.v 14 | -------------------------------------------------------------------------------- /samples/hdl/verilog/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | CONFIG_ASSERT=y 7 | CONFIG_NEWLIB_LIBC=y 8 | CONFIG_CPLUSPLUS=y 9 | CONFIG_LIB_CPLUSPLUS=y 10 | -------------------------------------------------------------------------------- /samples/hdl/verilog/sample.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | sample: 7 | name: Verilog integration sample 8 | tests: 9 | samples.hdl.verilog: 10 | build_only: true 11 | integration_platforms: 12 | - custom_board 13 | - native_posix 14 | -------------------------------------------------------------------------------- /samples/hdl/verilog/yosys.cfg.in: -------------------------------------------------------------------------------- 1 | read_verilog ${CMAKE_CURRENT_SOURCE_DIR}/src/plc.v; 2 | write_cxxrtl ${CMAKE_CURRENT_BINARY_DIR}/zephyr/include/generated/plc.hpp 3 | -------------------------------------------------------------------------------- /samples/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Samples 7 | ####### 8 | 9 | .. toctree:: 10 | :maxdepth: 1 11 | :caption: Contents 12 | 13 | drivers/gpio/mcp23s17/doc/index.rst 14 | renode/nativesimulation/doc/index.rst 15 | -------------------------------------------------------------------------------- /samples/lib/control/dcmotor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cmake_minimum_required(VERSION 3.13.1) 6 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 7 | project(sample) 8 | 9 | target_sources(app PRIVATE src/main.c) 10 | zephyr_compile_definitions(-DM_PI=3.1416) 11 | 12 | check_clang_tidy(app) 13 | -------------------------------------------------------------------------------- /samples/lib/control/dcmotor/boards/custom_board.overlay: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | */ 7 | &adc1 { 8 | reg = < 0x70000400 0x3ff >; 9 | status = "okay"; 10 | pinctrl-0 = < &adc1_in0_pa0 >; 11 | pinctrl-names = "default"; 12 | }; 13 | 14 | &timers1 { 15 | reg = < 0x70000000 0x3ff >; 16 | status = "okay"; 17 | pwm { 18 | pinctrl-0 = < &tim1_ch1_pa8 >; 19 | pinctrl-names = "default"; 20 | status = "okay"; 21 | }; 22 | }; 23 | -------------------------------------------------------------------------------- /samples/lib/control/dcmotor/boards/custom_board.repl: -------------------------------------------------------------------------------- 1 | using "platforms/cpus/stm32f4.repl" 2 | 3 | device: SocketPeripheral @ sysbus <0x70000000, +0x800> 4 | IRQ -> gpioPortB@8 5 | -------------------------------------------------------------------------------- /samples/lib/control/dcmotor/boards/custom_board.resc: -------------------------------------------------------------------------------- 1 | :name: Renode interrupt control sample 2 | :description: This sample shows interrupt based interaction 3 | 4 | using sysbus 5 | 6 | mach create 7 | machine LoadPlatformDescription $ORIGIN/custom_board.repl 8 | 9 | device PeripheralPath @/usr/bin/instrument-dcmotor 10 | 11 | showAnalyzer sysbus.usart2 12 | 13 | logLevel 3 14 | 15 | : Uncomment this line to show debug messages 16 | :logLevel 0 sysbus.device 17 | logLevel 0 sysbus.timer1 18 | sysbus LogPeripheralAccess sysbus.timer1 19 | logLevel 0 sysbus.usart2 20 | 21 | macro reset 22 | """ 23 | sysbus LoadELF $bin 24 | """ 25 | 26 | runMacro $reset 27 | -------------------------------------------------------------------------------- /samples/lib/control/dcmotor/design.m: -------------------------------------------------------------------------------- 1 | dir = fileparts(mfilename('fullpath')); 2 | path(strcat(dir, "/../../../../../modules/lib/control/octave/"), path); 3 | 4 | pkg load control pkg load symbolic 5 | 6 | #Step 1 : start with a continuous time state space model 7 | syms s J b K R L z Ts A = [-b / J K / J; - K / L - R / L]; 8 | B = [0; 1 / L]; 9 | C = [1 0]; 10 | D = 0; 11 | sys = ss(A, B, C, D); 12 | 13 | #Step 2 : transform into a continuous time transfer function 14 | Hz = tf(sys, Ts) 15 | 16 | #Step 4 : extract the difference equation 17 | [N, D] = numden(Hz) 18 | 19 | #Step 5 : generate C code 20 | ccode(Hz) 21 | 22 | #Step 6 : discrete time state space model 23 | syms s J b K R L z Ts 24 | #J = 0.01; b = 0.1; K = 0.01; R = 1; L = 0.5; Ts = 0.01; 25 | A = [-b / J K / J; - K / L - R / L]; 26 | B = [0; 1 / L]; 27 | C = [1 0]; 28 | D = [0]; 29 | #c2d(ss(A, B, C, D), Ts, 'tustin') 30 | 31 | #Ad = simplify(sym(inv(Ts * eye(size(A)) - A) * (Ts * eye(size(A)) + A))); 32 | sys = ss(A, B, C, D); 33 | sys = c2d(A, B, C, D, Ts); 34 | display(sys) ccode(sys) 35 | 36 | Ad = [-500.0 / 501.0 200.0 / 201401.0; - 4.0 / 201401.0 - 498.0 / 503.0]; 37 | Bd = [(250.0 / 7909.0) * pi; (455.0 / 1438.0) * pi]; 38 | Cd = [1.0 / 501.0 200.0 / 201401.0]; 39 | Dd = [(250.0 / 7909.0) * pi]; 40 | Ts = 0.01; 41 | 42 | #bode(ss(Ad, Bd, Cd, Dd, Ts), c2d(ss(A, B, C, D), Ts)) 43 | #input("") 44 | -------------------------------------------------------------------------------- /samples/lib/control/dcmotor/doc/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/samples/lib/control/dcmotor/doc/screenshot.png -------------------------------------------------------------------------------- /samples/lib/control/dcmotor/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | CONFIG_PWM=y 6 | CONFIG_PWM_STM32=y 7 | CONFIG_CONTROL=y 8 | CONFIG_NEWLIB_LIBC=y 9 | CONFIG_INSTRUMENTS=y 10 | -------------------------------------------------------------------------------- /samples/lib/control/dcmotor/sample.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | sample: 7 | name: DC Motor Simulation And Control Sample 8 | tests: 9 | samples.lib.control.dcmotor: 10 | platform_allow: custom_board 11 | build_only: true 12 | integration_platforms: 13 | - custom_board 14 | -------------------------------------------------------------------------------- /samples/lib/example/example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cmake_minimum_required(VERSION 3.13.1) 6 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 7 | project(shell) 8 | 9 | target_sources(app PRIVATE src/main.c) 10 | 11 | check_clang_tidy(app) 12 | -------------------------------------------------------------------------------- /samples/lib/example/example/README.md: -------------------------------------------------------------------------------- 1 | # Example library 2 | This sample demonstrates use of example library module in your application. 3 | 4 | ## Building and running 5 | 6 | This sample can be built and run as follows: 7 | 8 | ```bash 9 | west build -p -b native_posix samples/lib/example/example -t run 10 | ``` 11 | -------------------------------------------------------------------------------- /samples/lib/example/example/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | CONFIG_SHELL=y 7 | CONFIG_EXAMPLE_LIBRARY=y 8 | -------------------------------------------------------------------------------- /samples/lib/example/example/sample.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | sample: 7 | name: Example sample 8 | tests: 9 | samples.lib.example.example.release: 10 | build_only: true 11 | integration_platforms: 12 | - native_posix 13 | - custom_board 14 | -------------------------------------------------------------------------------- /samples/lib/example/example/src/main.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | void main(void) 14 | { 15 | printk("Sample started (v%s)\n", PROJECT_VERSION_STRING); 16 | struct example_object _ex; 17 | 18 | if (example_object_init(&_ex) != 0) { 19 | printk("Could not initialize example object\n"); 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /samples/renode/interrupts/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cmake_minimum_required(VERSION 3.13.1) 6 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 7 | project(sample) 8 | 9 | target_sources(app PRIVATE src/main.c) 10 | 11 | check_clang_tidy(app) 12 | -------------------------------------------------------------------------------- /samples/renode/interrupts/boards/custom_board.repl: -------------------------------------------------------------------------------- 1 | using "platforms/cpus/stm32f4.repl" 2 | 3 | device: SocketPeripheral @ sysbus <0x70000000, +0x100> 4 | IRQ -> gpioPortB@8 5 | -------------------------------------------------------------------------------- /samples/renode/interrupts/boards/custom_board.resc: -------------------------------------------------------------------------------- 1 | :name: Renode interrupt control sample 2 | :description: This sample shows interrupt based interaction 3 | 4 | using sysbus 5 | 6 | mach create 7 | machine LoadPlatformDescription $ORIGIN/custom_board.repl 8 | 9 | device PeripheralPath @/usr/bin/instrument-keypad 10 | 11 | showAnalyzer sysbus.usart2 12 | 13 | logLevel 3 14 | 15 | : Uncomment this line to show debug messages 16 | :logLevel 0 sysbus.device 17 | logLevel 0 sysbus.usart2 18 | 19 | macro reset 20 | """ 21 | sysbus LoadELF $bin 22 | """ 23 | 24 | runMacro $reset 25 | -------------------------------------------------------------------------------- /samples/renode/interrupts/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | CONFIG_INSTRUMENTS=y 7 | -------------------------------------------------------------------------------- /samples/renode/interrupts/sample.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | sample: 7 | name: Socket peripheral interrupt sample 8 | tests: 9 | samples.lib.renode.interrupts: 10 | platform_allow: custom_board 11 | build_only: true 12 | integration_platforms: 13 | - custom_board 14 | -------------------------------------------------------------------------------- /samples/renode/interrupts/src/main.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * 5 | * Consulting: https://swedishembedded.com/go 6 | * Training: https://swedishembedded.com/tag/training 7 | * 8 | * This example shows how to send interrupt notifications back to the firmware. 9 | **/ 10 | 11 | #include 12 | 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | static volatile struct keypad_instrument *vdev = ((volatile struct keypad_instrument *)0x70000000); 23 | 24 | #define IRQ_PIN 8 25 | 26 | struct application { 27 | struct gpio_callback irq_cb; 28 | }; 29 | 30 | static struct application app; 31 | 32 | static void irq_handler(const struct device *dev, struct gpio_callback *cb, uint32_t pins) 33 | { 34 | (void)dev; 35 | (void)cb; 36 | (void)pins; 37 | // read interrupt flags 38 | uint32_t intf = vdev->keys_changed; 39 | 40 | printk("IRQ triggered (INTF: %08x)\n", intf); 41 | } 42 | 43 | void main(void) 44 | { 45 | printk("Renode interrupt handling sample\n"); 46 | 47 | const struct device *dev = device_get_binding("GPIOB"); 48 | 49 | if (!dev) { 50 | printk("Could not get GPIO\n"); 51 | return; 52 | } 53 | 54 | if (gpio_pin_configure(dev, IRQ_PIN, GPIO_INPUT) != 0) { 55 | printk("Error initializing INTA gpio\n"); 56 | return; 57 | } 58 | if (gpio_pin_interrupt_configure(dev, IRQ_PIN, GPIO_INT_EDGE_TO_ACTIVE) != 0) { 59 | printk("Error configuring interrupt on INTA gpio\n"); 60 | return; 61 | } 62 | 63 | gpio_init_callback(&app.irq_cb, irq_handler, BIT(IRQ_PIN)); 64 | if (gpio_add_callback(dev, &app.irq_cb) != 0) { 65 | printk("Error setting callback for GPIO\n"); 66 | return; 67 | } 68 | 69 | while (1) { 70 | k_sleep(K_MSEC(10)); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /samples/renode/nativesimulation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cmake_minimum_required(VERSION 3.13.1) 6 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 7 | project(sample) 8 | 9 | target_sources(app PRIVATE src/main.c) 10 | 11 | set(_renode_infrastructure ${PROJECT_BASE}/../renode/src/Infrastructure) 12 | 13 | add_custom_target( 14 | peripheral 15 | COMMAND 16 | gcc -I${PROJECT_BASE}/include/ 17 | -I${_renode_infrastructure}/src/Emulator/Cores/renode/include/ -fPIC -shared 18 | -o plugin/peripheral.so plugin/peripheral.c 19 | ${PROJECT_BASE}/lib/renode/renode.c 20 | COMMENT "Building peripheral device" 21 | WORKING_DIRECTORY ${APPLICATION_SOURCE_DIR}) 22 | 23 | add_dependencies(app peripheral) 24 | -------------------------------------------------------------------------------- /samples/renode/nativesimulation/boards/custom_board.repl: -------------------------------------------------------------------------------- 1 | using "platforms/cpus/stm32f4.repl" 2 | 3 | shared: SharedLibraryPeripheral @ sysbus <0x70000000, +0x100> 4 | -------------------------------------------------------------------------------- /samples/renode/nativesimulation/boards/custom_board.resc: -------------------------------------------------------------------------------- 1 | :name: Renode cosimulation sample 2 | :description: Custom cosimulation board 3 | 4 | using sysbus 5 | 6 | mach create 7 | machine LoadPlatformDescription $ORIGIN/custom_board.repl 8 | 9 | shared LibraryPath $ORIGIN/../plugin/peripheral.so 10 | 11 | showAnalyzer sysbus.usart2 12 | 13 | logLevel 3 14 | 15 | logLevel 0 sysbus.shared 16 | logLevel 0 sysbus.usart2 17 | 18 | sysbus.shared WriteDoubleWord 1 1234 19 | sysbus.shared ReadDoubleWord 1 20 | 21 | macro reset 22 | """ 23 | sysbus LoadELF $bin 24 | """ 25 | 26 | runMacro $reset 27 | -------------------------------------------------------------------------------- /samples/renode/nativesimulation/doc/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Peripheral Simulation Using Native Shared Library 7 | ################################################# 8 | 9 | This sample shows how to write a plugin for interfacing with a shared library 10 | allowing you to memory map your new simulated peripheral into your 11 | microcontroller address space in simulation. 12 | 13 | .. code-block:: text 14 | 15 | cperipheral: SharedLibraryPeripheral @ sysbus <0x70000000, +0x100> 16 | 17 | Which allows us to then access our peripheral from the firmware side directly as 18 | though it was mapped into processor address space: 19 | 20 | .. code-block:: c 21 | 22 | #define REG_BASE (volatile uint32_t *)0x70000000; 23 | #define REG_IN *(REG_BASE + 0x01) 24 | #define REG_OUT *(REG_BASE + 0x02) 25 | 26 | REG_IN = 555; 27 | printf("REG_OUT = %08x\n", REG_OUT); 28 | 29 | This gives us flexibility to create powerful simulation tools that run along 30 | side of our firmware such as dynamic model simulation, physics simulation or 31 | other types of sensor simulation. 32 | -------------------------------------------------------------------------------- /samples/renode/nativesimulation/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | CONFIG_SHELL=y 7 | -------------------------------------------------------------------------------- /samples/renode/nativesimulation/src/main.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #define REG_BASE ((volatile uint32_t *)0x70000000) 13 | #define REG_IN *(REG_BASE + 0x01) 14 | #define REG_OUT *(REG_BASE + 0x02) 15 | 16 | void main(void) 17 | { 18 | printk("Native Simulation Sample (v%s)\n", PROJECT_VERSION_STRING); 19 | 20 | // this is peripheral address 21 | printk("Previous return value (%p) = %08x\n", ®_OUT, REG_OUT); 22 | REG_IN = 555; 23 | printk("New return value = %08x\n", REG_OUT); 24 | }; 25 | -------------------------------------------------------------------------------- /samples/rust/basic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cmake_minimum_required(VERSION 3.20.0) 6 | 7 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 8 | project(rust_basic) 9 | 10 | add_subdirectory(rslib) 11 | 12 | target_sources(app PRIVATE src/main.c) 13 | target_link_libraries(app PRIVATE rust_lib) 14 | -------------------------------------------------------------------------------- /samples/rust/basic/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_lib" 3 | version = "0.1.0" 4 | authors = ["Martin Schröder "] 5 | edition = "2018" 6 | 7 | [lib] 8 | path = "rslib/lib.rs" 9 | crate-type = ["staticlib"] 10 | 11 | -------------------------------------------------------------------------------- /samples/rust/basic/README.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | .. _rust_basic: 7 | 8 | Rust Basic Sample 9 | ################# 10 | 11 | Overview 12 | ******** 13 | 14 | This sample shows minimal code required to include rust code as a library into 15 | your Zephyr application. The main method of this sample calls a rust function, 16 | then the rust function calls Zephyr printk function to print a message and then 17 | calls a C function in the main application. 18 | 19 | Building and Running 20 | ******************** 21 | 22 | This application can be built and executed on QEMU as follows: 23 | 24 | .. zephyr-app-commands:: 25 | :zephyr-app: samples/rust/basic 26 | :host-os: unix 27 | :board: qemu_x86 28 | :goals: run 29 | :compact: 30 | 31 | To build for another board, change "qemu_x86" above to that board's name. 32 | 33 | Sample Output 34 | ============= 35 | 36 | .. code-block:: console 37 | 38 | Message from RUST: Hello World! 123 39 | Message from C: Hello World! qemu_x86_64 40 | 41 | Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`. 42 | -------------------------------------------------------------------------------- /samples/rust/basic/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | # nothing here 7 | -------------------------------------------------------------------------------- /samples/rust/basic/rslib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cargo_build(NAME rust_lib) 6 | -------------------------------------------------------------------------------- /samples/rust/basic/rslib/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | use core::panic::PanicInfo; 3 | 4 | extern "C" { 5 | fn print_message_from_c(); 6 | fn printk(fmt: *const u8, ...); 7 | } 8 | 9 | #[no_mangle] 10 | pub extern "C" fn print_message_from_rust() -> () { 11 | let v = 123; 12 | unsafe { 13 | printk("Message from RUST: Hello World! %d\n".as_ptr(), v); 14 | print_message_from_c(); 15 | } 16 | } 17 | 18 | #[panic_handler] 19 | pub fn panic_handler(_info: &PanicInfo) -> ! { 20 | loop {}; 21 | } 22 | -------------------------------------------------------------------------------- /samples/rust/basic/sample.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | sample: 7 | description: Rust Hello World sample 8 | application 9 | name: rust hello world 10 | common: 11 | tags: introduction 12 | platform_allow: qemu_cortex_m3 13 | integration_platforms: 14 | - qemu_cortex_m3 15 | harness: console 16 | harness_config: 17 | type: one_line 18 | regex: 19 | - "Message from RUST: Hello World! (.*)" 20 | tests: 21 | sample.rust.basic: 22 | tags: introduction 23 | -------------------------------------------------------------------------------- /samples/rust/basic/src/main.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | 10 | void print_message_from_rust(void); 11 | 12 | void print_message_from_c(void) 13 | { 14 | printk("Message from C: Hello World! %s\n", CONFIG_BOARD); 15 | } 16 | 17 | void main(void) 18 | { 19 | print_message_from_rust(); 20 | } 21 | -------------------------------------------------------------------------------- /scripts/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: Apache-2.0 3 | # Copyright (c) 2022 Martin Schröder 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | 7 | ROOT="$(realpath "$(dirname "${BASH_SOURCE[0]}")/..")" 8 | 9 | export CMAKE_PREFIX_PATH=/opt/toolchains 10 | export PATH=/opt/oss-cad-suite/bin/:$PATH 11 | 12 | set -e 13 | 14 | source "${ROOT}/VERSION" 15 | source "${ROOT}/../zephyr/zephyr-env.sh" 16 | west zephyr-export 17 | 18 | # Build applications and samples 19 | "$ROOT/../zephyr/scripts/twister" \ 20 | -p custom_board \ 21 | -c \ 22 | -O build-apps \ 23 | -v \ 24 | -i \ 25 | -T apps \ 26 | -T samples || { 27 | echo "Error while trying to build project" 28 | exit 1 29 | } 30 | 31 | # Build releases 32 | "${ROOT}/scripts/release" -b custom_board -s apps/shell 33 | -------------------------------------------------------------------------------- /scripts/build-doc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: Apache-2.0 3 | # Copyright (c) 2022 Martin Schröder 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | 7 | ROOT="$(realpath "$(dirname "${BASH_SOURCE[0]}")/..")" 8 | 9 | set -e 10 | 11 | . ${ROOT}/VERSION 12 | . ${ROOT}/../zephyr/zephyr-env.sh 13 | 14 | BUILD_DIR=build-doc 15 | SDK_ONLY=0 16 | 17 | # Parse arguments (standard way of doing it in bash) 18 | while [[ $# -gt 0 ]]; do 19 | case $1 in 20 | --sdk-only) 21 | SDK_ONLY=1 22 | shift 23 | ;; 24 | esac 25 | done 26 | 27 | # Build documentation 28 | (mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} && cmake ../doc) 29 | if [[ -z "$SDK_ONLY" ]]; then 30 | make -C ${BUILD_DIR} build-all pdf 2>&1 | tee ${BUILD_DIR}/build.log 31 | else 32 | make -C ${BUILD_DIR} sdk-all sdk-pdf 2>&1 | tee ${BUILD_DIR}/build.log 33 | fi 34 | 35 | cat ${BUILD_DIR}/build.log | \ 36 | grep -v "Not copying tabs assets" | \ 37 | grep WARNING && { 38 | echo "ERROR: documentation has warnings!" 39 | # Disabling this for now since there are many zephyr warnings that need to be fixed 40 | #exit 1 41 | } 42 | 43 | [[ -f ${BUILD_DIR}/latex/sdk/swedishembedded.pdf ]] && { 44 | VERSION="$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH" 45 | DOC=$BUILD_DIR/latex/sdk/Swedish-Embedded-Platform-SDK-v$VERSION.pdf 46 | mv "$BUILD_DIR/latex/sdk/swedishembedded.pdf" "$DOC" 47 | echo "Documentation ready in $DOC" 48 | } 49 | 50 | -------------------------------------------------------------------------------- /scripts/checkpatch/typedefsfile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/scripts/checkpatch/typedefsfile -------------------------------------------------------------------------------- /scripts/ci/check-file-sorted: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: Apache-2.0 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | set -e 7 | 8 | if [[ ! "$1" ]]; then 9 | echo "Usage: $0 " 10 | exit 1 11 | fi 12 | 13 | # check that file is sorted 14 | LC_ALL=C sort --check $1 || { 15 | echo "File $1 is not sorted"; 16 | echo "Run: LC_ALL=C sort -u -o $1 $1" 17 | exit 1 18 | } 19 | 20 | -------------------------------------------------------------------------------- /scripts/ci/check-links: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: Apache-2.0 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | ROOT="$(realpath $(dirname $BASH_SOURCE)/../..)" 7 | 8 | set -e 9 | 10 | ERROR=0 11 | for FILE in `git ls-files \ 12 | "*CMakeLists.txt" \ 13 | "*.cmake" \ 14 | "*Kconfig" \ 15 | "*.robot" \ 16 | "*prj.conf" \ 17 | "*.c" \ 18 | "*.h" \ 19 | "*.cs" \ 20 | "*.cpp" \ 21 | "*.yaml" \ 22 | "*.dts" \ 23 | "*.overlay" \ 24 | "*.rst" 25 | `; do 26 | grep "Copyright " ${FILE} > /dev/null || { 27 | echo "$FILE: no copyright information" 28 | ERROR=1 29 | } 30 | grep "SPDX-License-Identifier: " ${FILE} > /dev/null || { 31 | echo "$FILE: no SPDX license" 32 | ERROR=1 33 | } 34 | grep "Consulting: " ${FILE} > /dev/null || { 35 | echo "$FILE: no consulting offer" 36 | ERROR=1 37 | } 38 | grep "Training: " ${FILE} > /dev/null || { 39 | echo "$FILE: no training offer" 40 | ERROR=1 41 | } 42 | done 43 | 44 | exit $ERROR 45 | -------------------------------------------------------------------------------- /scripts/dockerize: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | ROOT="$(realpath "$(dirname "${BASH_SOURCE[0]}")/..")" 5 | WORKSPACE="$(realpath "$ROOT/..")" 6 | 7 | DOCKER_IMAGE="swedishembedded/build:v0.26.4-1" 8 | 9 | HOST_UID=$(id -u) 10 | HOST_GID=$(id -g) 11 | 12 | PARAMETERS="$@" 13 | 14 | docker run -it --rm \ 15 | -v $WORKSPACE:$WORKSPACE \ 16 | -v $HOME/.ssh/:/home/user/.ssh \ 17 | $DOCKER_IMAGE /bin/bash -c \ 18 | "cd $ROOT; sudo -u user $PARAMETERS" 19 | -------------------------------------------------------------------------------- /scripts/init: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: Apache-2.0 3 | # Copyright (c) 2022 Martin Schröder 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | 7 | ROOT="$(realpath $(dirname $BASH_SOURCE)/..)" 8 | 9 | # abort on error (note that this is only a fallback. You should still check 10 | # return codes every single time!) 11 | set -e 12 | 13 | # Show commands being executed 14 | set -x 15 | 16 | # Remove any existing west config (since we are reinitializing) 17 | if [[ -d ../.west ]]; then 18 | rm -rf ../.west 19 | fi 20 | 21 | # Print out manifest 22 | echo "Using west manifest: " 23 | cat $ROOT/west.yml 24 | 25 | # Initialize the repository 26 | west init -l . 27 | west update 28 | 29 | export ZEPHYR_TOOLCHAIN_VARIANT=zephyr 30 | 31 | # Install python requirements 32 | pip3 install -r ../zephyr/scripts/requirements.txt 33 | pip3 install -r ./scripts/requirements-doc.txt 34 | 35 | pip3 install pre-commit 36 | 37 | # Install cmake tools for cmake-format 38 | pip3 install cmakelang 39 | 40 | # Install robot framework 41 | pip3 install robotframework 42 | 43 | # Install pre commit instead of local hooks 44 | git config --unset-all core.hooksPath || true 45 | pre-commit install 46 | 47 | . ../zephyr/zephyr-env.sh 48 | 49 | west zephyr-export 50 | 51 | -------------------------------------------------------------------------------- /scripts/release: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: Apache-2.0 3 | # Copyright (c) 2022 Martin Schröder 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | 7 | ROOT="$(realpath $(dirname $BASH_SOURCE)/..)" 8 | set -e 9 | 10 | . ${ROOT}/../zephyr/zephyr-env.sh 11 | . ${ROOT}/VERSION 12 | 13 | # Parse arguments (standard way of doing it in bash) 14 | while [[ $# -gt 0 ]]; do 15 | case $1 in 16 | -b|--board) 17 | PLATFORM="$2" 18 | shift 19 | shift 20 | ;; 21 | -s|--source) 22 | SOURCE_DIRECTORY="$2" 23 | shift 24 | shift 25 | ;; 26 | *) 27 | POS_ARGS+=("$1") 28 | shift 29 | ;; 30 | esac 31 | done 32 | 33 | if [[ $SOURCE_DIRECTORY = "" ]]; then 34 | echo "No source directory given"; 35 | exit 1 36 | fi 37 | 38 | if [[ $PLATFORM = "" ]]; then 39 | echo "No platform given"; 40 | exit 1 41 | fi 42 | 43 | # Create build directory 44 | BUILD_DIRECTORY=build-release/${PLATFORM}/$(\ 45 | realpath --relative-to=$ROOT $SOURCE_DIRECTORY) 46 | mkdir -p $BUILD_DIRECTORY 47 | 48 | VERSION=${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} 49 | # Get name of output archive 50 | OUTPUT_ARCHIVE="$(echo \ 51 | $(realpath \ 52 | --relative-to=$ROOT/build-release/${PLATFORM} \ 53 | $BUILD_DIRECTORY) |\ 54 | tr "\/" "." \ 55 | )-$(echo \ 56 | ${PLATFORM} | tr '@' '_'\ 57 | )-${VERSION}" 58 | OUTPUT_ARCHIVE="$ROOT/release/$OUTPUT_ARCHIVE.tar.gz" 59 | 60 | mkdir -p $ROOT/release 61 | 62 | # Build a release 63 | west spdx --init -d $BUILD_DIRECTORY 64 | west build -d $BUILD_DIRECTORY -b $PLATFORM -s $SOURCE_DIRECTORY 65 | west spdx -d $BUILD_DIRECTORY 66 | 67 | # Copy release files 68 | pushd $BUILD_DIRECTORY 69 | mkdir -p release 70 | cp -r spdx release 71 | cp -r zephyr/zephyr.* release 72 | cp zephyr/.config release 73 | # Pack release 74 | tar -czf $OUTPUT_ARCHIVE release/* 75 | popd 76 | 77 | echo "Release archive created: $(realpath --relative-to=$ROOT $OUTPUT_ARCHIVE)" 78 | -------------------------------------------------------------------------------- /scripts/requirements-doc.txt: -------------------------------------------------------------------------------- 1 | breathe>=4.30,<4.33 # 4.33: disabled due to #803 and #805 issues 2 | sphinx~=4.0 3 | sphinx_rtd_theme~=1.0 4 | sphinx-tabs 5 | sphinx-togglebutton 6 | sphinx_markdown_tables 7 | sphinx-notfound-page 8 | sphinx_tabs 9 | sphinxcontrib-svg2pdfconverter 10 | sphinxcontrib-mscgen>=0.6 11 | sphinxcontrib-plantuml 12 | sphinx-ncs-theme>=1.0.3,<1.1 13 | pygments>=2.9 14 | sphinx-notfound-page 15 | sphinx-copybutton 16 | recommonmark==0.6.0 17 | CommonMark>=0.9.1 18 | m2r2>=0.3.2 19 | pygit2<=1.10 20 | pyyaml 21 | myst-parser 22 | -------------------------------------------------------------------------------- /scripts/sort-codeowners: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: Apache-2.0 3 | # Copyright (c) 2022 Martin Schröder 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | 7 | ROOT="$PWD" 8 | 9 | LC_ALL=C sort -u -o \ 10 | ${ROOT}/CODEOWNERS \ 11 | ${ROOT}/CODEOWNERS 12 | -------------------------------------------------------------------------------- /scripts/spdx/find_git_commit_for_file_sha1: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | usage(){ 4 | echo "$0 -f -s " 5 | } 6 | 7 | while [[ $# -gt 0 ]]; do 8 | case $1 in 9 | -s|--sha1) 10 | SHA1SUM=$2 11 | shift 12 | shift 13 | ;; 14 | -f|--path) 15 | FILE="$2" 16 | shift 17 | shift 18 | ;; 19 | *) 20 | POS_ARGS+=("$1") 21 | shift 22 | ;; 23 | esac 24 | done 25 | 26 | if [[ "$FILE" = "" ]] || [[ "$SHA1SUM" = "" ]]; then 27 | usage 28 | exit 1 29 | fi 30 | 31 | git log --format=%H \ 32 | | xargs -Iz sh -c \ 33 | "echo -n \"z \"; git show z:$FILE | sha1sum" 2>/dev/null \ 34 | | grep -m1 $SHA1SUM \ 35 | | cut -d " " -f 1 \ 36 | | xargs -Iz git log z -1 --format=%H 37 | -------------------------------------------------------------------------------- /scripts/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: Apache-2.0 3 | # Copyright (c) 2022 Martin Schröder 4 | # Consulting: https://swedishembedded.com/go 5 | # Training: https://swedishembedded.com/tag/training 6 | 7 | ROOT="$(realpath $(dirname $BASH_SOURCE)/..)" 8 | 9 | set -e 10 | 11 | . ${ROOT}/../zephyr/zephyr-env.sh 12 | 13 | # Build applications and samples 14 | $ROOT/../zephyr/scripts/twister \ 15 | --integration \ 16 | --coverage \ 17 | --coverage-platform native_posix \ 18 | -c \ 19 | -O build-tests \ 20 | -v \ 21 | -i \ 22 | -T tests || { 23 | echo "Error while trying to build project" 24 | exit 1 25 | } 26 | 27 | ./scripts/coverage build-tests 28 | 29 | # Check that all files have coverage 30 | diff \ 31 | <(find lib drivers -name "*.c" | sort) \ 32 | <(lcov \ 33 | --rc lcov_branch_coverage=1 \ 34 | --list-full-path \ 35 | --list build-tests/coverage-project.info | \ 36 | grep $ROOT | \ 37 | awk -F '|' '{print $1;}' | \ 38 | xargs realpath --relative-to=$ROOT | \ 39 | sort 40 | ) || { 41 | echo "Some files in the project do not have coverage data!" 42 | exit 1 43 | } 44 | 45 | -------------------------------------------------------------------------------- /scripts/west-commands.yml: -------------------------------------------------------------------------------- 1 | west-commands: 2 | - file: scripts/west/simulate.py 3 | commands: 4 | - name: simulate 5 | class: Simulate 6 | help: run local renode simulation 7 | -------------------------------------------------------------------------------- /testbench/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | choice TESTBENCH 7 | prompt "Testbench" 8 | default TESTBENCH_NUCLEO401RE_MCP23S17 9 | 10 | config TESTBENCH_NUCLEO401RE_MCP23S17 11 | bool "Nucleo401re browser based testbench" 12 | help 13 | "Browser based testbench for testing the firmware" 14 | 15 | endchoice 16 | -------------------------------------------------------------------------------- /testbench/example_sensor/custom_board.resc: -------------------------------------------------------------------------------- 1 | :name: STM32F4 Discovery 2 | :description: STM32 Discovery Board 3 | 4 | using sysbus 5 | $name?="STM32F4_Discovery" 6 | set ROOT_DIR $ORIGIN/../../../../../ 7 | 8 | i $ROOT_DIR/renode/drivers/example/ExampleSensor.cs 9 | 10 | set bin $ROOT_DIR/build-apps/custom_board/drivers/example/example_sensor/samples.drivers.example.example_sensor.release/zephyr/zephyr.elf 11 | 12 | mach create $name 13 | machine LoadPlatformDescription $ROOT_DIR/renode/boards/arm/custom_board.repl 14 | 15 | cpu PerformanceInMips 125 16 | 17 | logLevel 3 18 | logLevel 0 sysbus.spi1 19 | sysbus LogPeripheralAccess sysbus.spi1 20 | 21 | showAnalyzer sysbus.usart2 22 | 23 | ### Set random board UNIQUE ID ### 24 | 25 | python "import _random" 26 | python "rand = _random.Random()" 27 | 28 | $id1 = `python "print rand.getrandbits(32)"` 29 | $id2 = `python "print rand.getrandbits(32)"` 30 | $id3 = `python "print rand.getrandbits(32)"` 31 | macro reset 32 | """ 33 | sysbus LoadELF $bin 34 | 35 | sysbus WriteDoubleWord 0x1FFF7A10 $id1 36 | sysbus WriteDoubleWord 0x1FFF7A14 $id2 37 | sysbus WriteDoubleWord 0x1FFF7A18 $id3 38 | """ 39 | 40 | runMacro $reset 41 | -------------------------------------------------------------------------------- /testbench/example_sensor/run.robot: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | *** Settings *** 7 | Suite Setup Setup 8 | Suite Teardown Teardown 9 | Test Setup Reset Emulation 10 | Test Teardown Test Teardown 11 | Resource ${RENODEKEYWORDS} 12 | Variables ${CURDIR}/../../scrum/variables.py 13 | 14 | *** Variables *** 15 | ${UART} sysbus.usart2 16 | 17 | *** Test Cases *** 18 | Example sensor driver can read temperature 19 | Execute Command include @${CURDIR}/custom_board.resc 20 | 21 | Create Terminal Tester ${UART} 22 | Start Emulation 23 | Wait For Line On Uart Booting Zephyr OS 24 | Execute Command sysbus.spi1.exampleSensor Temperature 25 25 | Wait For Line On Uart Temperature: 25.0 26 | Execute Command sysbus.spi1.exampleSensor Temperature 41 27 | Wait For Line On Uart Temperature: 41.0 28 | Execute Command sysbus.spi1.exampleSensor Temperature 41.2 29 | Wait For Line On Uart Temperature: 41.2 30 | Execute Command sysbus.spi1.exampleSensor Temperature -10 31 | Wait For Line On Uart Temperature: -10.0 32 | 33 | Temperature limits are reported correctly 34 | Execute Command include @${CURDIR}/custom_board.resc 35 | 36 | Create Terminal Tester ${UART} 37 | Start Emulation 38 | Wait For Line On Uart Booting Zephyr OS 39 | Execute Command sysbus.spi1.exampleSensor Temperature 155 40 | Wait For Line On Uart Temperature: 150.0 41 | Execute Command sysbus.spi1.exampleSensor Temperature -60 42 | Wait For Line On Uart Temperature: -55 43 | -------------------------------------------------------------------------------- /testbench/nucleo401re_mcp23s17/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | set(TESTBENCH "nucleo401re_mcp23s17" "TESTBENCH") 6 | -------------------------------------------------------------------------------- /testbench/nucleo401re_mcp23s17/doc/img/testbench-demo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/testbench/nucleo401re_mcp23s17/doc/img/testbench-demo.jpg -------------------------------------------------------------------------------- /testbench/nucleo401re_mcp23s17/doc/index.rst: -------------------------------------------------------------------------------- 1 | .. SPDX-License-Identifier: Apache-2.0 2 | .. Copyright 2022 Martin Schröder 3 | Consulting: https://swedishembedded.com/go 4 | Training: https://swedishembedded.com/tag/training 5 | 6 | Nucleo401RE MCP23S17 Testbench 7 | ############################## 8 | 9 | This testbench is a simple setup with an STM32F401RE board connected to an SPI 10 | GPIO expander. This test bench uses websocket to interface with the simulation. 11 | 12 | The GPIO expander PORTA is connected to 8 buttons and PORTB is connected to 8 13 | LEDs. 14 | 15 | .. image:: img/testbench-demo.jpg 16 | 17 | The testbench is suitable for running the mcp23s17 driver sample: 18 | 19 | .. code-block:: 20 | 21 | west build -p -b custom_board samples/drivers/gpio/mcp23s17 -t testbench 22 | 23 | You may need to start the visual server (if it doesn't start automaticallY): 24 | 25 | .. code-block:: 26 | 27 | startVisual 8000 28 | 29 | Now you can access the testbench through "localhost:8000" address. 30 | 31 | This testbench demonstrates a simple way to create visualizations for your 32 | product using javascript. This has the advantage of allowing you to use mature 33 | web frameworks like jQuery for controlling your UI elements. 34 | -------------------------------------------------------------------------------- /testbench/nucleo401re_mcp23s17/testbench.repl: -------------------------------------------------------------------------------- 1 | using "platforms/cpus/stm32f4.repl" 2 | 3 | // chip select 4 | gpioPortB: 5 | 6 -> gpioExpander@16 6 | 7 | A0: Miscellaneous.Button @ gpioExpander 8 | -> gpioExpander@0 9 | A1: Miscellaneous.Button @ gpioExpander 10 | -> gpioExpander@1 11 | A2: Miscellaneous.Button @ gpioExpander 12 | -> gpioExpander@2 13 | A3: Miscellaneous.Button @ gpioExpander 14 | -> gpioExpander@3 15 | A4: Miscellaneous.Button @ gpioExpander 16 | -> gpioExpander@4 17 | A5: Miscellaneous.Button @ gpioExpander 18 | -> gpioExpander@5 19 | A6: Miscellaneous.Button @ gpioExpander 20 | -> gpioExpander@6 21 | A7: Miscellaneous.Button @ gpioExpander 22 | -> gpioExpander@7 23 | 24 | gpioExpander: GPIOPort.MCP23S17 @ spi1 25 | INTA -> gpioPortB@8 26 | INTB -> gpioPortB@9 27 | 8 -> SW0LED@0 28 | 9 -> SW1LED@0 29 | 10 -> SW2LED@0 30 | 11 -> SW3LED@0 31 | 12 -> SW4LED@0 32 | 13 -> SW5LED@0 33 | 14 -> SW6LED@0 34 | 15 -> SW7LED@0 35 | 36 | SW0LED: Miscellaneous.LED @ gpioExpander 37 | SW1LED: Miscellaneous.LED @ gpioExpander 38 | SW2LED: Miscellaneous.LED @ gpioExpander 39 | SW3LED: Miscellaneous.LED @ gpioExpander 40 | SW4LED: Miscellaneous.LED @ gpioExpander 41 | SW5LED: Miscellaneous.LED @ gpioExpander 42 | SW6LED: Miscellaneous.LED @ gpioExpander 43 | SW7LED: Miscellaneous.LED @ gpioExpander 44 | -------------------------------------------------------------------------------- /testbench/nucleo401re_mcp23s17/testbench.resc: -------------------------------------------------------------------------------- 1 | :name: MCP23S17 Sample 2 | :description: Custom MCP23S17 Board 3 | 4 | using sysbus 5 | 6 | set PROJECT_BASE $ORIGIN/../../ 7 | 8 | i $ORIGIN/visualizer/plugin.py 9 | i $PROJECT_BASE/renode/drivers/gpio/Mcp23S17.cs 10 | 11 | mach create 12 | machine LoadPlatformDescription $ORIGIN/testbench.repl 13 | 14 | # Setup pty terminal 15 | #emulation CreateUartPtyTerminal "usart2" $APPLICATION_BINARY_DIR/usart2 16 | #connector Connect sysbus.usart2 usart2 17 | 18 | cpu PerformanceInMips 168 19 | 20 | logLevel 3 21 | sysbus LogPeripheralAccess sysbus.spi1.gpioExpander 22 | 23 | showAnalyzer sysbus.usart2 24 | 25 | macro reset 26 | """ 27 | sysbus LoadELF $bin 28 | """ 29 | 30 | runMacro $reset 31 | -------------------------------------------------------------------------------- /testbench/nucleo401re_mcp23s17/testbench.robot: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | *** Settings *** 7 | Resource ${RENODEKEYWORDS} 8 | Suite Setup Setup 9 | Suite Teardown Teardown 10 | Test Setup Reset Emulation 11 | Test Teardown Test Teardown 12 | 13 | *** Variables *** 14 | ${PROJECT_BASE} %{PROJECT_BASE} 15 | ${APPLICATION_BINARY_DIR} %{APPLICATION_BINARY_DIR} 16 | ${APPLICATION_SOURCE_DIR} %{APPLICATION_SOURCE_DIR} 17 | ${BOARD} %{BOARD} 18 | ${UART} sysbus.usart2 19 | 20 | *** Test Cases *** 21 | 22 | Leds can be controlled by buttons 23 | Set Test Variable ${GPIO} GPIO_E0 24 | Boot 25 | FOR ${PIN} IN RANGE 8 15 26 | ${btn}= Evaluate ${PIN} - 8 27 | Write Line To Uart gpio get ${GPIO} ${PIN} 28 | Wait For Line On Uart Value 0 timeout=2 29 | 30 | Execute Command sysbus.spi1.gpioExpander.A${btn} Press 31 | Write Line To Uart gpio get ${GPIO} ${PIN} 32 | Wait For Line On Uart Value 1 timeout=2 33 | 34 | Execute Command sysbus.spi1.gpioExpander.A${btn} Release 35 | Write Line To Uart gpio get ${GPIO} ${PIN} 36 | Wait For Line On Uart Value 0 timeout=2 37 | END 38 | 39 | *** Keywords *** 40 | 41 | Boot 42 | Execute Command set bin @${APPLICATION_BINARY_DIR}/zephyr/zephyr.elf 43 | Execute Command set APPLICATION_BINARY_DIR @${APPLICATION_BINARY_DIR} 44 | Execute Command include @${CURDIR}/testbench.resc 45 | Create Terminal Tester ${UART} 46 | Start Emulation 47 | Wait For Line On Uart MCP23S17 initialized 48 | 49 | -------------------------------------------------------------------------------- /testbench/nucleo401re_mcp23s17/visualizer/application.js: -------------------------------------------------------------------------------- 1 | let ws = new WebSocket("ws://localhost:9001/") 2 | 3 | function initBoard(self) 4 | { 5 | SVGInject(self).then(() => { 6 | [0, 1, 2, 3, 4, 5, 6, 7].forEach((s) => { 7 | $("[id^=SW" + s + "BTN]") 8 | .mousedown(() => { ws.send("BTN|A" + s + "|Press") }); 9 | $("[id^=SW" + s + "BTN]") 10 | .mouseup(() => { ws.send("BTN|A" + s + "|Release") }); 11 | $("[id^=SW" + s + "LED]").attr("style", "fill: red"); 12 | }); 13 | }); 14 | } 15 | document.initBoard = initBoard; 16 | 17 | $(function() { 18 | var term = new Terminal({ fontSize: 10, rows: 20, cols: 80 }); 19 | term.open(document.getElementById('terminal')); 20 | 21 | ws.onopen = 22 | function() { 23 | console.log("onopen") 24 | } 25 | 26 | ws.onmessage = 27 | function(e) { 28 | let split = e.data.split("|") 29 | let type = split[0] let name = split[1] let message = split[2] 30 | 31 | if (type == "LED") 32 | { 33 | console.log(e.data); 34 | if (message == "True") { 35 | $("[id^=" + name + "]").attr("style", "fill: green"); 36 | } else { 37 | $("[id^=" + name + "]").attr("style", "fill: red"); 38 | } 39 | } 40 | else if (type == "UART") 41 | { 42 | term.write(message); 43 | } 44 | } 45 | 46 | ws.onclose = 47 | function() { 48 | console.log("onclose") 49 | } 50 | 51 | ws.onerror = function(e) { 52 | console.log("onerror") 53 | console.log(e) 54 | } 55 | }) 56 | -------------------------------------------------------------------------------- /testbench/nucleo401re_mcp23s17/visualizer/favicon/android-chrome-96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/testbench/nucleo401re_mcp23s17/visualizer/favicon/android-chrome-96x96.png -------------------------------------------------------------------------------- /testbench/nucleo401re_mcp23s17/visualizer/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/testbench/nucleo401re_mcp23s17/visualizer/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /testbench/nucleo401re_mcp23s17/visualizer/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/testbench/nucleo401re_mcp23s17/visualizer/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /testbench/nucleo401re_mcp23s17/visualizer/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/testbench/nucleo401re_mcp23s17/visualizer/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /testbench/nucleo401re_mcp23s17/visualizer/favicon/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Swedish Embedded Platform SDK", 3 | "short_name": "Swedish Embedded Platform SDK", 4 | "icons": [ 5 | { 6 | "src": "/android-chrome-96x96.png", 7 | "sizes": "96x96", 8 | "type": "image/png" 9 | } 10 | ], 11 | "theme_color": "#007ded", 12 | "background_color": "#007ded", 13 | "display": "standalone" 14 | } 15 | -------------------------------------------------------------------------------- /tests/Kconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | menuconfig PLACEHOLDER 7 | bool "Dummy option" 8 | help 9 | This is a dummy option to make tests pass 10 | -------------------------------------------------------------------------------- /tests/drivers/example/example_driver/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cmake_minimum_required(VERSION 3.20.0) 6 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 7 | project(test) 8 | 9 | if(CONFIG_CMOCK) 10 | unity_generate_test_runner(src/unit.c) 11 | # cmock_generate_mocks(${ZEPHYR_BASE}/include/zephyr/device.h .) 12 | cmock_generate_mocks(${ZEPHYR_BASE}/include/zephyr/kernel.h .) 13 | target_sources(app PRIVATE src/unit.c) 14 | else() 15 | target_sources( 16 | app 17 | PRIVATE 18 | ${CMAKE_CURRENT_LIST_DIR}/../../../../drivers/example/example_driver.c) 19 | unity_generate_test_runner(src/integration.c) 20 | target_sources(app PRIVATE src/integration.c) 21 | endif() 22 | -------------------------------------------------------------------------------- /tests/drivers/example/example_driver/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/tests/drivers/example/example_driver/README.md -------------------------------------------------------------------------------- /tests/drivers/example/example_driver/boards/custom_board.overlay: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | */ 7 | / { 8 | example_driver { 9 | compatible = "example-driver"; 10 | custom-variable = <1>; 11 | status = "okay"; 12 | }; 13 | }; 14 | -------------------------------------------------------------------------------- /tests/drivers/example/example_driver/boards/native_posix.overlay: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | */ 7 | 8 | / { 9 | example_driver { 10 | compatible = "example-driver"; 11 | custom-variable = <1>; 12 | status = "okay"; 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /tests/drivers/example/example_driver/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | CONFIG_UNITY=y 7 | CONFIG_ASSERT=n 8 | CONFIG_TEST_LOGGING_DEFAULTS=n 9 | -------------------------------------------------------------------------------- /tests/drivers/example/example_driver/src/integration.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | 11 | void test_something_cool(void) 12 | { 13 | TEST_ASSERT_EQUAL(0, 0); 14 | } 15 | -------------------------------------------------------------------------------- /tests/drivers/example/example_driver/src/unit.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include "mock_kernel.h" 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../../../../../drivers/example/example_driver.c" 16 | 17 | void test_example_driver_init_should_return_einval_on_invalid_args(void) 18 | { 19 | TEST_ASSERT_EQUAL(-EINVAL, example_driver_init(NULL)); 20 | } 21 | 22 | void test_example_driver_init_should_initialize_driver(void) 23 | { 24 | struct example_driver ex; 25 | struct example_driver_config conf; 26 | struct device dev = { .data = &ex, .config = &conf }; 27 | 28 | TEST_ASSERT_EQUAL(0, example_driver_init(&dev)); 29 | } 30 | -------------------------------------------------------------------------------- /tests/drivers/example/example_driver/testcase.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | tests: 7 | drivers.example.example_driver.unit: 8 | tags: drivers/example/example_driver.c 9 | extra_configs: 10 | - CONFIG_CMOCK=y 11 | integration_platforms: 12 | - native_posix 13 | drivers.example.example_driver.integration: 14 | tags: drivers/example/example_driver.c 15 | integration_platforms: 16 | - native_posix 17 | -------------------------------------------------------------------------------- /tests/drivers/example/example_sensor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cmake_minimum_required(VERSION 3.20.0) 6 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 7 | project(test) 8 | 9 | if(CONFIG_CMOCK) 10 | unity_generate_test_runner(src/unit.c) 11 | cmock_generate_mocks(${ZEPHYR_BASE}/include/zephyr/kernel.h .) 12 | cmock_generate_mocks(${ZEPHYR_BASE}/include/zephyr/drivers/gpio.h .) 13 | cmock_generate_mocks(${ZEPHYR_BASE}/include/zephyr/drivers/spi.h .) 14 | target_sources(app PRIVATE src/unit.c) 15 | else() 16 | target_sources( 17 | app 18 | PRIVATE 19 | ${CMAKE_CURRENT_LIST_DIR}/../../../../drivers/example/example_sensor.c) 20 | unity_generate_test_runner(src/integration.c) 21 | target_sources(app PRIVATE src/integration.c) 22 | endif() 23 | -------------------------------------------------------------------------------- /tests/drivers/example/example_sensor/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/tests/drivers/example/example_sensor/README.md -------------------------------------------------------------------------------- /tests/drivers/example/example_sensor/boards/custom_board.overlay: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | &spi1 { 9 | pinctrl-0 = <&spi1_sck_pa5 &spi1_miso_pa6 &spi1_mosi_pa7>; 10 | pinctrl-names = "default"; 11 | cs-gpios = < 12 | &gpiob 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP) 13 | >; 14 | status = "okay"; 15 | 16 | example_sensor: example_sensor@0{ 17 | reg = <0>; 18 | compatible = "example-sensor"; 19 | gpios = <&gpioa 4 GPIO_ACTIVE_LOW>; 20 | spi-max-frequency = <1000000>; 21 | status = "okay"; 22 | }; 23 | }; 24 | -------------------------------------------------------------------------------- /tests/drivers/example/example_sensor/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | CONFIG_UNITY=y 7 | CONFIG_ASSERT=n 8 | CONFIG_SPI=y 9 | CONFIG_TEST_LOGGING_DEFAULTS=n 10 | -------------------------------------------------------------------------------- /tests/drivers/example/example_sensor/src/integration.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | 11 | void test_something_cool(void) 12 | { 13 | TEST_ASSERT_EQUAL(0, 0); 14 | } 15 | -------------------------------------------------------------------------------- /tests/drivers/example/example_sensor/testcase.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | tests: 7 | drivers.example.example_sensor.unit: 8 | tags: drivers/example/example_sensor.c 9 | extra_configs: 10 | - CONFIG_CMOCK=y 11 | integration_platforms: 12 | - native_posix 13 | drivers.example.example_sensor.integration: 14 | tags: drivers/example/example_sensor.c 15 | build_only: true 16 | integration_platforms: 17 | - custom_board 18 | -------------------------------------------------------------------------------- /tests/drivers/gpio/mcp23s17/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cmake_minimum_required(VERSION 3.20.0) 6 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 7 | project(test) 8 | 9 | if(CONFIG_CMOCK) 10 | unity_generate_test_runner(src/unit.c) 11 | cmock_generate_mocks(${ZEPHYR_BASE}/include/zephyr/kernel.h .) 12 | cmock_generate_mocks(${ZEPHYR_BASE}/include/zephyr/drivers/gpio.h .) 13 | cmock_generate_mocks(${ZEPHYR_BASE}/include/zephyr/drivers/spi.h .) 14 | target_sources(app PRIVATE src/unit.c) 15 | else() 16 | target_sources( 17 | app PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../../../../drivers/gpio/mcp23s17.c) 18 | unity_generate_test_runner(src/integration.c) 19 | target_sources(app PRIVATE src/integration.c) 20 | endif() 21 | -------------------------------------------------------------------------------- /tests/drivers/gpio/mcp23s17/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/tests/drivers/gpio/mcp23s17/README.md -------------------------------------------------------------------------------- /tests/drivers/gpio/mcp23s17/boards/custom_board.overlay: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 */ 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | &spi1 { 9 | pinctrl-0 = <&spi1_sck_pa5 &spi1_miso_pa6 &spi1_mosi_pa7>; 10 | pinctrl-names = "default"; 11 | cs-gpios = < 12 | &gpiob 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP) 13 | >; 14 | status = "okay"; 15 | 16 | mcp23s17: mcp23s17@0 { 17 | compatible = "microchip,mcp23s17v2"; 18 | spi-max-frequency = <1000000>; 19 | reg = <0>; 20 | gpio-controller; 21 | #gpio-cells = <2>; 22 | ngpios = <16>; 23 | inta-gpios = < 24 | &gpiob 8 (GPIO_ACTIVE_LOW | GPIO_PULL_UP) 25 | >; 26 | intb-gpios = < 27 | &gpiob 9 (GPIO_ACTIVE_LOW | GPIO_PULL_UP) 28 | >; 29 | status = "okay"; 30 | }; 31 | }; 32 | -------------------------------------------------------------------------------- /tests/drivers/gpio/mcp23s17/boards/custom_board.repl: -------------------------------------------------------------------------------- 1 | using "platforms/cpus/stm32f4.repl" 2 | 3 | // chip select 4 | gpioPortB: 5 | 6 -> gpioExpander@16 6 | 7 | A0: Miscellaneous.Button @ gpioExpander 8 | -> gpioExpander@0 9 | A1: Miscellaneous.Button @ gpioExpander 10 | -> gpioExpander@1 11 | A2: Miscellaneous.Button @ gpioExpander 12 | -> gpioExpander@2 13 | A3: Miscellaneous.Button @ gpioExpander 14 | -> gpioExpander@3 15 | A4: Miscellaneous.Button @ gpioExpander 16 | -> gpioExpander@4 17 | A5: Miscellaneous.Button @ gpioExpander 18 | -> gpioExpander@5 19 | A6: Miscellaneous.Button @ gpioExpander 20 | -> gpioExpander@6 21 | A7: Miscellaneous.Button @ gpioExpander 22 | -> gpioExpander@7 23 | B0: Miscellaneous.Button @ gpioExpander 24 | -> gpioExpander@8 25 | B1: Miscellaneous.Button @ gpioExpander 26 | -> gpioExpander@9 27 | B2: Miscellaneous.Button @ gpioExpander 28 | -> gpioExpander@10 29 | B3: Miscellaneous.Button @ gpioExpander 30 | -> gpioExpander@11 31 | B4: Miscellaneous.Button @ gpioExpander 32 | -> gpioExpander@12 33 | B5: Miscellaneous.Button @ gpioExpander 34 | -> gpioExpander@13 35 | B6: Miscellaneous.Button @ gpioExpander 36 | -> gpioExpander@14 37 | B7: Miscellaneous.Button @ gpioExpander 38 | -> gpioExpander@15 39 | 40 | gpioExpander: GPIOPort.MCP23S17 @ spi1 41 | INTA -> gpioPortB@8 42 | INTB -> gpioPortB@9 43 | -------------------------------------------------------------------------------- /tests/drivers/gpio/mcp23s17/boards/custom_board.resc: -------------------------------------------------------------------------------- 1 | :name: MCP23S17 Sample 2 | :description: Custom MCP23S17 Board 3 | 4 | using sysbus 5 | 6 | set ROOT_DIR $ORIGIN/../../../../../ 7 | 8 | i $ROOT_DIR/renode/drivers/gpio/Mcp23S17.cs 9 | 10 | $bin?=@$ROOT_DIR/build-apps/custom_board/drivers/gpio/mcp23s17/samples.drivers.gpio.mcp23s17.release/zephyr/zephyr.elf 11 | 12 | mach create 13 | machine LoadPlatformDescription $ORIGIN/custom_board.repl 14 | 15 | # Setup pty terminal 16 | emulation CreateUartPtyTerminal "usart2" $APPLICATION_BINARY_DIR/usart2 17 | connector Connect sysbus.usart2 usart2 18 | 19 | cpu PerformanceInMips 168 20 | 21 | logLevel 3 22 | logLevel 0 sysbus.usart2 23 | logLevel 0 sysbus.spi1 24 | logLevel 0 sysbus.spi1.gpioExpander 25 | sysbus LogPeripheralAccess sysbus.spi1.gpioExpander 26 | 27 | showAnalyzer sysbus.usart2 28 | 29 | macro reset 30 | """ 31 | sysbus LoadELF $bin 32 | """ 33 | 34 | runMacro $reset 35 | -------------------------------------------------------------------------------- /tests/drivers/gpio/mcp23s17/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | CONFIG_UNITY=y 7 | CONFIG_ASSERT=n 8 | CONFIG_SPI=y 9 | CONFIG_SPI_STM32_INTERRUPT=n 10 | CONFIG_TEST_LOGGING_DEFAULTS=n 11 | -------------------------------------------------------------------------------- /tests/drivers/gpio/mcp23s17/src/integration.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | 11 | void test_mcp23s17_is_connected(void) 12 | { 13 | // we can check whether the device works by setting a pin and then getting it 14 | const struct device *gpio = device_get_binding("mcp23s17@0"); 15 | 16 | TEST_ASSERT_NOT_NULL(gpio); 17 | TEST_ASSERT_EQUAL(0, gpio_pin_get(gpio, 1)); 18 | TEST_ASSERT_EQUAL(0, gpio_pin_set(gpio, 1, 1)); 19 | TEST_ASSERT_EQUAL(1, gpio_pin_get(gpio, 1)); 20 | TEST_ASSERT_EQUAL(0, 0); 21 | } 22 | -------------------------------------------------------------------------------- /tests/drivers/gpio/mcp23s17/testcase.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | tests: 7 | drivers.gpio.mcp23s17.unit: 8 | tags: drivers/gpio/mcp23s17.c 9 | extra_configs: 10 | - CONFIG_CMOCK=y 11 | platform_allow: native_posix 12 | integration_platforms: 13 | - native_posix 14 | drivers.gpio.mcp23s17.integration: 15 | tags: drivers/gpio/mcp23s17.c 16 | build_only: true 17 | integration_platforms: 18 | - custom_board 19 | -------------------------------------------------------------------------------- /tests/lib/example/example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 Copyright (c) 2022 Martin Schröder 2 | # Consulting: https://swedishembedded.com/go 3 | # Training: https://swedishembedded.com/tag/training 4 | 5 | cmake_minimum_required(VERSION 3.20.0) 6 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 7 | project(test) 8 | 9 | if(CONFIG_CMOCK) 10 | unity_generate_test_runner(src/unit.c) 11 | cmock_generate_mocks(${ZEPHYR_BASE}/include/zephyr/kernel.h .) 12 | target_sources(app PRIVATE src/unit.c) 13 | else() 14 | target_sources( 15 | app PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../../../../lib/example/example.c) 16 | unity_generate_test_runner(src/integration.c) 17 | target_sources(app PRIVATE src/integration.c) 18 | endif() 19 | -------------------------------------------------------------------------------- /tests/lib/example/example/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swedishembedded/sdk/39f25099fe64f417cc84339b82c8bf3e4f5e7c50/tests/lib/example/example/README.md -------------------------------------------------------------------------------- /tests/lib/example/example/prj.conf: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | CONFIG_POLL=y 7 | CONFIG_UNITY=y 8 | -------------------------------------------------------------------------------- /tests/lib/example/example/src/integration.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include 9 | #include 10 | 11 | void test_something_cool(void) 12 | { 13 | TEST_ASSERT_EQUAL(0, 0); 14 | } 15 | -------------------------------------------------------------------------------- /tests/lib/example/example/src/unit.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | /** 3 | * Copyright 2022 Martin Schröder 4 | * Consulting: https://swedishembedded.com/go 5 | * Training: https://swedishembedded.com/tag/training 6 | **/ 7 | 8 | #include "mock_kernel.h" 9 | 10 | #include 11 | #include 12 | 13 | // this is a unit test so we will include the file directly 14 | // this is the only place where we do this - it is the optimal solution. 15 | #include "../../../../../lib/example/example.c" 16 | 17 | void test_example_object_init_should_return_einval_on_invalid_args(void) 18 | { 19 | TEST_ASSERT_EQUAL(-EINVAL, example_object_init(NULL)); 20 | } 21 | 22 | void test_example(void) 23 | { 24 | struct example_object ex; 25 | 26 | __wrap_k_mutex_init_ExpectAndReturn(&ex.mx, 0); 27 | TEST_ASSERT_EQUAL(0, example_object_init(&ex)); 28 | } 29 | -------------------------------------------------------------------------------- /tests/lib/example/example/testcase.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright (c) 2022 Martin Schröder 3 | # Consulting: https://swedishembedded.com/go 4 | # Training: https://swedishembedded.com/tag/training 5 | 6 | tests: 7 | lib.example.example.unit: 8 | tags: lib/example/example.c 9 | extra_configs: 10 | - CONFIG_CMOCK=y 11 | integration_platforms: 12 | - native_posix 13 | lib.example.example.integration: 14 | tags: lib/example/example.c 15 | integration_platforms: 16 | - native_posix 17 | -------------------------------------------------------------------------------- /west.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | manifest: 4 | self: 5 | path: sdk 6 | west-commands: scripts/west-commands.yml 7 | 8 | remotes: 9 | - name: swedishembedded 10 | url-base: https://github.com/swedishembedded 11 | - name: zephyr 12 | url-base: https://github.com/zephyrproject-rtos 13 | - name: renode 14 | url-base: https://github.com/renode 15 | projects: 16 | - name: workstation 17 | remote: swedishembedded 18 | revision: v0.26.4-0 19 | path: workstation 20 | - name: zephyr 21 | remote: zephyr 22 | revision: v3.4.0 23 | import: true 24 | - name: renode 25 | path: tools/renode 26 | revision: v1.13.1 27 | submodules: true 28 | remote: renode 29 | - name: renode-docs 30 | path: tools/renode/docs 31 | revision: master 32 | remote: renode 33 | - name: control 34 | path: modules/lib/control 35 | revision: v0.36.0 36 | remote: swedishembedded 37 | - name: instruments 38 | path: tools/instruments 39 | revision: v0.35.1 40 | remote: swedishembedded 41 | - name: testing 42 | path: modules/test/testing 43 | revision: fc85f31 44 | remote: swedishembedded 45 | import: true 46 | -------------------------------------------------------------------------------- /zephyr/module.yml: -------------------------------------------------------------------------------- 1 | build: 2 | kconfig: Kconfig 3 | cmake: . 4 | settings: 5 | board_root: . 6 | dts_root: . 7 | --------------------------------------------------------------------------------