├── .cargo └── config ├── .gitignore ├── .vscode ├── README.md ├── extensions.json ├── launch.json └── tasks.json ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── build.rs ├── memory.x ├── openocd.cfg ├── openocd.gdb └── src └── main.rs /.cargo/config: -------------------------------------------------------------------------------- 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] 2 | # uncomment ONE of these three option to make `cargo run` start a GDB session 3 | # which option to pick depends on your system 4 | # runner = "arm-none-eabi-gdb -q -x openocd.gdb" 5 | # runner = "gdb-multiarch -q -x openocd.gdb" 6 | # runner = "gdb -q -x openocd.gdb" 7 | 8 | rustflags = [ 9 | # LLD (shipped with the Rust toolchain) is used as the default linker 10 | "-C", "link-arg=-Tlink.x", 11 | 12 | # if you run into problems with LLD switch to the GNU linker by commenting out 13 | # this line 14 | # "-C", "linker=arm-none-eabi-ld", 15 | 16 | # if you need to link to pre-compiled C libraries provided by a C toolchain 17 | # use GCC as the linker by commenting out both lines above and then 18 | # uncommenting the three lines below 19 | # "-C", "linker=arm-none-eabi-gcc", 20 | # "-C", "link-arg=-Wl,-Tlink.x", 21 | # "-C", "link-arg=-nostartfiles", 22 | ] 23 | 24 | [build] 25 | # comment out the following line if you intend to run unit tests on host machine 26 | target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/*.rs.bk 2 | .#* 3 | .gdb_history 4 | Cargo.lock 5 | target/ 6 | 7 | # editor files 8 | .vscode/* 9 | !.vscode/*.md 10 | !.vscode/*.svd 11 | !.vscode/launch.json 12 | !.vscode/tasks.json 13 | !.vscode/extensions.json -------------------------------------------------------------------------------- /.vscode/README.md: -------------------------------------------------------------------------------- 1 | # VS Code Configuration 2 | 3 | Example configuration for debugging programs in-editor with VS Code. 4 | 5 | ## Required Extensions 6 | 7 | If you have the `code` command in your path, you can run the following commands to install the necessary extensions. 8 | 9 | ```sh 10 | code --install-extension rust-lang.rust 11 | code --install-extension marus25.cortex-debug 12 | ``` 13 | 14 | Otherwise, you can use the Extensions view to search for and install them, or go directly to their marketplace pages and click the "Install" button. 15 | 16 | - [Rust Language Server (RLS)](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust) 17 | - [Cortex-Debug](https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug) 18 | 19 | ## Use 20 | 21 | The `Debug (OpenOCD)`: Starts a debug session for a `STM32F3DISCOVERY` board. 22 | It will use the default `.cargo/config` configuration to build the executable, upload it to the device, and start a debug session. 23 | 24 | `ITM` output, if used, will be written to the Output view `SWO: ITM [port: 0, type: console]` output. 25 | 26 | ### Git 27 | 28 | Files in the `.vscode/` directory are `.gitignore`d by default because many files that may end up in the `.vscode/` directory should not be committed and shared. 29 | However, a number of files are explicitly tracked, because they define complex debug configurations and should be shared with anyone cloning your project. 30 | 31 | ### SVD File 32 | 33 | The SVD file is a standard way of describing all registers and peripherals of an ARM Cortex-M mCU. 34 | Cortex-Debug needs this file to display the current register values for the peripherals on the device. 35 | 36 | For licensing reasons, we're unable to include the SVD file in the quickstart repository, but it can be downloaded from the [ST's Website][stm32f3]. 37 | 38 | Download the [stm32f3 SVD pack][stm32f3-svd], and copy the `STM32F303.svd` file into `~/.svd/`. 39 | This line of the config tells the Cortex-Debug plug in where to find the file. 40 | 41 | ```json 42 | "svdFile": "${env:HOME}/.svd/STM32F303.svd", 43 | ``` 44 | 45 | Personally, I like keeping them in my home directory so I don't have to keep multiple copies of the SVD on disk, but you could also keep the file under `.vscode/` if you have a private project where there are no licensing concerns around the SVD file. 46 | 47 | ```json 48 | "svdFile": "${workspaceRoot}/.vscode/STM32F303.svd", 49 | ``` 50 | 51 | ### CPU Frequency 52 | 53 | If your device is running at a frequency other than the default 8MHz, you'll need to modify this line of `launch.json` for the `ITM` output to work correctly. 54 | 55 | ```json 56 | "cpuFrequency": 8000000, 57 | ``` 58 | 59 | 60 | 61 | [cortex-debug]: https://github.com/Marus/cortex-debug 62 | [stm32f3]: https://www.st.com/content/st_com/en/products/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus/stm32-mainstream-mcus/stm32f3-series.html#resource 63 | [stm32f3-svd]: https://www.st.com/resource/en/svd/stm32f3_svd.zip 64 | [openocd-config]: http://openocd.org/doc/html/Config-File-Guidelines.html 65 | [openocd-repo]: https://sourceforge.net/p/openocd/code/ci/master/tree/tcl/ 66 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. 3 | // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp 4 | 5 | // List of extensions which should be recommended for users of this workspace. 6 | "recommendations": [ 7 | "rust-lang.rust", 8 | "marus25.cortex-debug", 9 | ], 10 | // List of extensions recommended by VS Code that should not be recommended for users of this workspace. 11 | "unwantedRecommendations": [ 12 | 13 | ] 14 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | /* 3 | * Requires the Rust Language Server (RLS) and Cortex-Debug extensions 4 | * https://marketplace.visualstudio.com/items?itemName=rust-lang.rust 5 | * https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug 6 | */ 7 | "version": "0.2.0", 8 | "configurations": [ 9 | { 10 | /* Configuration for the STM32F303 Discovery board */ 11 | "type": "cortex-debug", 12 | "request": "launch", 13 | "name": "Debug (OpenOCD)", 14 | "servertype": "openocd", 15 | "cwd": "${workspaceRoot}", 16 | "preLaunchTask": "cargo build", 17 | "runToMain": true, 18 | "executable": "./target/thumbv7em-none-eabihf/debug/{{project-name}}", 19 | "device": "STM32F303VCT6", 20 | "configFiles": [ 21 | "interface/stlink-v2-1.cfg", 22 | "target/stm32f3x.cfg" 23 | ], 24 | "svdFile": "${env:HOME}/.svd/STM32F303.svd", 25 | "swoConfig": { 26 | "enabled": true, 27 | "cpuFrequency": 8000000, 28 | "swoFrequency": 2000000, 29 | "source": "probe", 30 | "decoders": [ 31 | { "type": "console", "label": "ITM", "port": 0 } 32 | ] 33 | } 34 | }, 35 | { 36 | /* Launches debug session for currently open example */ 37 | "type": "cortex-debug", 38 | "request": "launch", 39 | "name": "Debug Current Example (OpenOCD)", 40 | "servertype": "openocd", 41 | "cwd": "${workspaceRoot}", 42 | "preLaunchTask": "cargo build --examples", 43 | "runToMain": true, 44 | "executable": "./target/thumbv7em-none-eabihf/debug/examples/${fileBasenameNoExtension}", 45 | "device": "STM32F303VCT6", 46 | "configFiles": [ 47 | "interface/stlink-v2-1.cfg", 48 | "target/stm32f3x.cfg" 49 | ], 50 | "svdFile": "${env:HOME}/.svd/STM32F303.svd", 51 | "swoConfig": { 52 | "enabled": true, 53 | "cpuFrequency": 8000000, 54 | "swoFrequency": 2000000, 55 | "source": "probe", 56 | "decoders": [ 57 | { "type": "console", "label": "ITM", "port": 0 } 58 | ] 59 | } 60 | } 61 | ] 62 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | /* 8 | * This is the default cargo build task, 9 | * but we need to provide a label for it, 10 | * so we can invoke it from the debug launcher. 11 | */ 12 | "label": "cargo build", 13 | "type": "process", 14 | "command": "cargo", 15 | "args": ["build"], 16 | "problemMatcher": [ 17 | "$rustc" 18 | ], 19 | "group": { 20 | "kind": "build", 21 | "isDefault": true 22 | } 23 | }, 24 | { 25 | "label": "cargo build --release", 26 | "type": "process", 27 | "command": "cargo", 28 | "args": ["build", "--release"], 29 | "problemMatcher": [ 30 | "$rustc" 31 | ], 32 | "group": "build" 33 | }, 34 | { 35 | "label": "cargo build --examples", 36 | "type": "process", 37 | "command": "cargo", 38 | "args": ["build","--examples"], 39 | "problemMatcher": [ 40 | "$rustc" 41 | ], 42 | "group": "build" 43 | }, 44 | { 45 | "label": "cargo build --examples --release", 46 | "type": "process", 47 | "command": "cargo", 48 | "args": ["build","--examples", "--release"], 49 | "problemMatcher": [ 50 | "$rustc" 51 | ], 52 | "group": "build" 53 | }, 54 | { 55 | "label": "cargo clean", 56 | "type": "process", 57 | "command": "cargo", 58 | "args": ["clean"], 59 | "problemMatcher": [], 60 | "group": "build" 61 | }, 62 | ] 63 | } 64 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["{{authors}}"] 3 | edition = "2018" 4 | readme = "README.md" 5 | name = "{{project-name}}" 6 | version = "0.1.0" 7 | 8 | [dependencies] 9 | cortex-m = "0.7.2" 10 | cortex-m-rt = "0.6.14" 11 | cortex-m-semihosting = "0.3.7" 12 | stm32f3-discovery = "0.6.1" 13 | panic-halt = "0.2.0" 14 | 15 | # Uncomment for the panic example. 16 | # panic-itm = "0.4.1" 17 | 18 | # Uncomment for the allocator example. 19 | # alloc-cortex-m = "0.3.5" 20 | 21 | # this lets you use `cargo fix`! 22 | [[bin]] 23 | name = "{{project-name}}" 24 | test = false 25 | bench = false 26 | 27 | [profile.release] 28 | codegen-units = 1 # better optimizations 29 | debug = true # symbols are nice and they don't increase the size on Flash 30 | lto = true # better optimizations 31 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2020 Christopher McClellan 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020 Christopher McClellan 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `stm32f3-discovery-quickstart` 2 | 3 | Template to develop bare metal Rust applications for the [STM32F3DISCOVERY][stm32f3discovery] board. 4 | Utilizes the [stm32f3-discovery board support crate](https://crates.io/crates/stm32f3-discovery). 5 | 6 | ## Dependencies 7 | 8 | To build embedded programs using this template you'll need: 9 | 10 | - Rust 1.31 or a newer toolchain. 11 | - The `cargo generate` subcommand. [Installation 12 | instructions][cargo-generate-install]. 13 | - `rust-std` components (pre-compiled `core` crate) for the ARM Cortex-M 14 | target. 15 | 16 | ``` console 17 | $ cargo install cargo-generate 18 | $ rustup target add thumbv7em-none-eabihf 19 | ``` 20 | 21 | ## Using this template 22 | 23 | **NOTE**: This is the very short version that only covers building programs. For 24 | the long version, which additionally covers flashing, running and debugging 25 | programs, check [the embedded Rust book][book] and [the Discover book][discovery-book]. 26 | 27 | ``` console 28 | $ cargo generate --git https://github.com/rubberduck203/stm32f3-discovery-quickstart 29 | Project Name: app 30 | Creating project called `app`... 31 | Done! New project created /tmp/app 32 | 33 | $ cd app 34 | $ cargo build 35 | ``` 36 | 37 | ## Examples 38 | 39 | For examples, see the [examples directory of the stm32f3-discovery repository](https://github.com/rubberduck203/stm32f3-discovery/tree/master/examples). 40 | 41 | ## VS Code 42 | 43 | This template includes launch configurations for debugging CortexM programs with Visual Studio Code located in the `.vscode/` directory. 44 | See [.vscode/README.md](./.vscode/README.md) for more information. 45 | If you're not using VS Code, you can safely delete the directory from the generated project. 46 | 47 | # License 48 | 49 | This template is licensed under either of 50 | 51 | - Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) 52 | - MIT license (http://opensource.org/licenses/MIT) 53 | 54 | at your option. 55 | 56 | ## Contribution 57 | 58 | Unless you explicitly state otherwise, any contribution intentionally submitted 59 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be 60 | dual licensed as above, without any additional terms or conditions. 61 | 62 | ## Attributions 63 | 64 | This project is based on and forked from the [cortex-m-quickstart][cortex-m-quickstart] project. 65 | 66 | 67 | 68 | [stm32f3discovery]: https://www.st.com/en/evaluation-tools/stm32f3discovery.html# 69 | [cortex-m-quickstart]: https://github.com/rust-embedded/cortex-m-quickstart 70 | [book]: https://rust-embedded.github.io/book 71 | [discovery-book]: https://rust-embedded.github.io/discovery/ 72 | [cargo-generate-install]: https://github.com/ashleygwilliams/cargo-generate#installation -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | use std::fs::File; 3 | use std::io::Write; 4 | use std::path::PathBuf; 5 | 6 | fn main() { 7 | // Put the linker script somewhere the linker can find it 8 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); 9 | File::create(out.join("memory.x")) 10 | .unwrap() 11 | .write_all(include_bytes!("memory.x")) 12 | .unwrap(); 13 | println!("cargo:rustc-link-search={}", out.display()); 14 | 15 | // Only re-run the build script when memory.x is changed, 16 | // instead of when any part of the source code changes. 17 | println!("cargo:rerun-if-changed=memory.x"); 18 | } 19 | -------------------------------------------------------------------------------- /memory.x: -------------------------------------------------------------------------------- 1 | /* Linker script for the STM32F303VCT6 */ 2 | MEMORY 3 | { 4 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ 5 | FLASH : ORIGIN = 0x08000000, LENGTH = 256K 6 | RAM : ORIGIN = 0x20000000, LENGTH = 40K 7 | } 8 | 9 | /* This is where the call stack will be allocated. */ 10 | /* The stack is of the full descending type. */ 11 | /* You may want to use this variable to locate the call stack and static 12 | variables in different memory regions. Below is shown the default value */ 13 | /* _stack_start = ORIGIN(RAM) + LENGTH(RAM); */ 14 | 15 | /* You can use this symbol to customize the location of the .text section */ 16 | /* If omitted the .text section will be placed right after the .vector_table 17 | section */ 18 | /* This is required only on microcontrollers that store some configuration right 19 | after the vector table */ 20 | /* _stext = ORIGIN(FLASH) + 0x400; */ 21 | 22 | /* Example of putting non-initialized variables into custom RAM locations. */ 23 | /* This assumes you have defined a region RAM2 above, and in the Rust 24 | sources added the attribute `#[link_section = ".ram2bss"]` to the data 25 | you want to place there. */ 26 | /* Note that the section will not be zero-initialized by the runtime! */ 27 | /* SECTIONS { 28 | .ram2bss (NOLOAD) : ALIGN(4) { 29 | *(.ram2bss); 30 | . = ALIGN(4); 31 | } > RAM2 32 | } INSERT AFTER .bss; 33 | */ 34 | -------------------------------------------------------------------------------- /openocd.cfg: -------------------------------------------------------------------------------- 1 | # Sample OpenOCD configuration for the STM32F3DISCOVERY development board 2 | 3 | # Depending on the hardware revision you got you'll have to pick ONE of these 4 | # interfaces. At any time only one interface should be commented out. 5 | 6 | # Revision C (newer revision) 7 | source [find interface/stlink-v2-1.cfg] 8 | 9 | # Revision A and B (older revisions) 10 | # source [find interface/stlink-v2.cfg] 11 | 12 | source [find target/stm32f3x.cfg] 13 | -------------------------------------------------------------------------------- /openocd.gdb: -------------------------------------------------------------------------------- 1 | target extended-remote :3333 2 | 3 | # print demangled symbols 4 | set print asm-demangle on 5 | 6 | # set backtrace limit to not have infinite backtrace loops 7 | set backtrace limit 32 8 | 9 | # detect unhandled exceptions, hard faults and panics 10 | break DefaultHandler 11 | break HardFault 12 | break rust_begin_unwind 13 | # # run the next few lines so the panic message is printed immediately 14 | # # the number needs to be adjusted for your panic handler 15 | # commands $bpnum 16 | # next 4 17 | # end 18 | 19 | # *try* to stop at the user entry point (it might be gone due to inlining) 20 | break main 21 | 22 | monitor arm semihosting enable 23 | 24 | # # send captured ITM to the file itm.fifo 25 | # # (the microcontroller SWO pin must be connected to the programmer SWO pin) 26 | # # 8000000 must match the core clock frequency 27 | # monitor tpiu config internal itm.txt uart off 8000000 28 | 29 | # # OR: make the microcontroller SWO pin output compatible with UART (8N1) 30 | # # 8000000 must match the core clock frequency 31 | # # 2000000 is the frequency of the SWO pin 32 | # monitor tpiu config external uart off 8000000 2000000 33 | 34 | # # enable ITM port 0 35 | # monitor itm port 0 on 36 | 37 | load 38 | 39 | # start the process but immediately halt the processor 40 | stepi 41 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | #![no_std] 2 | #![no_main] 3 | 4 | // pick a panicking behavior 5 | extern crate panic_halt; // you can put a breakpoint on `rust_begin_unwind` to catch panics 6 | // extern crate panic_abort; // requires nightly 7 | // extern crate panic_itm; // logs messages over ITM; requires ITM support 8 | // extern crate panic_semihosting; // logs messages to the host stderr; requires a debugger 9 | 10 | use cortex_m_rt::entry; 11 | 12 | use stm32f3_discovery::stm32f3xx_hal::prelude::*; 13 | use stm32f3_discovery::stm32f3xx_hal::stm32; 14 | use stm32f3_discovery::stm32f3xx_hal::delay::Delay; 15 | 16 | use stm32f3_discovery::switch_hal::{IntoSwitch, OutputSwitch, ToggleableOutputSwitch}; 17 | 18 | #[entry] 19 | fn main() -> ! { 20 | 21 | let device_periphs = stm32::Peripherals::take().unwrap(); 22 | let mut reset_control_clock = device_periphs.RCC.constrain(); 23 | let mut gpioe = device_periphs.GPIOE.split(&mut reset_control_clock.ahb); 24 | 25 | let mut led = 26 | gpioe 27 | .pe13 28 | .into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper) 29 | .into_active_high_switch(); 30 | 31 | led.off().unwrap(); 32 | 33 | let core_periphs = cortex_m::Peripherals::take().unwrap(); 34 | let mut flash = device_periphs.FLASH.constrain(); 35 | let clocks = reset_control_clock.cfgr.freeze(&mut flash.acr); 36 | let mut delay = Delay::new(core_periphs.SYST, clocks); 37 | 38 | loop { 39 | led.toggle().unwrap(); 40 | delay.delay_ms(1000u16); 41 | } 42 | } 43 | --------------------------------------------------------------------------------