Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

turn macros into attributes #90

Merged
merged 13 commits into from
Sep 6, 2018
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
**/*.rs.bk
.#*
Cargo.lock
bin/*.after
bin/*.before
Expand Down
37 changes: 21 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@ language: rust
matrix:
include:
- env: TARGET=x86_64-unknown-linux-gnu
rust: stable
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)

- env: TARGET=thumbv6m-none-eabi
rust: stable
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)

- env: TARGET=thumbv7m-none-eabi
rust: stable
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)

- env: TARGET=thumbv7em-none-eabi
rust: stable
# TODO switch to 1.30-beta
rust: nightly
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)

- env: TARGET=thumbv7em-none-eabihf
rust: stable
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
# TODO enable when 1.30-beta is out
# - env: TARGET=thumbv6m-none-eabi
# rust: beta
# if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)

# TODO enable when 1.30-beta is out
# - env: TARGET=thumbv7m-none-eabi
# rust: beta
# if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)

# TODO enable when 1.30-beta is out
# - env: TARGET=thumbv7em-none-eabi
# rust: beta
# if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)

# TODO enable when 1.30-beta is out
# - env: TARGET=thumbv7em-none-eabihf
# rust: beta
# if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)

- env: TARGET=thumbv6m-none-eabi
rust: nightly
Expand Down
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ version = "0.5.3"

[dependencies]
r0 = "0.2.1"
cortex-m-rt-macros = { path = "macros", version = "0.1.0" }

[dev-dependencies]
panic-semihosting = "0.3.0"
panic-abort = "0.2.0"
cortex-m = "0.5.4"
panic-abort = "0.3.0"
panic-semihosting = "0.4.0"

[target.'cfg(not(target_os = "none"))'.dev-dependencies]
compiletest_rs = "0.3.14"

[features]
device = []
23 changes: 15 additions & 8 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,31 @@ main() {

cargo check --target $TARGET --features device

if [ $TARGET = x86_64-unknown-linux-gnu ]; then
( cd macros && cargo check && cargo test )

cargo test --test compiletest
fi

local examples=(
alignment
minimal
divergent-default-handler
divergent-exception
entry-static
main
minimal
override-exception
pre_init
state
unsafe-default-handler
unsafe-hard-fault
unsafe-entry
unsafe-exception
)
local fail_examples=(
data_overflow
)
if [ $TRAVIS_RUST_VERSION = nightly ]; then
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
# linking with GNU LD
for ex in "${examples[@]}"; do
cargo rustc --target $TARGET --example $ex -- \
Expand Down Expand Up @@ -48,29 +61,23 @@ main() {
# linking with rustc's LLD
for ex in "${examples[@]}"; do
cargo rustc --target $TARGET --example $ex -- \
-C linker=rust-lld \
-C link-arg=-Tlink.x

cargo rustc --target $TARGET --example $ex --release -- \
-C linker=rust-lld \
-C link-arg=-Tlink.x
done
for ex in "${fail_examples[@]}"; do
! cargo rustc --target $TARGET --example $ex -- \
-C linker=rust-lld \
-C link-arg=-Tlink.x

! cargo rustc --target $TARGET --example $ex --release -- \
-C linker=rust-lld \
-C link-arg=-Tlink.x
done

cargo rustc --target $TARGET --example device --features device -- \
-C linker=rust-lld \
-C link-arg=-Tlink.x

cargo rustc --target $TARGET --example device --features device --release -- \
-C linker=rust-lld \
-C link-arg=-Tlink.x
fi

Expand Down
4 changes: 2 additions & 2 deletions examples/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
#![no_main]
#![no_std]

#[macro_use(entry)]
extern crate cortex_m_rt as rt;
extern crate panic_abort;

use core::ptr;

entry!(main);
use rt::entry;

static mut BSS1: u16 = 0;
static mut BSS2: u8 = 0;
Expand All @@ -19,6 +18,7 @@ static mut DATA2: u16 = 1;
static RODATA1: &[u8; 3] = b"012";
static RODATA2: &[u8; 2] = b"34";

#[entry]
fn main() -> ! {
unsafe {
let _bss1 = ptr::read_volatile(&BSS1);
Expand Down
4 changes: 2 additions & 2 deletions examples/data_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
#![no_main]
#![no_std]

#[macro_use(entry)]
extern crate cortex_m_rt as rt;
extern crate panic_abort;

use core::ptr;

entry!(main);
use rt::entry;

// This large static array uses most of .rodata
static RODATA: [u8; 48*1024] = [1u8; 48*1024];
Expand All @@ -20,6 +19,7 @@ static RODATA: [u8; 48*1024] = [1u8; 48*1024];
// without also overflowing RAM.
static mut DATA: [u8; 16*1024] = [1u8; 16*1024];

#[entry]
fn main() -> ! {
unsafe {
let _bigdata = ptr::read_volatile(&RODATA as *const u8);
Expand Down
5 changes: 2 additions & 3 deletions examples/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
#![no_main]
#![no_std]

#[macro_use(entry)]
extern crate cortex_m_rt as rt;
extern crate panic_semihosting;

// the program entry point
entry!(main);
use rt::entry;

#[entry]
fn main() -> ! {
loop {}
}
Expand Down
19 changes: 19 additions & 0 deletions examples/divergent-default-handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]

extern crate cortex_m_rt;
extern crate panic_semihosting;

use cortex_m_rt::{entry, exception};

#[entry]
fn foo() -> ! {
loop {}
}

#[exception]
fn DefaultHandler(_irqn: i16) -> ! {
loop {}
}
18 changes: 18 additions & 0 deletions examples/divergent-exception.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![deny(warnings)]
#![no_main]
#![no_std]

extern crate cortex_m_rt;
extern crate panic_semihosting;

use cortex_m_rt::{entry, exception};

#[entry]
fn foo() -> ! {
loop {}
}

#[exception]
fn SysTick() -> ! {
loop {}
}
20 changes: 20 additions & 0 deletions examples/entry-static.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! `static mut` variables local to the entry point are safe to use

#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]

extern crate cortex_m_rt as rt;
extern crate panic_semihosting;

use rt::entry;

#[entry]
fn main() -> ! {
static mut COUNT: u32 = 0;

loop {
*COUNT += 1;
}
}
6 changes: 3 additions & 3 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#![no_main]
#![no_std]

#[macro_use(entry)]
extern crate cortex_m_rt as rt;
extern crate panic_semihosting;

// the program entry point
entry!(main);
use rt::entry;

// the program entry point
#[entry]
fn main() -> ! {
loop {}
}
17 changes: 6 additions & 11 deletions examples/override-exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,24 @@
#![no_std]

extern crate cortex_m;
#[macro_use(entry, exception)]
extern crate cortex_m_rt as rt;
extern crate panic_semihosting;

use cortex_m::asm;
use rt::ExceptionFrame;

// the program entry point
entry!(main);
use rt::{entry, exception, ExceptionFrame};

#[entry]
fn main() -> ! {
loop {}
}

exception!(*, default_handler);

fn default_handler(_irqn: i16) {
#[exception]
fn DefaultHandler(_irqn: i16) {
asm::bkpt();
}

exception!(HardFault, hard_fault);

fn hard_fault(_ef: &ExceptionFrame) -> ! {
#[exception]
fn HardFault(_ef: &ExceptionFrame) -> ! {
asm::bkpt();

loop {}
Expand Down
8 changes: 3 additions & 5 deletions examples/pre_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
#![no_main]
#![no_std]

#[macro_use(entry, pre_init)]
extern crate cortex_m_rt as rt;
extern crate panic_semihosting;

pre_init!(disable_watchdog);
use rt::{entry, pre_init};

#[pre_init]
unsafe fn disable_watchdog() {
// Do what you need to disable the watchdog.
}

// the program entry point
entry!(main);

#[entry]
fn main() -> ! {
loop {}
}
12 changes: 6 additions & 6 deletions examples/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
#![no_main]
#![no_std]

#[macro_use(entry, exception)]
extern crate cortex_m_rt as rt;
extern crate panic_semihosting;

// the program entry point
entry!(main);
use rt::{entry, exception};

#[entry]
fn main() -> ! {
loop {}
}

// exception handler with state
exception!(SysTick, sys_tick, state: u32 = 0);
#[exception]
fn SysTick() {
static mut STATE: u32 = 0;

fn sys_tick(state: &mut u32) {
*state += 1;
*STATE += 1;
}
16 changes: 16 additions & 0 deletions examples/unsafe-default-handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![deny(warnings)]
#![no_main]
#![no_std]

extern crate cortex_m_rt;
extern crate panic_semihosting;

use cortex_m_rt::{entry, exception};

#[entry]
fn foo() -> ! {
loop {}
}

#[exception]
unsafe fn DefaultHandler(_irqn: i16) {}
13 changes: 13 additions & 0 deletions examples/unsafe-entry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![deny(warnings)]
#![no_main]
#![no_std]

extern crate cortex_m_rt;
extern crate panic_semihosting;

use cortex_m_rt::entry;

#[entry]
unsafe fn foo() -> ! {
loop {}
}
Loading