Created
August 30, 2019 10:10
-
-
Save btrepp/a9e7839d938dd43d6e525ee73719b88d to your computer and use it in GitHub Desktop.
RXNEIE not firing?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![no_std] | |
#![no_main] | |
// pick a panicking behavior | |
extern crate panic_halt; // you can put a breakpoint on `rust_begin_unwind` to catch panics | |
// extern crate panic_abort; // requires nightly | |
// extern crate panic_itm; // logs messages over ITM; requires ITM support | |
// extern crate panic_semihosting; // logs messages to the host stderr; requires a debugger | |
use cortex_m_semihosting::{hprintln}; | |
use rtfm::{app}; | |
//use nb; | |
use stm32f4xx_hal:: { | |
prelude::*, | |
gpio:: { | |
GpioExt, | |
gpioa::PA5, | |
PushPull, | |
Output, | |
}, | |
stm32, | |
hal:: { | |
digital::v2::OutputPin, | |
}, | |
serial, | |
nb | |
}; | |
use core::result::Result; | |
type LED = PA5<Output<PushPull>>; | |
type TX = serial::Tx<stm32::USART2>; | |
type RX = serial::Rx<stm32::USART2>; | |
//type SERIAL2 = serial::Serial<stm32::USART2,?>; | |
#[app(device = stm32f4::stm32f411)] | |
const APP: () = { | |
static mut LED: LED = (); //OutputPin<Error=!> = (); | |
static mut TX : TX = (); | |
static mut RX : RX = (); | |
//static mut SERIAL2 : SERIAL2 = (); | |
#[init(spawn = [blink])] | |
fn init() -> init::LateResources { | |
// Cortex-M peripherals | |
let _core: rtfm::Peripherals = core; | |
// Device specific peripherals | |
let device: stm32f4::stm32f411::Peripherals = device; | |
let gpioa = device.GPIOA.split(); | |
let pin = gpioa.pa5.into_push_pull_output(); | |
let config = serial::config::Config::default() | |
.baudrate(9600.bps()) | |
; | |
//Enable RX interrupt? | |
device.USART2.cr1.modify(|_,w| w.rxneie().set_bit()); | |
let clocks = device.RCC.constrain().cfgr.freeze(); | |
let tx_pin = gpioa.pa2.into_alternate_af7(); | |
let rx_pin = gpioa.pa3.into_alternate_af7(); | |
let pins = (tx_pin,rx_pin); | |
let (tx,rx) = | |
serial::Serial::usart2(device.USART2, | |
pins, | |
config, | |
clocks).unwrap().split(); | |
hprintln!("init").unwrap(); | |
spawn.blink().unwrap(); | |
init::LateResources { | |
LED : pin, | |
TX : tx, | |
RX: rx, | |
} | |
} | |
#[task(schedule = [blink], resources = [LED,TX])] | |
fn blink(){ | |
static mut STATE: bool = false; | |
let led = resources.LED; | |
if *STATE ==true { | |
led.set_low().unwrap(); | |
//hprintln!("Blink On").unwrap(); | |
} else { | |
led.set_high().unwrap(); | |
//hprintln!("Blink Off").unwrap(); | |
} | |
resources.TX.write('h' as u8); | |
*STATE = !*STATE; | |
schedule.blink(scheduled+8_000_000.cycles()).unwrap(); | |
} | |
#[interrupt(resources = [RX])] | |
fn USART2(){ | |
hprintln!("Rx").unwrap(); | |
match resources.RX.read() { | |
Err(x) => | |
match x { | |
nb::Error::WouldBlock => (), | |
nb::Error::Other(_) => () | |
}, | |
Ok (x) => | |
hprintln!("X",).unwrap() | |
} | |
} | |
extern "C" { | |
fn USART1(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment