Skip to content

Commit 0f022c7

Browse files
Clarify usage of #[interrupt] attribute and recommend device crate re-export
1 parent 0b8219a commit 0f022c7

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/start/interrupts.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,22 @@ The general initialization steps at runtime are always the same:
1919
* Set the desired priority of the interrupt handler in the interrupt controller
2020
* Enable the interrupt handler in the interrupt controller
2121

22-
Similarly to exceptions, the `cortex-m-rt` crate provides an [`interrupt`]
23-
attribute to declare interrupt handlers. The available interrupts (and
24-
their position in the interrupt handler table) are usually automatically
25-
generated via `svd2rust` from a SVD description.
22+
Similarly to exceptions, the cortex-m-rt crate exposes an [`interrupt`] attribute for declaring interrupt handlers. However, this
23+
attribute is only available when the device feature is enabled. That said, this attribute is not intended to be used directly—doing
24+
so will result in a compilation error.
25+
26+
Instead, you should use the re-exported version of the interrupt attribute provided by the device crate (usually generated using svd2rust).
27+
This ensures that the compiler can verify that the interrupt actually exists on the target device. The list of available interrupts—and
28+
their position in the interrupt vector table—is typically auto-generated from an SVD file by svd2rust.
2629

2730
[`interrupt`]: https://docs.rs/cortex-m-rt-macros/0.1.5/cortex_m_rt_macros/attr.interrupt.html
2831

2932
``` rust,ignore
33+
use lm3s6965::interrupt; // Re-exported attribute from the device crate
34+
3035
// Interrupt handler for the Timer2 interrupt
3136
#[interrupt]
32-
fn TIM2() {
37+
fn TIMER2A() {
3338
// ..
3439
// Clear reason for the generated interrupt request
3540
}
@@ -46,7 +51,7 @@ variables inside the interrupt handlers for *safe* state keeping.
4651

4752
``` rust,ignore
4853
#[interrupt]
49-
fn TIM2() {
54+
fn TIMER2A() {
5055
static mut COUNT: u32 = 0;
5156
5257
// `COUNT` has type `&mut u32` and it's safe to use

0 commit comments

Comments
 (0)