如何在stm32f30x中从cortex-m-rt获取中断重新导出来运行

问题描述

我想使用 rust 和 cortex-m-rtstm32f30x 板条箱为 STM32F3discovery 板编写程序。更准确地说,我想实现一个我想使用 #[interrupt] 属性的外部中断。但是转口好像有问题。

cortex-m-rt documentation on interrupts 表示不应直接使用 #[interrupt] 属性,而应使用设备箱中的重新导出:

extern crate device;

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

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

事实上,stm32f3x crate 的文档显示 cortex-m-rt 箱中的这个属性被重新导出。但是,编译:

#![no_main]
#![no_std]

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

#![no_main]
#![no_std]

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

给出错误

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

我不知道为什么会发生这种情况,因为 example I followed 也是如此。我在 Cargo.toml 中的依赖项如下所示:

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

我很感激任何帮助:)

解决方法

您需要启用 stm32f30x cratert 功能。

简而言之,像这样更改您的依赖项:

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

功能没有出现在 "Features flags" page 上的原因是因为版本比“功能标志”本身(PR #1144)更旧,这就是页面提到“功能此版本没有标志数据”。

如果文档没有提到功能。然后是“最简单”的方式来了解问题是否由功能引起。是检查 Cargo.toml for stm32f30x 是否包含任何特征。然后,寻找任何特征门。在这种情况下,如果您查看 lib.rs at the re-export,则会看到以下内容:

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...