Skip to content
Snippets Groups Projects
Commit 0fa98325 authored by Florian Jung's avatar Florian Jung
Browse files

usart support

parent 8dd413c1
Branches master
No related tags found
No related merge requests found
...@@ -38,6 +38,7 @@ dependencies = [ ...@@ -38,6 +38,7 @@ dependencies = [
"cortex-m 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
"cortex-m-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "cortex-m-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"panic-halt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "panic-halt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"stm32f4xx-hal 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "stm32f4xx-hal 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
......
...@@ -39,3 +39,5 @@ version = "0.6.4" ...@@ -39,3 +39,5 @@ version = "0.6.4"
[dependencies.panic-halt] [dependencies.panic-halt]
version = "0.2.0" version = "0.2.0"
[dependencies.nb]
...@@ -10,12 +10,18 @@ extern crate embedded_hal as hal; ...@@ -10,12 +10,18 @@ extern crate embedded_hal as hal;
use cortex_m_rt::entry; use cortex_m_rt::entry;
use core::fmt::Write;
use mcu::delay::Delay; use mcu::delay::Delay;
use mcu::prelude::*; use mcu::prelude::*;
use mcu::stm32; use mcu::stm32;
use mcu::gpio; use mcu::gpio;
use mcu::gpio::gpiod::{PD12, PD13, PD14, PD15}; use mcu::gpio::gpiod::{PD12, PD13, PD14, PD15};
use mcu::serial;
use mcu::nb::block;
use hal::digital::OutputPin; use hal::digital::OutputPin;
...@@ -32,6 +38,13 @@ struct Leds { ...@@ -32,6 +38,13 @@ struct Leds {
fn main() -> ! { fn main() -> ! {
if let (Some(p), Some(cp)) = (stm32::Peripherals::take(), Peripherals::take()) { if let (Some(p), Some(cp)) = (stm32::Peripherals::take(), Peripherals::take()) {
let gpiod = p.GPIOD.split(); let gpiod = p.GPIOD.split();
let gpioa = p.GPIOA.split();
// Constrain clock registers
let mut rcc = p.RCC.constrain();
// Configure clock to 168 MHz (i.e. the maximum) and freeze it
let clocks = rcc.cfgr.sysclk(84.mhz()).freeze();
// Configure LED outputs // Configure LED outputs
let mut leds = Leds { let mut leds = Leds {
...@@ -41,11 +54,14 @@ fn main() -> ! { ...@@ -41,11 +54,14 @@ fn main() -> ! {
blue: gpiod.pd15.into_push_pull_output(), blue: gpiod.pd15.into_push_pull_output(),
}; };
// Constrain clock registers let pin_tx = gpioa.pa2.into_alternate_af7();
let mut rcc = p.RCC.constrain(); //let pin_rx = gpioa.pa3.into_alternate_af7();
let pin_rx = serial::NoRx;
let mut usart = serial::Serial::usart2(p.USART2, (pin_tx, pin_rx), serial::config::Config::default().baudrate(115200.bps()), clocks).unwrap();
// separate into tx and rx channels
let (mut tx, mut rx) = usart.split();
// Configure clock to 168 MHz (i.e. the maximum) and freeze it
let clocks = rcc.cfgr.sysclk(84.mhz()).freeze();
// Get delay provider // Get delay provider
let mut delay = Delay::new(cp.SYST, clocks); let mut delay = Delay::new(cp.SYST, clocks);
...@@ -54,6 +70,25 @@ fn main() -> ! { ...@@ -54,6 +70,25 @@ fn main() -> ! {
// Turn LED on // Turn LED on
leds.blue.set_high(); leds.blue.set_high();
/*tx.write(b'h').ok();
tx.write(b'e').ok();
tx.write(b'l').ok();
tx.write(b'l').ok();
tx.write(b'o').ok();
tx.write(b'\r').ok();
tx.write(b'\n').ok();*/
/*block!(usart.write(b'h')).ok();
block!(usart.write(b'e')).ok();
block!(usart.write(b'l')).ok();
block!(usart.write(b'l')).ok();
block!(usart.write(b'o')).ok();*/
//usart.write_str("foo");
tx.write_str("foo");
writeln!(tx, "bar");
// Delay twice for half a second due to limited timer resolution // Delay twice for half a second due to limited timer resolution
delay.delay_ms(500_u16); delay.delay_ms(500_u16);
delay.delay_ms(500_u16); delay.delay_ms(500_u16);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment