A template for building applications for ARM Cortex-M microcontrollers
The original template is developed and maintained by the Cortex-M team. I am merely making this easy to be used by Arduino UNO R4 Wifi.
To build embedded programs using this template you'll need:
-
Rust 1.31, 1.30-beta, nightly-2018-09-13 or a newer toolchain. e.g.
rustup default beta
-
The
cargo generate
subcommand. Installation instructions. -
rust-std
components (pre-compiledcore
crate) for the ARM Cortex-M targets. Run:
$ rustup target add thumbv6m-none-eabi thumbv7m-none-eabi thumbv7em-none-eabi thumbv7em-none-eabihf
NOTE: This is the very short version that only covers building programs. For the long version, which additionally covers flashing, running and debugging programs, check the embedded Rust book.
- Before we begin you need to identify some characteristics of the target device as these will be used to configure the project:
-
The ARM core. e.g. Cortex-M3.
-
Does the ARM core include an FPU? Cortex-M4F and Cortex-M7F cores do.
-
How much Flash memory and RAM does the target device has? e.g. 256 KiB of Flash and 32 KiB of RAM.
-
Where are Flash memory and RAM mapped in the address space? e.g. RAM is commonly located at address
0x2000_0000
.
You can find this information in the data sheet or the reference manual of your device.
In this example we'll be using the STM32F3DISCOVERY. This board contains an R7FA4M1AB microcontroller. This microcontroller has:
-
A Cortex-M4F core that includes a single precision FPU
-
256 KiB of Flash located at address 0x00004000.
-
32 KiB of RAM located at address 0x2000_0000.
-
8 KiB of Data Flash located at address 0x0x40100000
- Instantiate the template.
$ cargo generate --git https://github.com/rust-embedded/cortex-m-quickstart
Project Name: app
Creating project called `app`...
Done! New project created /tmp/app
$ cd app
- Set a default compilation target. There are four options as mentioned at the
bottom of
.cargo/config
. For the R7FA4M1AB, which has a Cortex-M4F core, we'll pick thethumbv7em-none-eabihf
target.
$ tail -n9 .cargo/config.toml
[build]
# Pick ONE of these compilation targets
# target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
# target = "thumbv7m-none-eabi" # Cortex-M3
# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU)
target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)
# target = "thumbv8m.base-none-eabi" # Cortex-M23
# target = "thumbv8m.main-none-eabi" # Cortex-M33 (no FPU)
# target = "thumbv8m.main-none-eabihf" # Cortex-M33 (with FPU)
- Enter the memory region information into the
memory.x
file.
$ cat memory.x
/* Linker script for the R7FA4M1AB */
MEMORY
{
/* NOTE 1 K = 1 KiBi = 1024 bytes */
FLASH(rx) : ORIGIN = 0x00004000, LENGTH = 256k
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 32k
DFLASH(r) : ORIGIN = 0x40100000, LENGTH = 8k
}
- Build the template application or one of the examples.
$ cargo build
- Uploading the template to your board
$ cargo embed
This template includes launch configurations for debugging CortexM programs with Visual Studio Code located in the .vscode/
directory.
See .vscode/README.md for more information.
If you're not using VS Code, you can safely delete the directory from the generated project.
This template is licensed under either of
-
Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
-
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Contribution to this crate is organized under the terms of the Rust Code of Conduct, the maintainer of this crate, the Cortex-M team, promises to intervene to uphold that code of conduct.