Skip to content

Minimal blinky #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions minimal_blinky/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[target.thumbv7m-none-eabi]
# uncomment this to make `cargo run` execute programs on QEMU
# runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"

[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# uncomment ONE of these three option to make `cargo run` start a GDB session
# which option to pick depends on your system
# runner = "arm-none-eabi-gdb -q -x openocd.gdb"
# runner = "gdb-multiarch -q -x openocd.gdb"
# runner = "gdb -q -x openocd.gdb"

rustflags = [
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95
# "-C", "link-arg=--nmagic",

# LLD (shipped with the Rust toolchain) is used as the default linker
# "-C", "link-arg=-Tgcc_arm.ld",

# Generate a .map file
# "-C", "link-args=-Map=minimal_blinky.map",

# if you run into problems with LLD switch to the GNU linker by commenting out
# this line
"-C", "linker=arm-none-eabi-ld",

# if you need to link to pre-compiled C libraries provided by a C toolchain
# use GCC as the linker by commenting out both lines above and then
# uncommenting the three lines below
"-C", "linker=arm-none-eabi-gcc",
"-C", "link-arg=-Wl,-Tgcc_arm.ld",
"-C", "link-arg=-Wl,-Map,minimal_blinky.map",
"-C", "link-arg=-nostartfiles",
]

[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)
6 changes: 6 additions & 0 deletions minimal_blinky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Files
*.map
.vscode/.cortex-debug.*

# Folders
target
34 changes: 34 additions & 0 deletions minimal_blinky/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"configurations": [
{
"cwd": "${workspaceFolder}",
"executable": "target/thumbv7em-none-eabihf/debug/minimal_blinky",
"configFiles": [
"stm32l4discovery.cfg"
],
"postLaunchCommands": [
"load",
"monitor arm semihosting enable",
],
"name": "Rust Debug",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd"
},
{
"cwd": "${workspaceFolder}",
"executable": "target/thumbv7em-none-eabihf/release/minimal_blinky",
"configFiles": [
"stm32l4discovery.cfg"
],
"postLaunchCommands": [
"load",
"monitor arm semihosting enable",
],
"name": "Rust Release",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd"
}
]
}
10 changes: 10 additions & 0 deletions minimal_blinky/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "minimal_blinky"
version = "0.1.0"
authors = ["Niket Naidu <coder137@gmail.com>"]
edition = "2018"
readme = "README.md"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
36 changes: 36 additions & 0 deletions minimal_blinky/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- [Minimal Blinky](#minimal-blinky)
- [Links](#links)
- [Pre-requisites](#pre-requisites)
- [Build](#build)
- [Running the code](#running-the-code)

# Minimal Blinky

This code has been tested on

- B-L475-IOT01A board (STM32L475VGT6 ARM Cortex M4 CPU with FPU)

## Links

- [Cargo binutils](https://github.com/rust-embedded/cargo-binutils)
- [Embedded Rust book](https://doc.rust-lang.org/stable/embedded-book/)
- [Lowlevel Embedded Rust book](https://docs.rust-embedded.org/embedonomicon/)

## Pre-requisites

- arm-none-eabi-gcc (v11.2)
- Rust

## Build

- `rustup default stable`
- `rustup target add <your_target>`
- See **.cargo/config.toml** file to install the correct target
- `cargo install cargo-binutils`

## Running the code

- `cargo build`
- Run the code on the target board using the **.vscode/launch.json** configurations
- These can also be manually run on the target using OpenOCD
- Requires the **cortex-debug** vscode extension
26 changes: 26 additions & 0 deletions minimal_blinky/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//! This build script copies the `memory.x` file from the crate root into
//! a directory where the linker can always find it at build time.
//! For many projects this is optional, as the linker always searches the
//! project root directory -- wherever `Cargo.toml` is. However, if you
//! are using a workspace or have a more complicated build setup, this
//! build script becomes required. Additionally, by requesting that
//! Cargo re-run the build script whenever `memory.x` is changed,
//! updating `memory.x` ensures a rebuild of the application with the
//! new memory settings.

use std::env;
use std::path::PathBuf;

fn reference() {
let out: &PathBuf = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
println!("cargo:warning={:?}", out.display());
}

fn linker_script() {
println!("cargo:rerun-if-changed=gcc_arm.ld");
}

fn main() {
reference();
linker_script();
}
Loading