• Stars
    star
    713
  • Rank 60,950 (Top 2 %)
  • Language
    Rust
  • Created about 7 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Template to develop bare metal applications for Cortex-M microcontrollers

cortex-m-quickstart

A template for building applications for ARM Cortex-M microcontrollers

This project is developed and maintained by the Cortex-M team.

Dependencies

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-compiled core crate) for the ARM Cortex-M targets. Run:

$ rustup target add thumbv6m-none-eabi thumbv7m-none-eabi thumbv7em-none-eabi thumbv7em-none-eabihf

Using this template

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.

  1. 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 STM32F303VCT6 microcontroller. This microcontroller has:

  • A Cortex-M4F core that includes a single precision FPU

  • 256 KiB of Flash located at address 0x0800_0000.

  • 40 KiB of RAM located at address 0x2000_0000. (There's another RAM region but for simplicity we'll ignore it).

  1. 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
  1. Set a default compilation target. There are four options as mentioned at the bottom of .cargo/config. For the STM32F303VCT6, which has a Cortex-M4F core, we'll pick the thumbv7em-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)
  1. Enter the memory region information into the memory.x file.
$ cat memory.x
/* Linker script for the STM32F303VCT6 */
MEMORY
{
  /* NOTE 1 K = 1 KiBi = 1024 bytes */
  FLASH : ORIGIN = 0x08000000, LENGTH = 256K
  RAM : ORIGIN = 0x20000000, LENGTH = 40K
}
  1. Build the template application or one of the examples.
$ cargo build

VS Code

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.

License

This template is licensed under either of

at your option.

Contribution

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.

Code of Conduct

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.

More Repositories

1

rust-raspberrypi-OS-tutorials

📚 Learn to write an embedded OS in Rust 🦀
Rust
12,825
star
2

awesome-embedded-rust

Curated list of resources for Embedded and Low-level development in the Rust programming language
5,615
star
3

wg

Coordination repository of the embedded devices Working Group
1,808
star
4

embedded-hal

A Hardware Abstraction Layer (HAL) for embedded systems
Rust
1,775
star
5

discovery

Discover the world of microcontrollers through Rust!
Rust
1,378
star
6

heapless

Heapless, `static` friendly data structures
Rust
1,365
star
7

book

Documentation on how to use the Rust Programming Language to develop firmware for bare metal (microcontroller) devices
1,004
star
8

cortex-m

Low level access to Cortex-M processors
Rust
732
star
9

riscv

Low level access to RISC-V processors
Rust
711
star
10

svd2rust

Generate Rust register maps (`struct`s) from SVD files
Rust
642
star
11

cargo-binutils

Cargo subcommands to invoke the LLVM tools shipped with the Rust toolchain
Rust
457
star
12

rust-sysfs-gpio

A Rust Interface to the Linux sysfs GPIO interface (https://www.kernel.org/doc/Documentation/gpio/sysfs.txt)
Rust
377
star
13

cortex-m-rt

Minimal startup / runtime for Cortex-M microcontrollers
Rust
356
star
14

riscv-rt

Minimal runtime / startup for RISC-V CPU's.
Rust
302
star
15

embedded-alloc

A heap allocator for embedded systems
Rust
258
star
16

linux-embedded-hal

Implementation of the `embedded-hal` traits for Linux devices
Rust
220
star
17

gpio-cdev

Rust interface to the Linux GPIO Character Device API (/dev/gpiochip...)
Rust
202
star
18

embedonomicon

How to bootstrap support for a no_std target
Rust
200
star
19

rust-i2cdev

Rust library for interfacing with i2c devices under Linux
Rust
189
star
20

cortex-a

Low level access to Cortex-A processors
Rust
120
star
21

rust-spidev

Rust library providing access to spidev devices under Linux
Rust
118
star
22

not-yet-awesome-embedded-rust

A collection of items that are not yet awesome in Embedded Rust
116
star
23

bare-metal

Abstractions common to microcontrollers
Rust
109
star
24

gpio-utils

Userspace Utilities for managing GPIOs in Linux
Rust
93
star
25

showcase

Awesome embedded projects by the Rust community!
CSS
92
star
26

meta-rust-bin

Yocto layer for installing Rust toolchain from pre-built binaries
BitBake
90
star
27

nb

Minimal and reusable non-blocking I/O layer
Rust
85
star
28

rust-embedded.github.io

A collection of books and other documents about embedded Rust
84
star
29

blog

The Rust Embedded WG Blog
SCSS
71
star
30

critical-section

Pluggable critical section
Rust
70
star
31

r0

Initialization code ("crt0") written in Rust
Rust
69
star
32

svd

A CMSIS-SVD file parser
Rust
66
star
33

debugonomicon

Shell
57
star
34

svdtools

Python package to handle vendor-supplied, often buggy SVD files.
Rust
56
star
35

aarch64-cpu

Low level access to processors using the AArch64 execution state.
Rust
51
star
36

register-rs

Unified interface for type-safe MMIO and CPU register access in Rust
Rust
48
star
37

rust-sysfs-pwm

Linux PWM Access via Sysfs in Rust
Rust
46
star
38

fixedvec-rs

Heapless vector implementation for Rust
Rust
45
star
39

cortex-m-semihosting

Semihosting for ARM Cortex-M processors
Rust
39
star
40

msp430

Low level access to MSP430 microcontrollers
Rust
37
star
41

qemu-exit

Exit QEMU with user-defined code
Rust
35
star
42

embedded-dma

Rust
34
star
43

volatile-register

Volatile access to memory mapped hardware registers
Rust
33
star
44

msp430-quickstart

Template to develop bare metal applications for MSP430 microcontrollers
Rust
33
star
45

itm

Tool to parse and dump ITM packets
Rust
26
star
46

mutex-trait

Low level API definition of a Mutex
Rust
23
star
47

msp430-rt

Minimal startup / runtime for MSP430 microcontrollers
Rust
15
star
48

patterns

A book capturing different approaches or patterns for solving problems in Embedded Rust
15
star
49

docker-rust-cross

Docker images for testing rust code on many versions and architecures (DEPRECATED)
Shell
13
star
50

panic-semihosting

Report panic messages to the host stderr using semihosting
Rust
12
star
51

cortex-r

Low level access to Cortex-R processors
Shell
11
star
52

arm-dcc

Debug Communication Channel (DCC) API
Rust
8
star
53

rust-embedded-www

The Rust embedded website: http://www.rust-embedded.org
HTML
7
star
54

panic-itm

Log panic messages using the ITM (Instrumentation Trace Macrocell)
Rust
6
star
55

rust-embedded-provisioning

Terraform provisioning for Rust Embedded infrastructure
HCL
2
star
56

template

Rust
1
star