我正在尝试在STM32F407G-DISC1上接收简单的中断,并且我似乎无法配置EXTI0中断通道以从PE0接收,相反,它似乎仅在更改PA0时触发。
当我将3.3V引脚短接到PA0时,它会显示“接收到中断”,但是当我将3.3V短接到PE0时,什么也没发生。
我缺少一些配置调用吗?
构建脚本和其他配置文件基于the cortex-m quickstart,并进行了少量修改。如果相关,我也可以发布。
这是我的代码:
# Cargo.toml
[package]
name = "embedded-interrupt"
version = "0.1.0"
edition = "2018"
[dependencies]
cortex-m = "0.6.0"
cortex-m-rt = "0.6.8"
cortex-m-semihosting = "0.3.3"
panic-semihosting = "0.5"
hal = {package = "stm32f4xx-hal", features = ["stm32f407", "rt"], version = "0.5" }
// main.rs
#![no_std]
#![no_main]
extern crate panic_semihosting;
use cortex_m_rt::entry;
use cortex_m::interrupt::{Mutex, free};
use cortex_m_semihosting::hprintln;
use hal::prelude::*;
use hal::stm32::{interrupt, Interrupt, EXTI};
use hal::gpio::{ExtiPin, Edge, gpioe, Input, PullDown};
use core::cell::RefCell;
static PE0: Mutex<RefCell<Option<gpioe::PE0<Input<PullDown>>>>> = Mutex::new(RefCell::new(None));
static EXT_INTER: Mutex<RefCell<Option<EXTI>>> = Mutex::new(RefCell::new(None));
#[entry]
fn start() -> ! {
let p = hal::stm32::Peripherals::take().unwrap();
let c = cortex_m::Peripherals::take().unwrap();
let gpioe = p.GPIOE.split();
let mut syscfg = p.SYSCFG;
let mut exti = p.EXTI;
let mut nvic = c.NVIC;
nvic.enable(Interrupt::EXTI0);
let mut pe0 = gpioe.pe0.into_pull_down_input();
pe0.make_interrupt_source(&mut syscfg);
pe0.enable_interrupt(&mut exti);
pe0.trigger_on_edge(&mut exti, Edge::FALLING);
free(|cs| {
let cell = PE0.borrow(&cs);
*cell.borrow_mut() = Some(pe0);
let cell = EXT_INTER.borrow(&cs);
*cell.borrow_mut() = Some(exti);
});
loop{}
}
#[interrupt]
fn EXTI0() {
hprintln!("Interrupt received").unwrap();
// clear the interrupt
free(|cs| {
let pe0 = PE0.borrow(&cs);
let exti = EXT_INTER.borrow(&cs);
if let (Some(pe0), Some(mut exti)) = (pe0.borrow_mut().as_mut(), exti.borrow_mut().as_mut()) {
pe0.clear_interrupt_pending_bit(&mut exti);
}
});
}
答案 0 :(得分:0)
显然,必须启用系统配置控制器时钟才能更改syscfg寄存器。添加rcc.apb2enr.modify(|_, w| w.syscfgen().enabled());
使其起作用。全文:
#![no_std]
#![no_main]
extern crate panic_semihosting;
use cortex_m::interrupt::{free, Mutex};
use cortex_m_rt::entry;
use cortex_m_semihosting::hprintln;
use hal::gpio::{gpioe, Edge, ExtiPin, Input, PullDown};
use hal::prelude::*;
use hal::stm32::{interrupt, Interrupt, EXTI};
use core::cell::RefCell;
static PE0: Mutex<RefCell<Option<gpioe::PE0<Input<PullDown>>>>> = Mutex::new(RefCell::new(None));
static EXT_INTER: Mutex<RefCell<Option<EXTI>>> = Mutex::new(RefCell::new(None));
#[entry]
fn start() -> ! {
let p = hal::stm32::Peripherals::take().unwrap();
let c = cortex_m::Peripherals::take().unwrap();
let gpioe = p.GPIOE.split();
let rcc = p.RCC;
let mut syscfg = p.SYSCFG;
let mut exti = p.EXTI;
let mut nvic = c.NVIC;
rcc.apb2enr.modify(|_, w| w.syscfgen().enabled()); // important
nvic.enable(Interrupt::EXTI0);
let mut pe0 = gpioe.pe0.into_pull_down_input();
pe0.make_interrupt_source(&mut syscfg);
pe0.enable_interrupt(&mut exti);
pe0.trigger_on_edge(&mut exti, Edge::FALLING);
free(|cs| {
let cell = PE0.borrow(&cs);
*cell.borrow_mut() = Some(pe0);
let cell = EXT_INTER.borrow(&cs);
*cell.borrow_mut() = Some(exti);
});
loop {}
}
#[interrupt]
fn EXTI0() {
hprintln!("Interrupt received").unwrap();
// clear the interrupt
free(|cs| {
let pe0 = PE0.borrow(&cs);
let exti = EXT_INTER.borrow(&cs);
if let (Some(pe0), Some(mut exti)) = (pe0.borrow_mut().as_mut(), exti.borrow_mut().as_mut())
{
pe0.clear_interrupt_pending_bit(&mut exti);
}
});
}