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

Commit b6674f7

Browse files
author
Jorge Aparicio
authored
Merge pull request #4 from japaric/dev
make the "linker-script" Cargo feature opt-out
2 parents 8e80b59 + 56d0dec commit b6674f7

File tree

3 files changed

+90
-7
lines changed

3 files changed

+90
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ optional = true
2020
version = "0.1.3"
2121

2222
[features]
23-
default = ["exceptions"]
23+
default = ["exceptions", "linker-script"]
2424
# handle exceptions using the default handler
2525
exceptions = ["cortex-m"]
2626
linker-script = []

link.x

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,19 @@ SECTIONS
4343
}
4444
}
4545

46-
ASSERT(__exceptions - ORIGIN(FLASH) == 0x40,
47-
"you must define the _EXCEPTIONS symbol");
48-
49-
ASSERT(__interrupts - __exceptions > 0,
50-
"you must define the _INTERRUPTS symbol");
46+
ASSERT(__exceptions - ORIGIN(FLASH) == 0x40, "
47+
You must specify the exception handlers.
48+
Create a non `pub` static variable with type
49+
`cortex_m::exception::Handlers` and place it in the
50+
'.rodata.exceptions' section. (cf. #[link_section])
51+
Apply the `#[used]` attribute to the variable to help it reach the linker.");
52+
53+
ASSERT(__interrupts - __exceptions > 0, "
54+
You must specify the interrupt handlers.
55+
Create a non `pub` static variable and place it in the
56+
'.rodata.interrupts' section. (cf. #[link_section])
57+
Apply the `#[used]` attribute to the variable to help it reach the linker.");
58+
59+
ASSERT(__interrupts - __exceptions <= 0x3c0, "
60+
There can't be more than 240 interrupt handlers.
61+
Fix the '.rodata.interrupts' section. (cf. #[link_section])");

src/lib.rs

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Minimal startup / runtime for Cortex-M microcontrollers
22
//!
3-
//! Provides
3+
//! # Features
4+
//!
5+
//! This crate provides
46
//!
57
//! - Before main initialization of the `.bss` and `.data` sections
68
//!
@@ -67,6 +69,76 @@
6769
//! #[used]
6870
//! static INTERRUPTS: SomeStruct = SomeStruct { .. }
6971
//! ```
72+
//!
73+
//! # Usage
74+
//!
75+
//! ``` text
76+
//! $ cargo new --bin app && cd $_
77+
//!
78+
//! $ cargo add cortex-m cortex-m-rt
79+
//!
80+
//! $ cat Xargo.toml
81+
//! ```
82+
//!
83+
//! ``` text
84+
//! [dependencies.core]
85+
//!
86+
//! [dependencies.compiler_builtins]
87+
//! features = ["mem"]
88+
//! git = "https://github.com/rust-lang-nursery/compiler-builtins"
89+
//! stage = 1
90+
//! ```
91+
//!
92+
//! ``` text
93+
//! $ cat memory.x
94+
//! ```
95+
//!
96+
//! ``` text
97+
//! MEMORY
98+
//! {
99+
//! FLASH : ORIGIN = 0x08000000, LENGTH = 128K
100+
//! RAM : ORIGIN = 0x20000000, LENGTH = 8K
101+
//! }
102+
//! ```
103+
//!
104+
//! ``` text
105+
//! $ cat src/main.rs
106+
//! ```
107+
//!
108+
//! ``` ignore,no_run
109+
//! #![feature(used)]
110+
//! #![no_std]
111+
//!
112+
//! #[macro_use]
113+
//! extern crate cortex_m;
114+
//! extern crate cortex_m_rt;
115+
//!
116+
//! fn main() {
117+
//! hprintln!("Hello, world!");
118+
//! }
119+
//!
120+
//! #[allow(dead_code)]
121+
//! #[link_section = ".rodata.interrupts"]
122+
//! #[used]
123+
//! static INTERRUPTS: [u32; 240] = [0; 240];
124+
//! ```
125+
//!
126+
//! ``` text
127+
//! $ xargo rustc --target thumbv7m-none-eabi -- -C link-args='-Tlink.x -nostartfiles'
128+
//!
129+
//! $ arm-none-eabi-objdump -Cd $(find target -name app) | less
130+
//! 08000000 <_VECTOR_TABLE>:
131+
//! 8000000: 20002000 .word 0x20002000
132+
//!
133+
//! 08000004 <cortex_m_rt::RESET_HANDLER>:
134+
//! 8000004: 08000671 q...
135+
//!
136+
//! 08000008 <cortex_m_rt::EXCEPTIONS>:
137+
//! 8000008: 080005a5 080005bd 08000569 08000599 ........i.......
138+
//! 8000018: 08000581 00000000 00000000 00000000 ................
139+
//! 8000028: 00000000 080005b1 00000000 00000000 ................
140+
//! 8000038: 0800058d 08000575 ....u...
141+
//! ```
70142
71143
#![deny(missing_docs)]
72144
#![deny(warnings)]

0 commit comments

Comments
 (0)