diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..f232db7 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,59 @@ +# Copyright (c) 2024 Ferrous Systems +# SPDX-License-Identifier: MIT OR Apache-2.0 + +name: workflow-build-everything +run-name: Build Everything +on: [push] +jobs: + job-build-demo-app: + runs-on: ubuntu-latest + steps: + - name: Install Arm C compiler + run: | + sudo apt-get update -y && sudo apt-get -y install gcc-arm-none-eabi + - name: Install tools + uses: taiki-e/install-action@v2 + with: + tool: flip-link@0.1.7 + - name: Checkout repo + uses: actions/checkout@v4 + with: + submodules: 'true' + - name: Add rustup target + run: | + rustup target add thumbv7em-none-eabihf + - name: Find slug name + run: | + slug=$(./describe.sh "${GITHUB_REF}") + echo "Building with slug '${slug}'" + echo "BUILD_SLUG=${slug}" >> "${GITHUB_ENV}" + - name: Check Demo App + run: | + cd demo-app + cargo check --target=thumbv7em-none-eabihf + - name: Build Demo App + run: | + cd demo-app + cargo build --target=thumbv7em-none-eabihf --release + - name: Upload demo-app + uses: actions/upload-artifact@master + with: + name: demo-app + path: demo-app/target/thumbv7em-none-eabihf/release/demo-app + job-build-freertos-sys: + runs-on: ubuntu-latest + steps: + - name: Install Arm C compiler + run: | + sudo apt-get update -y && sudo apt-get -y install gcc-arm-none-eabi + - name: Checkout repo + uses: actions/checkout@v4 + with: + submodules: 'true' + - name: Add rustup target + run: | + rustup target add thumbv7em-none-eabihf + - name: Build freertos-sys + run: | + cd freertos-sys + cargo build --target=thumbv7em-none-eabihf diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml new file mode 100644 index 0000000..e521269 --- /dev/null +++ b/.github/workflows/clippy.yml @@ -0,0 +1,45 @@ +# Copyright (c) 2024 Ferrous Systems +# SPDX-License-Identifier: MIT OR Apache-2.0 + +name: workflow-code-analysis +run-name: Run code analysis +on: [push] +jobs: + job-clippy-demo-app: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + submodules: 'true' + - name: Install tools + run: | + sudo apt-get update -y && sudo apt-get -y install gcc-arm-none-eabi + - name: Add rustup target + run: | + rustup target add thumbv7em-none-eabihf + - name: Check Clippy on Demo App + env: + RUSTFLAGS: "-Dwarnings" + run: | + cd demo-app + cargo clippy --all-features + job-clippy-freertos-sys: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + submodules: 'true' + - name: Install tools + run: | + sudo apt-get update -y && sudo apt-get -y install gcc-arm-none-eabi + - name: Add rustup target + run: | + rustup target add thumbv7em-none-eabihf + - name: Check Clippy on freertos-sys + env: + RUSTFLAGS: "-Dwarnings" + run: | + cd freertos-sys + cargo clippy --all-features --target=thumbv7em-none-eabihf diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..275ae4b --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,27 @@ +# Copyright (c) 2024 Ferrous Systems +# SPDX-License-Identifier: MIT OR Apache-2.0 + +name: workflow-code-format +run-name: Check code formatting +on: [push] +jobs: + job-format-demo-app: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Check Formatting + run: | + cd demo-app + cargo fmt -- --check + job-format-freertos-sys: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + submodules: 'true' + - name: Check Formatting + run: | + cd freertos-sys + cargo fmt -- --check diff --git a/.github/workflows/reuse.yml b/.github/workflows/reuse.yml new file mode 100644 index 0000000..73a3af2 --- /dev/null +++ b/.github/workflows/reuse.yml @@ -0,0 +1,18 @@ +# Copyright (c) 2024 Ferrous Systems +# SPDX-License-Identifier: MIT OR Apache-2.0 + +name: workflow-code-licensing +run-name: Check code licensing +on: [push] +jobs: + job-run-reuse-lint: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Install tools + run: | + pipx install reuse + - name: Check Licensing + run: | + reuse lint diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..dd69a31 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "freertos-kernel"] + path = freertos-kernel + url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git diff --git a/.gitmodules.license b/.gitmodules.license new file mode 100644 index 0000000..73a85e6 --- /dev/null +++ b/.gitmodules.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +# SPDX-License-Identifier: CC0-1.0 + diff --git a/LICENSES/Apache-2.0.txt b/LICENSES/Apache-2.0.txt new file mode 100644 index 0000000..1b5ec8b --- /dev/null +++ b/LICENSES/Apache-2.0.txt @@ -0,0 +1,176 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/LICENSES/CC0-1.0.txt b/LICENSES/CC0-1.0.txt new file mode 100644 index 0000000..0e259d4 --- /dev/null +++ b/LICENSES/CC0-1.0.txt @@ -0,0 +1,121 @@ +Creative Commons Legal Code + +CC0 1.0 Universal + + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 0000000..2071b23 --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 5320ca4..d1007d0 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,42 @@ This repository shows how to compile a Rust application which runs on FreeRTOS. +* `freertos-kernel` is a git submodule to the FreeRTOS github repo +* `freertos-sys` is a Rust library which runs bindgen on the FreeRTOS headers, and compiles the FreeRTOS source for Cortex-M4F +* `demo-app` is a Rust application which uses `freertos-sys`, which runs on the nRF52840DK + +```console +$ git submodule update --init +$ cd demo-app +$ DEFMT_LOG=info cargo run --release + Finished release [optimized + debuginfo] target(s) in 0.04s + Running `probe-rs run --chip nRF52840_xxAA target/thumbv7em-none-eabihf/release/demo-app` + Erasing ✔ [00:00:00] [############################################################################################################################] 12.00 KiB/12.00 KiB @ 31.93 KiB/s (eta 0s ) + Programming ✔ [00:00:00] [############################################################################################################################] 12.00 KiB/12.00 KiB @ 39.68 KiB/s (eta 0s ) Finished in 0.699s +0 INFO Hello, this is version unknown! +└─ demo_app::__cortex_m_rt_main @ src/main.rs:27 +0 INFO Entering FreeRTOS kernel... +└─ demo_app::__cortex_m_rt_main @ src/main.rs:83 +0 INFO test_task2(params = 0x0, counter = 0) +└─ demo_app::test_task2 @ src/main.rs:105 +0 INFO test_task1(params = 0x0, counter = 0) +└─ demo_app::test_task1 @ src/main.rs:95 +50 INFO test_task1(params = 0x0, counter = 1) +└─ demo_app::test_task1 @ src/main.rs:95 +100 INFO test_task1(params = 0x0, counter = 2) +└─ demo_app::test_task1 @ src/main.rs:95 +``` + +## Prerequisites + +FreeRTOS is downloaded in source form using a git submodule. Ensure you have fetched the submodule, e.g. with: + +```sh +git submodule update --init +``` + +Because FreeRTOS is written in C, you will require a C compiler for your target. We compile the C code using the [`cc` crate](https://crates.io/crates/cc) which does a good job of finding an appropriate C compiler. You can download Arm's build of [GCC for arm-none-eabi](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads), or your system package manager might provide `gcc-arm-none-eabi` or `arm-none-eabi-gcc` packages. + ## Licence * Copyright (c) 2024 Ferrous Systems diff --git a/demo-app/.cargo/config.toml b/demo-app/.cargo/config.toml new file mode 100644 index 0000000..a58e665 --- /dev/null +++ b/demo-app/.cargo/config.toml @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +# SPDX-License-Identifier: MIT OR Apache-2.0 + +[target.thumbv7em-none-eabihf] +runner = "probe-rs run --chip nRF52840_xxAA" +rustflags = [ + "-C", "link-arg=-Tlink.x", # use the cortex-m-rt linker script + "-C", "linker=flip-link", # adds stack overflow protection + "-C", "link-arg=-Tdefmt.x", # defmt support + "-C", "link-arg=--nmagic", # fix page alignment +] + +[build] +# cross-compile to this target +target = "thumbv7em-none-eabihf" # = ARM Cortex-M4 with hard-float diff --git a/demo-app/.gitignore b/demo-app/.gitignore new file mode 100644 index 0000000..30bd429 --- /dev/null +++ b/demo-app/.gitignore @@ -0,0 +1,5 @@ +// SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +// SPDX-License-Identifier: MIT OR Apache-2.0 + +target +.vscode/.cortex-debug.registers.state.json diff --git a/demo-app/.vscode/launch.json b/demo-app/.vscode/launch.json new file mode 100644 index 0000000..63417b3 --- /dev/null +++ b/demo-app/.vscode/launch.json @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +// SPDX-License-Identifier: MIT OR Apache-2.0 + +{ + // Use `nc localhost 8765 | defmt-print -e ./target/thumbv7em-none-eabihf/release/demo-app` to print the defmt output + "version": "0.2.0", + "configurations": [ + { + "cwd": "${workspaceRoot}", + "executable": "./target/thumbv7em-none-eabihf/release/demo-app", + "name": "Debug Microcontroller (launch)", + "request": "launch", + "preLaunchTask": "rust: cargo build release", + "type": "cortex-debug", + "runToEntryPoint": "main", + "configFiles": ["interface/jlink.cfg"], + "servertype": "openocd", + "openOCDLaunchCommands": [ + "transport select swd", + "source [find target/nrf52.cfg]" + ], + "postLaunchCommands": [ + "monitor rtt setup 0x20000000 262144 \"SEGGER RTT\"", + "monitor rtt start", + "monitor rtt server start 8765 0" + ] + } + ] +} diff --git a/demo-app/.vscode/settings.json b/demo-app/.vscode/settings.json new file mode 100644 index 0000000..7dc8d85 --- /dev/null +++ b/demo-app/.vscode/settings.json @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +// SPDX-License-Identifier: MIT OR Apache-2.0 + +{ + // override the default setting (`cargo check --all-targets`) which produces the following error + // "can't find crate for `test`" when the default compilation target is a no_std target + // with these changes RA will call `cargo check --bins` on save + "rust-analyzer.checkOnSave.allTargets": false, + "rust-analyzer.checkOnSave.extraArgs": [ + "--bins" + ], + "rust-analyzer.check.targets": ["thumbv7em-none-eabihf"], + "rust-analyzer.cargo.target": "thumbv7em-none-eabihf" +} diff --git a/demo-app/.vscode/tasks.json b/demo-app/.vscode/tasks.json new file mode 100644 index 0000000..905cfc2 --- /dev/null +++ b/demo-app/.vscode/tasks.json @@ -0,0 +1,25 @@ +// SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +// SPDX-License-Identifier: MIT OR Apache-2.0 + +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cargo", + "command": "build", + "args": [ + "--target", + "thumbv7em-none-eabihf", + "--release" + ], + "problemMatcher": [ + "$rustc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "label": "rust: cargo build release" + } + ] +} diff --git a/demo-app/Cargo.lock b/demo-app/Cargo.lock new file mode 100644 index 0000000..79e61ae --- /dev/null +++ b/demo-app/Cargo.lock @@ -0,0 +1,970 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "atomic-polyfill" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ff7eb3f316534d83a8a2c3d1674ace8a5a71198eba31e2e2b597833f699b28" +dependencies = [ + "critical-section", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "az" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" + +[[package]] +name = "bare-metal" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" +dependencies = [ + "rustc_version 0.2.3", +] + +[[package]] +name = "bindgen" +version = "0.69.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ffcebc3849946a7170a05992aac39da343a90676ab392c51a4280981d6379c2" +dependencies = [ + "bitflags 2.4.1", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.37", + "which", +] + +[[package]] +name = "bitfield" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "byte-strings" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "002ee5531feb8450e59862fefa550eeac39b726d60b186071672751045ebc29a" +dependencies = [ + "byte-strings-proc_macros", +] + +[[package]] +name = "byte-strings-proc_macros" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f7e0e71f98d6c71bfe42b0a7a47d0f870ad808401fad2d44fa156ed5b0ae03" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.37", +] + +[[package]] +name = "bytemuck" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clang-sys" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "cortex-m" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ec610d8f49840a5b376c69663b6369e71f4b34484b9b2eb29fb918d92516cb9" +dependencies = [ + "bare-metal", + "bitfield", + "critical-section", + "embedded-hal", + "volatile-register", +] + +[[package]] +name = "cortex-m-rt" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee84e813d593101b1723e13ec38b6ab6abbdbaaa4546553f5395ed274079ddb1" +dependencies = [ + "cortex-m-rt-macros", +] + +[[package]] +name = "cortex-m-rt-macros" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f6f3e36f203cfedbc78b357fb28730aa2c6dc1ab060ee5c2405e843988d3c7" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "critical-section" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "defmt" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8a2d011b2fee29fb7d659b83c43fce9a2cb4df453e16d441a51448e448f3f98" +dependencies = [ + "bitflags 1.3.2", + "defmt-macros", +] + +[[package]] +name = "defmt-macros" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54f0216f6c5acb5ae1a47050a6645024e6edafc2ee32d421955eccfef12ef92e" +dependencies = [ + "defmt-parser", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.37", +] + +[[package]] +name = "defmt-parser" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "269924c02afd7f94bc4cecbfa5c379f6ffcf9766b3408fe63d22c728654eccd0" +dependencies = [ + "thiserror", +] + +[[package]] +name = "defmt-rtt" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "609923761264dd99ed9c7d209718cda4631c5fe84668e0f0960124cbb844c49f" +dependencies = [ + "critical-section", + "defmt", +] + +[[package]] +name = "demo-app" +version = "0.0.0" +dependencies = [ + "byte-strings", + "cortex-m", + "cortex-m-rt", + "defmt", + "defmt-rtt", + "freertos-sys", + "heapless", + "nrf52840-hal", + "panic-probe", + "static_cell", +] + +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" + +[[package]] +name = "embedded-dma" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "994f7e5b5cb23521c22304927195f236813053eb9c065dd2226a32ba64695446" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "embedded-hal" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff" +dependencies = [ + "nb 0.1.3", + "void", +] + +[[package]] +name = "embedded-storage" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "156d7a2fdd98ebbf9ae579cbceca3058cff946e13f8e17b90e3511db0508c723" + +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fixed" +version = "1.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02c69ce7e7c0f17aa18fdd9d0de39727adb9c6281f2ad12f57cbe54ae6e76e7d" +dependencies = [ + "az", + "bytemuck", + "half", + "typenum", +] + +[[package]] +name = "freertos-sys" +version = "0.1.0" +dependencies = [ + "bindgen", + "cc", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "half" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc52e53916c08643f1b56ec082790d1e86a32e58dc5268f897f313fbae7b4872" +dependencies = [ + "cfg-if", + "crunchy", +] + +[[package]] +name = "hash32" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +dependencies = [ + "byteorder", +] + +[[package]] +name = "heapless" +version = "0.7.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db04bc24a18b9ea980628ecf00e6c0264f3c1426dac36c00cb49b6fbad8b0743" +dependencies = [ + "atomic-polyfill", + "hash32", + "rustc_version 0.4.0", + "spin", + "stable_deref_trait", +] + +[[package]] +name = "home" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "libc" +version = "0.2.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" + +[[package]] +name = "libloading" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +dependencies = [ + "cfg-if", + "winapi", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" + +[[package]] +name = "lock_api" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nb" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f" +dependencies = [ + "nb 1.1.0", +] + +[[package]] +name = "nb" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "nrf-hal-common" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd244c63d588066d75cffdcae8a03299fd5fb272e36bdde4a9f922f3e4bc6e4b" +dependencies = [ + "cast", + "cfg-if", + "cortex-m", + "embedded-dma", + "embedded-hal", + "embedded-storage", + "fixed", + "nb 1.1.0", + "nrf-usbd", + "nrf52840-pac", + "rand_core", + "void", +] + +[[package]] +name = "nrf-usbd" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66b2907c0b3ec4d264981c1fc5a2321d51c463d5a63d386e573f00e84d5495e6" +dependencies = [ + "cortex-m", + "critical-section", + "usb-device", + "vcell", +] + +[[package]] +name = "nrf52840-hal" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b54757ec98f38331889d1d6c535edb5dd543c762751abfe507f2d644b30f6d4f" +dependencies = [ + "embedded-hal", + "nrf-hal-common", + "nrf52840-pac", +] + +[[package]] +name = "nrf52840-pac" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30713f36f1be02e5bc9abefa30eae4a1f943d810f199d4923d3ad062d1be1b3d" +dependencies = [ + "cortex-m", + "cortex-m-rt", + "vcell", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "panic-probe" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa6fa5645ef5a760cd340eaa92af9c1ce131c8c09e7f8926d8a24b59d26652b9" +dependencies = [ + "cortex-m", + "defmt", +] + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "portable-atomic" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0" + +[[package]] +name = "prettyplease" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" +dependencies = [ + "proc-macro2", + "syn 2.0.37", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver 0.9.0", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.19", +] + +[[package]] +name = "rustix" +version = "0.38.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e" +dependencies = [ + "bitflags 2.4.1", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.48.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad977052201c6de01a8ef2aa3378c4bd23217a056337d1d6da40468d267a4fb0" + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "static_cell" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa6ba4cf83bf80d3eb25f098ea5e790a0a1fcb5e357442259b231e412c2d3ca0" +dependencies = [ + "portable-atomic", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.37", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "usb-device" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f6cc3adc849b5292b4075fc0d5fdcf2f24866e88e336dd27a8943090a520508" + +[[package]] +name = "vcell" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "volatile-register" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ee8f19f9d74293faf70901bc20ad067dc1ad390d2cbf1e3f75f721ffee908b6" +dependencies = [ + "vcell", +] + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" diff --git a/demo-app/Cargo.lock.license b/demo-app/Cargo.lock.license new file mode 100644 index 0000000..73a85e6 --- /dev/null +++ b/demo-app/Cargo.lock.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +# SPDX-License-Identifier: CC0-1.0 + diff --git a/demo-app/Cargo.toml b/demo-app/Cargo.toml new file mode 100644 index 0000000..7b50028 --- /dev/null +++ b/demo-app/Cargo.toml @@ -0,0 +1,42 @@ +# SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +# SPDX-License-Identifier: MIT OR Apache-2.0 + +[package] +authors = ["Jonathan Pallant "] +edition = "2021" +license = "MIT OR Apache-2.0" +name = "demo-app" +version = "0.0.0" +description = "Rust FreeRTOS demo on nRF52840" + +[dependencies] +cortex-m = {version = "0.7", features = ["critical-section-single-core"]} +cortex-m-rt = "0.7" +nrf52840-hal = "0.16" +heapless = "0.7" +panic-probe = { version = "0.3", features = ["print-defmt"] } +defmt = "0.3.5" +defmt-rtt = "0.4" +freertos-sys = { path = "../freertos-sys" } +byte-strings = "0.3.1" +static_cell = "2.0.0" + +# optimize code in both profiles +[profile.dev] +codegen-units = 1 +debug = 2 +debug-assertions = true # ! +incremental = false +lto = "fat" +opt-level = 'z' # ! +overflow-checks = false + +[profile.release] +codegen-units = 1 +debug = 2 +debug-assertions = false +incremental = false +lto = "fat" +opt-level = 3 +overflow-checks = false + diff --git a/demo-app/build.rs b/demo-app/build.rs new file mode 100644 index 0000000..b08c4b1 --- /dev/null +++ b/demo-app/build.rs @@ -0,0 +1,17 @@ +//! Build script for the Rust/FreeRTOS demo + +// SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use std::{env, error::Error, fs, path::PathBuf}; + +fn main() -> Result<(), Box> { + let out_dir = PathBuf::from(env::var("OUT_DIR")?); + + // put memory layout (linker script) in the linker search path + fs::copy("memory.x", out_dir.join("memory.x"))?; + println!("cargo:rustc-link-search={}", out_dir.display()); + println!("cargo:rerun-if-changed=memory.x"); + + Ok(()) +} diff --git a/demo-app/memory.x b/demo-app/memory.x new file mode 100644 index 0000000..669304a --- /dev/null +++ b/demo-app/memory.x @@ -0,0 +1,10 @@ +/* +SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +SPDX-License-Identifier: MIT OR Apache-2.0 +*/ + +MEMORY +{ + FLASH : ORIGIN = 0x00000000, LENGTH = 1024K + RAM : ORIGIN = 0x20000000, LENGTH = 256K +} diff --git a/demo-app/src/main.rs b/demo-app/src/main.rs new file mode 100644 index 0000000..6d711b1 --- /dev/null +++ b/demo-app/src/main.rs @@ -0,0 +1,156 @@ +//! Rust Demo for the nRF52840, running FreeRTOS + +// SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +// SPDX-License-Identifier: MIT OR Apache-2.0 + +#![no_main] +#![no_std] + +use byte_strings::c; +use cortex_m_rt::entry; +use defmt_rtt as _; +use nrf52840_hal::prelude::OutputPin; +use panic_probe as _; + +static BUILD_SLUG: Option<&str> = option_env!("BUILD_SLUG"); + +const DEMO_STACK_SIZE: u16 = 1024; + +defmt::timestamp!("{=u32}", { unsafe { freertos_sys::xTaskGetTickCount() } }); + +#[entry] +fn main() -> ! { + defmt::info!( + "Hello, this is version {}!", + BUILD_SLUG.unwrap_or("unknown") + ); + + let pp = nrf52840_hal::pac::Peripherals::take().unwrap(); + + let clocks = nrf52840_hal::Clocks::new(pp.CLOCK); + let clocks = clocks.enable_ext_hfosc(); + let clocks = + clocks.set_lfclk_src_external(nrf52840_hal::clocks::LfOscConfiguration::NoExternalNoBypass); + let clocks = clocks.start_lfclk(); + let _clocks = clocks.enable_ext_hfosc(); + + let pins = nrf52840_hal::gpio::p0::Parts::new(pp.P0); + let mut led = pins + .p0_13 + .degrade() + .into_push_pull_output(nrf52840_hal::gpio::Level::High); + + let _ = led.set_low(); + + // Create a dynamic (heap allocated) queue. + // + // We can treat this handle as having 'static lifetime. + // + // See FreeRTOSConfig.h for the default heap size. + let queue_handle = unsafe { + freertos_sys::xQueueGenericCreate( + // number of items + 10, + // size of each item + 1, + // basic queue + freertos_sys::_queueQUEUE_TYPE_BASE, + ) + }; + + // Create Task 1 + unsafe { + freertos_sys::xTaskCreate( + // the function to call + Some(test_task1), + // what to call it (must be a C string) + c!("Test1").as_ptr(), + // how many bytes of stack + DEMO_STACK_SIZE, + // an argument to pass + queue_handle as *mut core::ffi::c_void, + // what priority to run it at + freertos_sys::tskIDLE_PRIORITY + 1, + // returned task handle + core::ptr::null_mut(), + ); + } + + // Create Task 2 + unsafe { + freertos_sys::xTaskCreate( + // the function to call + Some(test_task2), + // what to call it (must be a C string) + c!("Test2").as_ptr(), + // how many bytes of stack + DEMO_STACK_SIZE, + // an argument to pass + queue_handle as *mut core::ffi::c_void, + // what priority to run it at + freertos_sys::tskIDLE_PRIORITY + 1, + // returned task handle + core::ptr::null_mut(), + ); + } + + defmt::info!("Entering FreeRTOS kernel..."); + unsafe { + freertos_sys::vTaskStartScheduler(); + } + + panic!("Kernel exited"); +} + +/// A function to run in a thread +/// +/// Counts from 0 to 10, posting the counter into a queue. +unsafe extern "C" fn test_task1(params: *mut core::ffi::c_void) { + defmt::info!("params = {}", params); + let queue = params as *mut freertos_sys::QueueDefinition; + loop { + for counter in 0u8..=10 { + defmt::debug!("counter = {=u8}", counter); + unsafe { + freertos_sys::xQueueGenericSend( + queue, + &counter as *const u8 as *const core::ffi::c_void, + 0, + freertos_sys::_queueSEND_TO_BACK, + ); + } + freertos_sys::vTaskDelay(1000 / freertos_sys::_portTICK_PERIOD_MS); + } + } +} + +/// A second function to run in a thread +/// +/// Waits on a queue and prints the number that comes out. +unsafe extern "C" fn test_task2(params: *mut core::ffi::c_void) { + defmt::info!("params = {}", params); + let queue = params as *mut freertos_sys::QueueDefinition; + loop { + let mut value = 0u8; + // blocking queue read - zero indicates error/timeout + let result = unsafe { + freertos_sys::xQueueReceive( + queue, + &mut value as *mut u8 as *mut core::ffi::c_void, + freertos_sys::_portMAX_DELAY, + ) + }; + if result != 0 { + defmt::info!("Got value in queue: {=u8}", value); + } else { + defmt::error!("Error reading from queue"); + } + } +} + +// same panicking *behavior* as `panic-probe` but doesn't print a panic message +// this prevents the panic message being printed *twice* when `defmt::panic` is invoked +#[defmt::panic_handler] +fn panic() -> ! { + cortex_m::asm::udf() +} diff --git a/describe.sh b/describe.sh new file mode 100755 index 0000000..8222f51 --- /dev/null +++ b/describe.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Copyright (c) 2023 Ferrous Systems +# SPDX-License-Identifier: MIT OR Apache-2.0 + +set -euo pipefail + +GIVEN_REF=$1 + +case "${GIVEN_REF}" in + refs/heads/*) + slug="$(git branch --show)-$(git rev-parse --short HEAD)" + ;; + refs/tags/*) + slug="$(echo "${GIVEN_REF}" | awk '{split($0,a,"/"); print a[3]}')" + ;; + refs/pull/*/merge) + slug="pr-$(echo "${GIVEN_REF}" | awk '{split($0,a,"/"); print a[3]}')-$(git rev-parse --short HEAD)" + ;; +esac + +echo "${slug}" diff --git a/freertos-kernel b/freertos-kernel new file mode 160000 index 0000000..0240cd5 --- /dev/null +++ b/freertos-kernel @@ -0,0 +1 @@ +Subproject commit 0240cd55f20be7100439b606086709b74a105cb1 diff --git a/freertos-sys/.cargo/config.toml b/freertos-sys/.cargo/config.toml new file mode 100644 index 0000000..493114f --- /dev/null +++ b/freertos-sys/.cargo/config.toml @@ -0,0 +1,6 @@ +# SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +# SPDX-License-Identifier: MIT OR Apache-2.0 + +[build] +# cross-compile to this target +target = "thumbv7em-none-eabihf" # = ARM Cortex-M4 with hard-float diff --git a/freertos-sys/.gitignore b/freertos-sys/.gitignore new file mode 100644 index 0000000..1f3ba13 --- /dev/null +++ b/freertos-sys/.gitignore @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +# SPDX-License-Identifier: CC0-1.0 + +target/ +Cargo.lock diff --git a/freertos-sys/Cargo.lock.license b/freertos-sys/Cargo.lock.license new file mode 100644 index 0000000..73a85e6 --- /dev/null +++ b/freertos-sys/Cargo.lock.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +# SPDX-License-Identifier: CC0-1.0 + diff --git a/freertos-sys/Cargo.toml b/freertos-sys/Cargo.toml new file mode 100644 index 0000000..b5106aa --- /dev/null +++ b/freertos-sys/Cargo.toml @@ -0,0 +1,17 @@ +# SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +# SPDX-License-Identifier: MIT OR Apache-2.0 + +[package] +name = "freertos-sys" +version = "0.1.0" +edition = "2021" +authors = ["Jonathan Pallant "] +license = "MIT" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[build-dependencies] +bindgen = "0.69.1" +cc = "1.0.83" diff --git a/freertos-sys/build.rs b/freertos-sys/build.rs new file mode 100644 index 0000000..5e01d78 --- /dev/null +++ b/freertos-sys/build.rs @@ -0,0 +1,88 @@ +//! Build Script for freertos-sys +//! +//! Calls out to bindgen to generate a Rust crate from the FreeRTOS header +//! files. This is currently hard-coded for Cortex-M4F support. + +// SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use std::env; +use std::path::{Path, PathBuf}; + +fn main() { + let freertos_path = PathBuf::from("../freertos-kernel"); + + let maybe_path = std::env::var("FREERTOS_SYS_CONFIG_DIR"); + // If they don't give us one, use our example config + let config_path: PathBuf = maybe_path.as_deref().unwrap_or("example").into(); + + build_headers(&freertos_path, &config_path); + build_library(&freertos_path, &config_path); +} + +/// Convert the FreeRTOS header file into a Rust crate +fn build_headers(freertos_path: &Path, config_path: &Path) { + // The bindgen::Builder is the main entry point + // to bindgen, and lets you build up options for + // the resulting bindings. + let bindings = bindgen::Builder::default() + // The input header we would like to generate + // bindings for. + .header("wrapper.h") + // Point to FreeRTOS headers + .clang_arg(format!("-I{}", freertos_path.join("include").display())) + .clang_arg(format!( + "-I{}", + freertos_path.join("portable/GCC/ARM_CM4F").display() + )) + .clang_arg(format!("-I{}", config_path.display())) + // Add some custom headers + .clang_arg("-I./include") + // Disable standard includes (they belong to the host) + .clang_arg("-nostdinc") + // Set the target + .clang_arg("--target=arm") + .clang_arg("-mthumb") + .clang_arg("-mcpu=cortex-m4") + // Use hardfp + .clang_arg("-mfloat-abi=hard") + // We're no_std + .use_core() + // Format the output + .formatter(bindgen::Formatter::Rustfmt) + // Finish the builder and generate the bindings. + .generate() + // Unwrap the Result and panic on failure. + .expect("Unable to generate bindings"); + + // Write the bindings to the $OUT_DIR/bindings.rs file. + let rust_source = bindings.to_string(); + + let bindings_out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs"); + std::fs::write(bindings_out_path, rust_source).expect("Couldn't write updated bindgen output"); + + println!("cargo:rerun-if-changed=wrapper.h"); +} + +/// Compile the FreeRTOS kernel and link it +fn build_library(freertos_path: &Path, config_path: &Path) { + cc::Build::new() + .include(freertos_path.join("include")) + .include(freertos_path.join("portable/GCC/ARM_CM4F")) + .include(config_path) + .opt_level_str("s") + .file(freertos_path.join("portable/GCC/ARM_CM4F/port.c")) + .file(freertos_path.join("portable/MemMang/heap_4.c")) + .file(freertos_path.join("croutine.c")) + .file(freertos_path.join("queue.c")) + .file(freertos_path.join("timers.c")) + .file(freertos_path.join("event_groups.c")) + .file(freertos_path.join("stream_buffer.c")) + .file(freertos_path.join("list.c")) + .file(freertos_path.join("tasks.c")) + .compile("freertos"); + println!( + "cargo:rerun-if-changed={}", + config_path.join("FreeRTOSConfig.h").display() + ); +} diff --git a/freertos-sys/example/FreeRTOSConfig.h b/freertos-sys/example/FreeRTOSConfig.h new file mode 100644 index 0000000..0975f7e --- /dev/null +++ b/freertos-sys/example/FreeRTOSConfig.h @@ -0,0 +1,81 @@ +/* + * FreeRTOS V202212.00 + * SPDX-FileCopyrightText: Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * https://www.FreeRTOS.org + * https://github.com/FreeRTOS + * + */ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html + *----------------------------------------------------------*/ + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( ( unsigned long ) 64000000 ) +#define configTICK_RATE_HZ ( ( TickType_t ) 100 ) +#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 70 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 65536 ) ) +#define configMAX_TASK_NAME_LEN ( 10 ) +#define configUSE_TRACE_FACILITY 0 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_CO_ROUTINES 0 +#define configCHECK_HANDLER_INSTALLATION 0 + +#define configMAX_PRIORITIES ( 5 ) +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ + +#define INCLUDE_vTaskPrioritySet 0 +#define INCLUDE_uxTaskPriorityGet 0 +#define INCLUDE_vTaskDelete 0 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 0 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 + +#define configKERNEL_INTERRUPT_PRIORITY 255 +/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!! +See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ +#define configMAX_SYSCALL_INTERRUPT_PRIORITY 191 /* equivalent to 0xa0, or priority 5. */ + +// Rename the interrupt routines to what cortex-m-rt expects +#define xPortSysTickHandler SysTick +#define xPortPendSVHandler PendSV +#define vPortSVCHandler SVCall + +#endif /* FREERTOS_CONFIG_H */ \ No newline at end of file diff --git a/freertos-sys/include/stddef.h b/freertos-sys/include/stddef.h new file mode 100644 index 0000000..111644c --- /dev/null +++ b/freertos-sys/include/stddef.h @@ -0,0 +1,2 @@ +// SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +// SPDX-License-Identifier: CC0-1.0 diff --git a/freertos-sys/include/stdint.h b/freertos-sys/include/stdint.h new file mode 100644 index 0000000..09cfc38 --- /dev/null +++ b/freertos-sys/include/stdint.h @@ -0,0 +1,17 @@ +// A basic stdint.h header to make FreeRTOS happy +// +// Should match the C library your C compiler (probably gcc-arm-none-eabi) uses. +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +// SPDX-License-Identifier: CC0-1.0 + +#ifndef _STDINC_H +#define _STDINC_H + +typedef unsigned long uint32_t; +typedef signed long int32_t; +typedef unsigned long size_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; + +#endif \ No newline at end of file diff --git a/freertos-sys/include/stdlib.h b/freertos-sys/include/stdlib.h new file mode 100644 index 0000000..111644c --- /dev/null +++ b/freertos-sys/include/stdlib.h @@ -0,0 +1,2 @@ +// SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +// SPDX-License-Identifier: CC0-1.0 diff --git a/freertos-sys/include/string.h b/freertos-sys/include/string.h new file mode 100644 index 0000000..afc4475 --- /dev/null +++ b/freertos-sys/include/string.h @@ -0,0 +1,3 @@ +// SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +// SPDX-License-Identifier: CC0-1.0 + diff --git a/freertos-sys/src/lib.rs b/freertos-sys/src/lib.rs new file mode 100644 index 0000000..63bf946 --- /dev/null +++ b/freertos-sys/src/lib.rs @@ -0,0 +1,47 @@ +//! Auto-generated bindings for FreeRTOS v11.0.1 +//! +//! ```quote +//! * FreeRTOS Kernel V11.0.1 +//! * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +//! * +//! * SPDX-License-Identifier: MIT +//! * +//! * Permission is hereby granted, free of charge, to any person obtaining a copy of +//! * this software and associated documentation files (the "Software"), to deal in +//! * the Software without restriction, including without limitation the rights to +//! * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +//! * the Software, and to permit persons to whom the Software is furnished to do so, +//! * subject to the following conditions: +//! * +//! * The above copyright notice and this permission notice shall be included in all +//! * copies or substantial portions of the Software. +//! * +//! * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +//! * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +//! * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +//! * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +//! * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +//! * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +//! * +//! * https://www.FreeRTOS.org +//! * https://github.com/FreeRTOS +//! ``` + +// The notice above applies to the build output of this crate, including the +// bindings.rs file. +// +// The notice below applies to this file, without the bindings.rs file. +// +// SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +// SPDX-License-Identifier: CC0-1.0 + +#![no_std] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] +#![allow(non_upper_case_globals)] +#![allow(clippy::missing_safety_doc)] + +include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + +// These constants aren't picked out by bindgen +pub const tskIDLE_PRIORITY: UBaseType_t = 0; diff --git a/freertos-sys/wrapper.h b/freertos-sys/wrapper.h new file mode 100644 index 0000000..692d279 --- /dev/null +++ b/freertos-sys/wrapper.h @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: Copyright (c) 2024 Ferrous Systems +// SPDX-License-Identifier: CC0-1.0 + +#include +#include +#include +#include +#include +#include + +// bindgen can't see these macros for some reason, so promote them to const +// static for the purposes of code generation. +static const uint32_t _portTICK_PERIOD_MS = portTICK_PERIOD_MS; +static const uint8_t _queueQUEUE_TYPE_BASE = queueQUEUE_TYPE_BASE; +static const int32_t _queueSEND_TO_BACK = queueSEND_TO_BACK; +static const TickType_t _portMAX_DELAY = portMAX_DELAY;