├── .cargo └── config.toml ├── .genignore ├── .github ├── FUNDING.yml └── workflows │ └── build.yaml ├── .gitignore ├── .vscode └── settings.json ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── ci.sh ├── rust-toolchain.toml └── src ├── bin └── minimal.rs └── lib.rs /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] 2 | # TODO(2) replace `$CHIP` with your chip's name (see `probe-rs chip list` output) 3 | runner = "probe-rs run --chip $CHIP" 4 | rustflags = [ 5 | "-C", "linker=flip-link", 6 | "-C", "link-arg=-Tlink.x", 7 | "-C", "link-arg=-Tdefmt.x", 8 | # This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x 9 | # See https://github.com/rust-embedded/cortex-m-quickstart/pull/95 10 | "-C", "link-arg=--nmagic", 11 | ] 12 | 13 | [build] 14 | # TODO(3) Adjust the compilation target. 15 | # (`thumbv6m-*` is compatible with all ARM Cortex-M chips but using the right 16 | # target improves performance) 17 | # target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ 18 | # target = "thumbv7m-none-eabi" # Cortex-M3 19 | # target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU) 20 | # target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) 21 | 22 | [alias] 23 | rb = "run --bin" 24 | rrb = "run --release --bin" 25 | bbr = "build --release --bin" 26 | -------------------------------------------------------------------------------- /.genignore: -------------------------------------------------------------------------------- 1 | .github/FUNDING.yml 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [knurling-rs] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: 3 | merge_group: 4 | pull_request: 5 | push: 6 | branches: 7 | - main 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build: 14 | name: Build the project according to the steps 15 | runs-on: ubuntu-22.04 16 | steps: 17 | - name: Checkout 18 | uses: actions/checkout@v3 19 | 20 | - name: Install rust nightly 21 | run: | 22 | rustup override set nightly 23 | 24 | - name: Configure rust target 25 | run: | 26 | rustup target add thumbv7em-none-eabihf 27 | 28 | - name: Cache Dependencies 29 | uses: Swatinem/rust-cache@v2 30 | 31 | - name: Run steps 32 | run: | 33 | ./ci.sh 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | Cargo.lock -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | // override the default setting (`cargo check --all-targets`) which produces the following error 3 | // "can't find crate for `test`" when the default compilation target is a no_std target 4 | // with these changes RA will call `cargo check --bins` on save 5 | "rust-analyzer.checkOnSave.allTargets": false, 6 | "rust-analyzer.checkOnSave.extraArgs": [ 7 | "--bins" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | # TODO fix `authors` and `name` if you didn't use `cargo-generate` 3 | name = "test-app" 4 | edition = "2021" 5 | version = "0.1.0" 6 | 7 | [dependencies] 8 | cortex-m = { version = "0.7", features = ["critical-section-single-core"] } 9 | defmt = { version = "0.3", features = ["encoding-rzcobs"] } 10 | defmt-brtt = { version = "0.1", default-features = false, features = ["rtt"] } 11 | panic-probe = { version = "0.3", features = ["print-defmt"] } 12 | # TODO(4) Select the correct rtic backend 13 | rtic = { version = "2.0.0", features = [ "$RTIC_BACKEND" ] } 14 | # TODO(5) Add hal as dependency 15 | some-hal = "1.2.3" 16 | # TODO add a monotonic if you use scheduling 17 | # rtic-monotonics = { version = "1.0.0", features = [ "cortex-m-systick" ]} 18 | 19 | # cargo build/run 20 | [profile.dev] 21 | codegen-units = 1 22 | debug = 2 23 | debug-assertions = true # <- 24 | incremental = false 25 | opt-level = "s" # <- 26 | overflow-checks = true # <- 27 | 28 | # cargo test 29 | [profile.test] 30 | codegen-units = 1 31 | debug = 2 32 | debug-assertions = true # <- 33 | incremental = false 34 | opt-level = "s" # <- 35 | overflow-checks = true # <- 36 | 37 | # cargo build/run --release 38 | [profile.release] 39 | codegen-units = 1 40 | debug = 2 41 | debug-assertions = false # <- 42 | incremental = false 43 | lto = 'fat' 44 | opt-level = "s" # <- 45 | overflow-checks = false # <- 46 | 47 | # cargo test --release 48 | [profile.bench] 49 | codegen-units = 1 50 | debug = 2 51 | debug-assertions = false # <- 52 | incremental = false 53 | lto = 'fat' 54 | opt-level = "s" # <- 55 | overflow-checks = false # <- 56 | 57 | # uncomment this to switch from the crates.io version of defmt to its git version 58 | # check app-template's README for instructions 59 | # [patch.crates-io] 60 | # defmt = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" } 61 | # defmt-rtt = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" } 62 | # defmt-test = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" } 63 | # panic-probe = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" } 64 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any 2 | person obtaining a copy of this software and associated 3 | documentation files (the "Software"), to deal in the 4 | Software without restriction, including without 5 | limitation the rights to use, copy, modify, merge, 6 | publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software 8 | is furnished to do so, subject to the following 9 | conditions: 10 | 11 | The above copyright notice and this permission notice 12 | shall be included in all copies or substantial portions 13 | of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 16 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 17 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 18 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 19 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `app-template` 2 | 3 | > Quickly set up a [`probe-rs`] + [`defmt`] + [`flip-link`] embedded project 4 | > running on the [`RTIC`] scheduler 5 | 6 | [`probe-rs`]: https://crates.io/crates/probe-rs 7 | [`defmt`]: https://github.com/knurling-rs/defmt 8 | [`flip-link`]: https://github.com/knurling-rs/flip-link 9 | [`RTIC`]: https://rtic.rs/ 10 | 11 | Based on https://github.com/knurling-rs/app-template 12 | 13 | ## Dependencies 14 | 15 | #### 1. `flip-link`: 16 | 17 | ```console 18 | $ cargo install flip-link 19 | ``` 20 | 21 | #### 2. `probe-rs`: 22 | 23 | ``` console 24 | $ cargo install probe-rs --features cli 25 | ``` 26 | 27 | ## Setup 28 | 29 | #### 1. Clone the project template 30 | 31 | ``` console 32 | $ git clone https://github.com/rtic-rs/app-template test-app 33 | ``` 34 | 35 | If you look into your new `test-app` folder, you'll find that there are a few `TODO`s in the files marking the properties you need to set. The todo's are formatted as `TODO(n)`, where `n` is the number of the step in which the TODO is explained. 36 | 37 | Let's walk through them together now. 38 | 39 | #### 2. Set `probe-rs` chip 40 | 41 | Pick a chip from `probe-rs chip list` and enter it into `.cargo/config.toml`. 42 | 43 | If, for example, you have a nRF52840 Development Kit from one of [our workshops], replace `$CHIP` with `nRF52840_xxAA`. 44 | 45 | [our workshops]: https://github.com/ferrous-systems/embedded-trainings-2020 46 | 47 | ```diff 48 | # .cargo/config.toml 49 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] 50 | -runner = "probe-rs run --chip $CHIP" 51 | +runner = "probe-rs run --chip nRF52840_xxAA" 52 | ``` 53 | 54 | #### 3. Adjust the compilation target 55 | 56 | In `.cargo/config.toml`, pick the right compilation target for your board. 57 | 58 | ``` diff 59 | # .cargo/config.toml 60 | [build] 61 | -# target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ 62 | -# target = "thumbv7m-none-eabi" # Cortex-M3 63 | -# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU) 64 | -# target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) 65 | +target = "thumbv7em-none-eabihf" # Cortex-M4F (with FPU) 66 | ``` 67 | 68 | Add the target with `rustup`. 69 | 70 | ``` console 71 | $ rustup +nightly target add thumbv7em-none-eabihf 72 | ``` 73 | 74 | #### 4. Activate the correct `rtic` backend 75 | 76 | In `Cargo.toml`, activate the correct `rtic` backend for your target by replacing `$RTIC_BACKEND` with one of `thumbv6-backend`, `thumbv7-backend`, `thumbv8base-backend`, or `thumbv8main-backend`, depending on the target you are compiling for. 77 | 78 | ```diff 79 | # Cargo.toml 80 | -rtic = { version = "2.0.0", features = [ "$RTIC_BACKEND" ] } 81 | +rtic = { version = "2.0.0", features = [ "thumbv7-backend" ] } 82 | ``` 83 | 84 | #### 5. Add a HAL as a dependency 85 | 86 | In `Cargo.toml`, list the Hardware Abstraction Layer (HAL) for your board as a dependency. 87 | 88 | For the nRF52840 you'll want to use the [`nrf52840-hal`]. 89 | 90 | [`nrf52840-hal`]: https://crates.io/crates/nrf52840-hal 91 | 92 | ```diff 93 | # Cargo.toml 94 | [dependencies] 95 | -some-hal = "1.2.3" 96 | +nrf52840-hal = "0.16.0" 97 | ``` 98 | 99 | ⚠️ Note for RP2040 users ⚠️ 100 | 101 | You will need to not just specify the `rp-hal` HAL, but a BSP (board support crate) which includes a second stage bootloader. Please find a list of available BSPs [here](https://github.com/rp-rs/rp-hal-boards#packages). 102 | 103 | #### 6. Import your HAL 104 | 105 | Now that you have selected a HAL, fix the HAL import in `src/lib.rs` 106 | 107 | ``` diff 108 | # my-app/src/lib.rs 109 | -use some_hal as _; // memory layout 110 | +use nrf52840_hal as _; // memory layout 111 | ``` 112 | 113 | #### 7. Configure the `rtic::app` macro. 114 | 115 | In `src/bin/minimal.rs`, edit the `rtic::app` macro into a valid form. 116 | 117 | ``` diff 118 | # my-app/src/bin/minimal.rs 119 | \#[rtic::app( 120 | - // TODO: Replace `some_hal::pac` with the path to the PAC 121 | - device = some_hal::pac, 122 | - // TODO: Replace the `FreeInterrupt1, ...` with free interrupt vectors if software tasks are used 123 | - // You can usually find the names of the interrupt vectors in the some_hal::pac::interrupt enum. 124 | - dispatchers = [FreeInterrupt1, ...] 125 | + device = nrf52840_hal::pac, 126 | + dispatchers = [SWI0_EGU0] 127 | )] 128 | ``` 129 | 130 | #### (8. Get a linker script) 131 | 132 | Some HAL crates require that you manually copy over a file called `memory.x` from the HAL to the root of your project. For nrf52840-hal, this is done automatically so no action is needed. For other HAL crates, you can get it from your local Cargo folder, the default location is under: 133 | 134 | ``` 135 | ~/.cargo/registry/src/ 136 | ``` 137 | 138 | Not all HALs provide a `memory.x` file, you may need to write it yourself. Check the documentation for the HAL you are using. 139 | 140 | 141 | #### 9. Run! 142 | 143 | You are now all set to `cargo-run` your first `defmt`-powered application! 144 | There are some examples in the `src/bin` directory. 145 | 146 | Start by `cargo run`-ning `my-app/src/bin/minimal.rs`: 147 | 148 | ``` console 149 | $ # `rb` is an alias for `run --bin` 150 | $ DEFMT_LOG=trace cargo rb minimal 151 | Finished dev [optimized + debuginfo] target(s) in 0.03s 152 | flashing program .. 153 | DONE 154 | resetting device 155 | 0.000000 INFO Hello, world! 156 | (..) 157 | 158 | $ echo $? 159 | 0 160 | ``` 161 | 162 | If you're running out of memory (`flip-link` bails with an overflow error), you can decrease the size of the device memory buffer by setting the `DEFMT_BRTT_BUFFER_SIZE` environment variable. The default value is 1024 bytes, and powers of two should be used for optimal performance: 163 | 164 | ``` console 165 | $ DEFMT_BRTT_BUFFER_SIZE=64 cargo rb minimal 166 | ``` 167 | 168 | [RA docs]: https://rust-analyzer.github.io/manual.html#configuration 169 | [rust-analyzer]: https://rust-analyzer.github.io/ 170 | 171 | ## Support 172 | 173 | `app-template` is part of the [Knurling] project, [Ferrous Systems]' effort at 174 | improving tooling used to develop for embedded systems. 175 | 176 | If you think that our work is useful, consider sponsoring it via [GitHub 177 | Sponsors]. 178 | 179 | ## License 180 | 181 | Licensed under either of 182 | 183 | - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or 184 | http://www.apache.org/licenses/LICENSE-2.0) 185 | 186 | - MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) 187 | 188 | at your option. 189 | 190 | ### Contribution 191 | 192 | Unless you explicitly state otherwise, any contribution intentionally submitted 193 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 194 | licensed as above, without any additional terms or conditions. 195 | 196 | [Knurling]: https://knurling.ferrous-systems.com 197 | [Ferrous Systems]: https://ferrous-systems.com/ 198 | [GitHub Sponsors]: https://github.com/sponsors/knurling-rs 199 | -------------------------------------------------------------------------------- /ci.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | project="test-app" 6 | 7 | cleanup() { 8 | echo "Cleaning up" 9 | mv Cargo.toml.tmp Cargo.toml 10 | mv .cargo/config.toml.tmp .cargo/config.toml 11 | } 12 | 13 | if [ "$1" = "cleanup" ]; then 14 | cleanup 15 | exit 1 16 | fi 17 | 18 | echo "Installing necessary tools" 19 | cargo install flip-link sd 20 | 21 | echo "Cleaning up old project" 22 | rm -rf "$project" 23 | 24 | echo "Creating new project" 25 | # cargo generate -p . --name "$project" 26 | mkdir -p "$project" 27 | cp -r Cargo.toml LICENSE-* src/ rust-toolchain.toml .cargo/ "$project" 28 | 29 | echo "Storing current config so that the child project will compile." 30 | mv Cargo.toml Cargo.toml.tmp 31 | mv .cargo/config.toml .cargo/config.toml.tmp 32 | 33 | cd "$project" 34 | 35 | echo "Performing steps" 36 | 37 | sd -s -- '--chip $CHIP' '--chip nRF52840_xxAA' .cargo/config.toml 38 | sd -s '# target = "thumbv7em-none-eabihf"' 'target = "thumbv7em-none-eabihf"' .cargo/config.toml 39 | sd -s '$RTIC_BACKEND' 'thumbv7-backend' Cargo.toml 40 | sd -s 'some-hal = "1.2.3"' 'nrf52840-hal = "0.16.0"' Cargo.toml 41 | sd -s 'use some_hal as _;' 'use nrf52840_hal as _;' src/lib.rs 42 | sd -s 'some_hal::pac' 'nrf52840_hal::pac' src/bin/minimal.rs 43 | sd -s 'FreeInterrupt1, ...' 'SWI0_EGU0' src/bin/minimal.rs 44 | 45 | cargo bbr minimal 46 | 47 | cd .. 48 | cleanup -------------------------------------------------------------------------------- /rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "nightly" 3 | components = [ "rust-src", "rustfmt", "llvm-tools-preview" ] -------------------------------------------------------------------------------- /src/bin/minimal.rs: -------------------------------------------------------------------------------- 1 | #![no_main] 2 | #![no_std] 3 | #![feature(type_alias_impl_trait)] 4 | 5 | use test_app as _; // global logger + panicking-behavior + memory layout 6 | 7 | // TODO(7) Configure the `rtic::app` macro 8 | #[rtic::app( 9 | // TODO: Replace `some_hal::pac` with the path to the PAC 10 | device = some_hal::pac, 11 | // TODO: Replace the `FreeInterrupt1, ...` with free interrupt vectors if software tasks are used 12 | // You can usually find the names of the interrupt vectors in the some_hal::pac::interrupt enum. 13 | dispatchers = [FreeInterrupt1, ...] 14 | )] 15 | mod app { 16 | // Shared resources go here 17 | #[shared] 18 | struct Shared { 19 | // TODO: Add resources 20 | } 21 | 22 | // Local resources go here 23 | #[local] 24 | struct Local { 25 | // TODO: Add resources 26 | } 27 | 28 | #[init] 29 | fn init(cx: init::Context) -> (Shared, Local) { 30 | defmt::info!("init"); 31 | 32 | // TODO setup monotonic if used 33 | // let sysclk = { /* clock setup + returning sysclk as an u32 */ }; 34 | // let token = rtic_monotonics::create_systick_token!(); 35 | // rtic_monotonics::systick::Systick::new(cx.core.SYST, sysclk, token); 36 | 37 | 38 | task1::spawn().ok(); 39 | 40 | ( 41 | Shared { 42 | // Initialization of shared resources go here 43 | }, 44 | Local { 45 | // Initialization of local resources go here 46 | }, 47 | ) 48 | } 49 | 50 | // Optional idle, can be removed if not needed. 51 | #[idle] 52 | fn idle(_: idle::Context) -> ! { 53 | defmt::info!("idle"); 54 | 55 | loop { 56 | continue; 57 | } 58 | } 59 | 60 | // TODO: Add tasks 61 | #[task(priority = 1)] 62 | async fn task1(_cx: task1::Context) { 63 | defmt::info!("Hello from task1!"); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | #![no_main] 2 | #![no_std] 3 | 4 | use core::sync::atomic::{AtomicUsize, Ordering}; 5 | use defmt_brtt as _; // global logger 6 | 7 | use panic_probe as _; 8 | 9 | // TODO(6) Import your HAL 10 | use some_hal as _; // memory layout 11 | 12 | // same panicking *behavior* as `panic-probe` but doesn't print a panic message 13 | // this prevents the panic message being printed *twice* when `defmt::panic` is invoked 14 | #[defmt::panic_handler] 15 | fn panic() -> ! { 16 | cortex_m::asm::udf() 17 | } 18 | 19 | static COUNT: AtomicUsize = AtomicUsize::new(0); 20 | defmt::timestamp!("{=usize}", { 21 | // NOTE(no-CAS) `timestamps` runs with interrupts disabled 22 | let n = COUNT.load(Ordering::Relaxed); 23 | COUNT.store(n + 1, Ordering::Relaxed); 24 | n 25 | }); 26 | 27 | /// Terminates the application and makes `probe-rs` exit with exit-code = 0 28 | pub fn exit() -> ! { 29 | loop { 30 | cortex_m::asm::bkpt(); 31 | } 32 | } 33 | --------------------------------------------------------------------------------