Skip to content

Commit f2a155a

Browse files
committed
turn macros into attributes
1 parent 0fb0510 commit f2a155a

File tree

13 files changed

+517
-281
lines changed

13 files changed

+517
-281
lines changed

cortex-m-rt/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
**/*.rs.bk
2+
.#*
23
Cargo.lock
34
bin/*.after
45
bin/*.before

cortex-m-rt/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ version = "0.5.3"
1212

1313
[dependencies]
1414
r0 = "0.2.1"
15+
cortex-m-rt-macros = { path = "macros", version = "0.1.0" }
1516

1617
[dev-dependencies]
1718
panic-semihosting = "0.3.0"

cortex-m-rt/ci/script.sh

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ main() {
55

66
cargo check --target $TARGET --features device
77

8+
( cd macros && cargo check && cargo test )
9+
810
local examples=(
911
alignment
1012
minimal

cortex-m-rt/examples/alignment.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
#![no_main]
55
#![no_std]
66

7-
#[macro_use(entry)]
87
extern crate cortex_m_rt as rt;
98
extern crate panic_abort;
109

1110
use core::ptr;
1211

13-
entry!(main);
12+
use rt::entry;
1413

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

21+
#[entry]
2222
fn main() -> ! {
2323
unsafe {
2424
let _bss1 = ptr::read_volatile(&BSS1);

cortex-m-rt/examples/data_overflow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
#![no_main]
66
#![no_std]
77

8-
#[macro_use(entry)]
98
extern crate cortex_m_rt as rt;
109
extern crate panic_abort;
1110

1211
use core::ptr;
1312

14-
entry!(main);
13+
use rt::entry;
1514

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

22+
#[entry]
2323
fn main() -> ! {
2424
unsafe {
2525
let _bigdata = ptr::read_volatile(&RODATA as *const u8);

cortex-m-rt/examples/device.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
#![no_main]
66
#![no_std]
77

8-
#[macro_use(entry)]
98
extern crate cortex_m_rt as rt;
109
extern crate panic_semihosting;
1110

12-
// the program entry point
13-
entry!(main);
11+
use rt::entry;
1412

13+
#[entry]
1514
fn main() -> ! {
1615
loop {}
1716
}

cortex-m-rt/examples/minimal.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
#![no_main]
66
#![no_std]
77

8-
#[macro_use(entry)]
98
extern crate cortex_m_rt as rt;
109
extern crate panic_semihosting;
1110

12-
// the program entry point
13-
entry!(main);
11+
use rt::entry;
1412

13+
// the program entry point
14+
#[entry]
1515
fn main() -> ! {
1616
loop {}
1717
}

cortex-m-rt/examples/override-exception.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,23 @@
66
#![no_std]
77

88
extern crate cortex_m;
9-
#[macro_use(entry, exception)]
109
extern crate cortex_m_rt as rt;
1110
extern crate panic_semihosting;
1211

1312
use cortex_m::asm;
14-
use rt::ExceptionFrame;
15-
16-
// the program entry point
17-
entry!(main);
13+
use rt::{entry, exception, ExceptionFrame};
1814

15+
#[entry]
1916
fn main() -> ! {
2017
loop {}
2118
}
2219

23-
exception!(*, default_handler);
24-
20+
#[exception(DefaultHandler)]
2521
fn default_handler(_irqn: i16) {
2622
asm::bkpt();
2723
}
2824

29-
exception!(HardFault, hard_fault);
30-
25+
#[exception(HardFault)]
3126
fn hard_fault(_ef: &ExceptionFrame) -> ! {
3227
asm::bkpt();
3328

cortex-m-rt/examples/pre_init.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44
#![no_main]
55
#![no_std]
66

7-
#[macro_use(entry, pre_init)]
87
extern crate cortex_m_rt as rt;
98
extern crate panic_semihosting;
109

11-
pre_init!(disable_watchdog);
10+
use rt::{entry, pre_init};
1211

12+
#[pre_init]
1313
unsafe fn disable_watchdog() {
1414
// Do what you need to disable the watchdog.
1515
}
1616

17-
// the program entry point
18-
entry!(main);
19-
17+
#[entry]
2018
fn main() -> ! {
2119
loop {}
2220
}

cortex-m-rt/examples/state.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@
55
#![no_main]
66
#![no_std]
77

8-
#[macro_use(entry, exception)]
98
extern crate cortex_m_rt as rt;
109
extern crate panic_semihosting;
1110

12-
// the program entry point
13-
entry!(main);
11+
use rt::{entry, exception};
1412

13+
#[entry]
1514
fn main() -> ! {
1615
loop {}
1716
}
1817

1918
// exception handler with state
20-
exception!(SysTick, sys_tick, state: u32 = 0);
21-
22-
fn sys_tick(state: &mut u32) {
23-
*state += 1;
19+
#[exception(SysTick, static STATE: u32 = 0)]
20+
fn sys_tick() {
21+
*STATE += 1;
2422
}

cortex-m-rt/macros/Cargo.toml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "cortex-m-rt-macros"
3+
version = "0.1.0"
4+
authors = ["Jorge Aparicio <[email protected]>"]
5+
6+
[lib]
7+
proc-macro = true
8+
9+
[dependencies]
10+
quote = "0.6.6"
11+
12+
[dependencies.syn]
13+
features = ["extra-traits", "full"]
14+
version = "0.14.8"
15+
16+
[dev-dependencies]
17+
cortex-m-rt = { path = ".." }

0 commit comments

Comments
 (0)