Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

rust - How to get the interrupt reexport from cortex-m-rt in stm32f30x to run

I want to write a program for the STM32F3Discovery board using rust and the cortex-m-rt and stm32f30x crates. More precisely I want to implement an external interrupt for which I want to use the #[interrupt] attribute. But there seems to be a problem with the reexport.

The cortex-m-rt documentation on interrupts says that the #[interrupt] attribute should not be used directly but rather the re-export in the device crate should be used:

extern crate device;

// the attribute comes from the device crate not from cortex-m-rt
use device::interrupt;

#[interrupt]
fn USART1() {
    // ..
}

And indeed the documentation for the stm32f3x crate shows that this attribute from the cortex-m-rt crate is re-exported. However, compiling:

#![no_main]
#![no_std]

use cortex_m_rt::entry;
extern crate stm32f30x;
use stm32f30x::interrupt;

or

#![no_main]
#![no_std]

use cortex_m_rt::entry;
use stm32f30x::interrupt;

gives the error

error[E0432]: unresolved import `stm32f30x::interrupt`
 --> srcmain.rs:9:5
  |
9 | use stm32f30x::interrupt;
  |     ^^^^^^^^^^^---------
  |     |          |
  |     |          help: a similar name exists in the module (notice the capitalization): `Interrupt`
  |     no `interrupt` in the root

I have no idea why this happens, as the example I followed did the same. My dependencies in Cargo.toml look like the following:

[dependencies]
stm32f30x = "0.8.0"
cortex-m-rt = "0.6.3"
cortex-m = "0.6.3"

I am gratefull for any help :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to enable the rt feature of the stm32f30x crate.

In short, change your dependencies like this:

[dependencies]
stm32f30x = { version = "0.8.0", features = ["rt"] }
cortex-m-rt = "0.6.3"
cortex-m = "0.6.3"

The reason the feature(s) doesn't appear on the "Features flags" page, is because the release is older than "Feature flags" itself (PR #1144), which is why the page mentions "Feature flags data are not available for this release".

If the documentation doesn't mention features. Then the "easiest" way to know, if an issue is caused by a feature. Is to check if the Cargo.toml for stm32f30x contains any features. Then after that, look for any feature gates. In this case, if you look in lib.rs at the re-export, then you'll see the following:

#[cfg(feature = "rt")]
pub use self::Interrupt as interrupt;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...