Initial commit
This commit is contained in:
commit
da153abac6
40
.cargo/config
Normal file
40
.cargo/config
Normal file
@ -0,0 +1,40 @@
|
||||
[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=-Tlink.x",
|
||||
|
||||
# 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,-Tlink.x",
|
||||
# "-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)
|
13
.gitignore
vendored
Normal file
13
.gitignore
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
**/*.rs.bk
|
||||
.#*
|
||||
.gdb_history
|
||||
Cargo.lock
|
||||
target/
|
||||
|
||||
# editor files
|
||||
.vscode/*
|
||||
!.vscode/*.md
|
||||
!.vscode/*.svd
|
||||
!.vscode/launch.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/extensions.json
|
14
.vscode/extensions.json
vendored
Normal file
14
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
|
||||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
|
||||
|
||||
// List of extensions which should be recommended for users of this workspace.
|
||||
"recommendations": [
|
||||
"rust-lang.rust",
|
||||
"marus25.cortex-debug",
|
||||
],
|
||||
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
|
||||
"unwantedRecommendations": [
|
||||
|
||||
]
|
||||
}
|
54
.vscode/launch.json
vendored
Normal file
54
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
{
|
||||
/*
|
||||
* Requires the Rust Language Server (RLS) and Cortex-Debug extensions
|
||||
* https://marketplace.visualstudio.com/items?itemName=rust-lang.rust
|
||||
* https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug
|
||||
*/
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "cortex-debug",
|
||||
"request": "launch",
|
||||
"name": "Debug (QEMU)",
|
||||
"servertype": "qemu",
|
||||
"cwd": "${workspaceRoot}",
|
||||
"preLaunchTask": "Cargo Build (debug)",
|
||||
"runToMain": true,
|
||||
"executable": "./target/thumbv7m-none-eabi/debug/app",
|
||||
/* Run `cargo build --example hello` and uncomment this line to run semi-hosting example */
|
||||
//"executable": "./target/thumbv7m-none-eabi/debug/examples/hello",
|
||||
"cpu": "cortex-m3",
|
||||
"machine": "lm3s6965evb",
|
||||
},
|
||||
{
|
||||
"type": "cortex-debug",
|
||||
"request": "launch",
|
||||
"name": "Debug (OpenOCD)",
|
||||
"servertype": "openocd",
|
||||
"cwd": "${workspaceRoot}",
|
||||
"preLaunchTask": "Cargo Build (debug)",
|
||||
"runToMain": true,
|
||||
"executable": "./target/thumbv7em-none-eabihf/debug/app",
|
||||
/* Run `cargo build --example itm` and uncomment this line to run itm example */
|
||||
// "executable": "./target/thumbv7em-none-eabihf/debug/examples/itm",
|
||||
"device": "NRF52832",
|
||||
"configFiles": [
|
||||
"/usr/local/share/openocd/scripts/interface/jlink.cfg",
|
||||
"/usr/local/share/openocd/scripts/board/nordic_nrf52_dk.cfg"
|
||||
],
|
||||
// "svdFile": "${workspaceRoot}/.vscode/STM32F303.svd",
|
||||
"swoConfig": {
|
||||
"enabled": true,
|
||||
"cpuFrequency": 8000000,
|
||||
"swoFrequency": 2000000,
|
||||
"source": "probe",
|
||||
"decoders": [
|
||||
{ "type": "console", "label": "ITM", "port": 0 }
|
||||
]
|
||||
},
|
||||
"preLaunchCommands": [
|
||||
"monitor arm semihosting enable"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
44
.vscode/tasks.json
vendored
Normal file
44
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Cargo Build (debug)",
|
||||
"type": "process",
|
||||
"command": "cargo",
|
||||
"args": ["build"],
|
||||
"problemMatcher": [
|
||||
"$rustc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Cargo Build (release)",
|
||||
"type": "process",
|
||||
"command": "cargo",
|
||||
"args": ["build", "--release"],
|
||||
"problemMatcher": [
|
||||
"$rustc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Cargo Clean",
|
||||
"type": "process",
|
||||
"command": "cargo",
|
||||
"args": ["clean"],
|
||||
"problemMatcher": [
|
||||
"$rustc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
21
Cargo.toml
Normal file
21
Cargo.toml
Normal file
@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "app"
|
||||
version = "0.1.0"
|
||||
authors = ["Andres O. Vela"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
cortex-m = "0.7.2"
|
||||
cortex-m-rt = "0.6.14"
|
||||
cortex-m-semihosting = "0.3.7"
|
||||
|
||||
panic-semihosting = "0.5.6"
|
||||
|
||||
nrf52832-hal = { features = ["rt"], path = "/home/tkl/nrf-hal/nrf52832-hal" }
|
||||
|
||||
|
||||
[dependencies.embedded-hal]
|
||||
version = "0.2.3"
|
||||
features = ["unproven"]
|
31
build.rs
Normal file
31
build.rs
Normal file
@ -0,0 +1,31 @@
|
||||
//! 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::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
// Put `memory.x` in our output directory and ensure it's
|
||||
// on the linker search path.
|
||||
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
File::create(out.join("memory.x"))
|
||||
.unwrap()
|
||||
.write_all(include_bytes!("memory.x"))
|
||||
.unwrap();
|
||||
println!("cargo:rustc-link-search={}", out.display());
|
||||
|
||||
// By default, Cargo will re-run a build script whenever
|
||||
// any file in the project changes. By specifying `memory.x`
|
||||
// here, we ensure the build script is only re-run when
|
||||
// `memory.x` is changed.
|
||||
println!("cargo:rerun-if-changed=memory.x");
|
||||
}
|
35
memory.x
Normal file
35
memory.x
Normal file
@ -0,0 +1,35 @@
|
||||
MEMORY
|
||||
{
|
||||
/* NOTE 1 K = 1 KiBi = 1024 bytes */
|
||||
/* TODO Adjust these memory regions to match your device memory layout */
|
||||
/* These values correspond to the LM3S6965, one of the few devices QEMU can emulate */
|
||||
FLASH : ORIGIN = 0x00000000, LENGTH = 512K
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 64K
|
||||
}
|
||||
|
||||
|
||||
/* This is where the call stack will be allocated. */
|
||||
/* The stack is of the full descending type. */
|
||||
/* You may want to use this variable to locate the call stack and static
|
||||
variables in different memory regions. Below is shown the default value */
|
||||
/* _stack_start = ORIGIN(RAM) + LENGTH(RAM); */
|
||||
|
||||
/* You can use this symbol to customize the location of the .text section */
|
||||
/* If omitted the .text section will be placed right after the .vector_table
|
||||
section */
|
||||
/* This is required only on microcontrollers that store some configuration right
|
||||
after the vector table */
|
||||
/* _stext = ORIGIN(FLASH) + 0x400; */
|
||||
|
||||
/* Example of putting non-initialized variables into custom RAM locations. */
|
||||
/* This assumes you have defined a region RAM2 above, and in the Rust
|
||||
sources added the attribute `#[link_section = ".ram2bss"]` to the data
|
||||
you want to place there. */
|
||||
/* Note that the section will not be zero-initialized by the runtime! */
|
||||
/* SECTIONS {
|
||||
.ram2bss (NOLOAD) : ALIGN(4) {
|
||||
*(.ram2bss);
|
||||
. = ALIGN(4);
|
||||
} > RAM2
|
||||
} INSERT AFTER .bss;
|
||||
*/
|
63
src/main.rs
Normal file
63
src/main.rs
Normal file
@ -0,0 +1,63 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
use cortex_m::peripheral::{syst, Peripherals};
|
||||
use cortex_m_rt::{entry, exception};
|
||||
use cortex_m_semihosting::hprintln;
|
||||
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use nrf52832_hal as hal;
|
||||
use nrf52832_hal::gpio::Level;
|
||||
|
||||
use panic_semihosting as _;
|
||||
|
||||
const F_CPU:u32 = 64_000_000;
|
||||
|
||||
static mut FIRE_1S:bool = false;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
hprintln!("Hello, world!").unwrap();
|
||||
|
||||
let peripherals = Peripherals::take().unwrap();
|
||||
let mut systick = peripherals.SYST;
|
||||
systick.set_clock_source(syst::SystClkSource::Core);
|
||||
systick.set_reload(F_CPU / 1000 - 1);
|
||||
systick.clear_current();
|
||||
systick.enable_interrupt();
|
||||
systick.enable_counter();
|
||||
|
||||
let p = hal::pac::Peripherals::take().unwrap();
|
||||
let port0 = hal::gpio::p0::Parts::new(p.P0);
|
||||
let mut led = port0.p0_17.into_push_pull_output(Level::Low);
|
||||
led.set_low().unwrap();
|
||||
|
||||
let mut state:bool = false;
|
||||
loop {
|
||||
unsafe {
|
||||
if FIRE_1S {
|
||||
FIRE_1S = false;
|
||||
if state {
|
||||
hprintln!("off").unwrap();
|
||||
led.set_low().unwrap();
|
||||
state = false;
|
||||
} else {
|
||||
hprintln!("on").unwrap();
|
||||
led.set_high().unwrap();
|
||||
state = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[exception]
|
||||
fn SysTick() {
|
||||
static mut CNT:u32 = 0;
|
||||
*CNT += 1;
|
||||
if *CNT == 1000 {
|
||||
*CNT = 0;
|
||||
unsafe {
|
||||
FIRE_1S = true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user