Skip to content

Commit dc6135b

Browse files
authored
Minimal blinky (#1)
1 parent 378c716 commit dc6135b

File tree

12 files changed

+762
-0
lines changed

12 files changed

+762
-0
lines changed

minimal_blinky/.cargo/config.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[target.thumbv7m-none-eabi]
2+
# uncomment this to make `cargo run` execute programs on QEMU
3+
# runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"
4+
5+
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
6+
# uncomment ONE of these three option to make `cargo run` start a GDB session
7+
# which option to pick depends on your system
8+
# runner = "arm-none-eabi-gdb -q -x openocd.gdb"
9+
# runner = "gdb-multiarch -q -x openocd.gdb"
10+
# runner = "gdb -q -x openocd.gdb"
11+
12+
rustflags = [
13+
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
14+
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
15+
# "-C", "link-arg=--nmagic",
16+
17+
# LLD (shipped with the Rust toolchain) is used as the default linker
18+
# "-C", "link-arg=-Tgcc_arm.ld",
19+
20+
# Generate a .map file
21+
# "-C", "link-args=-Map=minimal_blinky.map",
22+
23+
# if you run into problems with LLD switch to the GNU linker by commenting out
24+
# this line
25+
"-C", "linker=arm-none-eabi-ld",
26+
27+
# if you need to link to pre-compiled C libraries provided by a C toolchain
28+
# use GCC as the linker by commenting out both lines above and then
29+
# uncommenting the three lines below
30+
"-C", "linker=arm-none-eabi-gcc",
31+
"-C", "link-arg=-Wl,-Tgcc_arm.ld",
32+
"-C", "link-arg=-Wl,-Map,minimal_blinky.map",
33+
"-C", "link-arg=-nostartfiles",
34+
]
35+
36+
[build]
37+
# Pick ONE of these compilation targets
38+
# target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
39+
# target = "thumbv7m-none-eabi" # Cortex-M3
40+
# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU)
41+
target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)
42+
# target = "thumbv8m.base-none-eabi" # Cortex-M23
43+
# target = "thumbv8m.main-none-eabi" # Cortex-M33 (no FPU)
44+
# target = "thumbv8m.main-none-eabihf" # Cortex-M33 (with FPU)

minimal_blinky/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Files
2+
*.map
3+
.vscode/.cortex-debug.*
4+
5+
# Folders
6+
target

minimal_blinky/.vscode/launch.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"configurations": [
3+
{
4+
"cwd": "${workspaceFolder}",
5+
"executable": "target/thumbv7em-none-eabihf/debug/minimal_blinky",
6+
"configFiles": [
7+
"stm32l4discovery.cfg"
8+
],
9+
"postLaunchCommands": [
10+
"load",
11+
"monitor arm semihosting enable",
12+
],
13+
"name": "Rust Debug",
14+
"request": "launch",
15+
"type": "cortex-debug",
16+
"servertype": "openocd"
17+
},
18+
{
19+
"cwd": "${workspaceFolder}",
20+
"executable": "target/thumbv7em-none-eabihf/release/minimal_blinky",
21+
"configFiles": [
22+
"stm32l4discovery.cfg"
23+
],
24+
"postLaunchCommands": [
25+
"load",
26+
"monitor arm semihosting enable",
27+
],
28+
"name": "Rust Release",
29+
"request": "launch",
30+
"type": "cortex-debug",
31+
"servertype": "openocd"
32+
}
33+
]
34+
}

minimal_blinky/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "minimal_blinky"
3+
version = "0.1.0"
4+
authors = ["Niket Naidu <coder137@gmail.com>"]
5+
edition = "2018"
6+
readme = "README.md"
7+
8+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
9+
10+
[dependencies]

minimal_blinky/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
- [Minimal Blinky](#minimal-blinky)
2+
- [Links](#links)
3+
- [Pre-requisites](#pre-requisites)
4+
- [Build](#build)
5+
- [Running the code](#running-the-code)
6+
7+
# Minimal Blinky
8+
9+
This code has been tested on
10+
11+
- B-L475-IOT01A board (STM32L475VGT6 ARM Cortex M4 CPU with FPU)
12+
13+
## Links
14+
15+
- [Cargo binutils](https://github.com/rust-embedded/cargo-binutils)
16+
- [Embedded Rust book](https://doc.rust-lang.org/stable/embedded-book/)
17+
- [Lowlevel Embedded Rust book](https://docs.rust-embedded.org/embedonomicon/)
18+
19+
## Pre-requisites
20+
21+
- arm-none-eabi-gcc (v11.2)
22+
- Rust
23+
24+
## Build
25+
26+
- `rustup default stable`
27+
- `rustup target add <your_target>`
28+
- See **.cargo/config.toml** file to install the correct target
29+
- `cargo install cargo-binutils`
30+
31+
## Running the code
32+
33+
- `cargo build`
34+
- Run the code on the target board using the **.vscode/launch.json** configurations
35+
- These can also be manually run on the target using OpenOCD
36+
- Requires the **cortex-debug** vscode extension

minimal_blinky/build.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//! This build script copies the `memory.x` file from the crate root into
2+
//! a directory where the linker can always find it at build time.
3+
//! For many projects this is optional, as the linker always searches the
4+
//! project root directory -- wherever `Cargo.toml` is. However, if you
5+
//! are using a workspace or have a more complicated build setup, this
6+
//! build script becomes required. Additionally, by requesting that
7+
//! Cargo re-run the build script whenever `memory.x` is changed,
8+
//! updating `memory.x` ensures a rebuild of the application with the
9+
//! new memory settings.
10+
11+
use std::env;
12+
use std::path::PathBuf;
13+
14+
fn reference() {
15+
let out: &PathBuf = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
16+
println!("cargo:warning={:?}", out.display());
17+
}
18+
19+
fn linker_script() {
20+
println!("cargo:rerun-if-changed=gcc_arm.ld");
21+
}
22+
23+
fn main() {
24+
reference();
25+
linker_script();
26+
}

0 commit comments

Comments
 (0)