diff options
author | Brian Cully <bjc@kublai.com> | 2022-08-08 12:19:08 -0400 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2022-08-08 12:19:08 -0400 |
commit | cabe5b42cfe408c7bbde8b4bd40ce0282eb7e58c (patch) | |
tree | 9247007dc67478babeab603150bbe9daeeaa6bf6 /src/main.rs | |
parent | 340eb6eb0d3fb47f5d968c323c92943662457fda (diff) | |
download | luchie-cabe5b42cfe408c7bbde8b4bd40ce0282eb7e58c.tar.gz luchie-cabe5b42cfe408c7bbde8b4bd40ce0282eb7e58c.zip |
get serial printing on usart1 (tx: pa2, rx: pa3)
Diffstat (limited to 'src/main.rs')
-rwxr-xr-x | src/main.rs | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 2740d25..a711398 100755 --- a/src/main.rs +++ b/src/main.rs @@ -3,11 +3,15 @@ mod blink; mod led; +mod log; use gd32vf103xx_hal::{ + afio::AfioExt, eclic::{self, EclicExt}, + gpio::GpioExt, pac::{self, Peripherals}, rcu::RcuExt, + serial::Serial, time::Hertz, timer, }; @@ -26,19 +30,39 @@ pub enum PollResult { #[entry] fn main(_hartid: usize) -> ! { - let p = unsafe { Peripherals::steal() }; + let p = Peripherals::take().expect("couldn't take peripherals"); pac::ECLIC::set_threshold_level(eclic::Level::L0); pac::ECLIC::set_level_priority_bits(eclic::LevelPriorityBits::L3P1); - let t6 = p.TIMER6; let mut rcu = p.RCU.configure().freeze(); - let timer = timer::Timer::<pac::TIMER6>::timer6(t6, Hertz(1), &mut rcu); + let mut afio = p.AFIO.constrain(&mut rcu); - let led = LED::new(); + let timer = timer::Timer::<pac::TIMER6>::timer6(p.TIMER6, Hertz(1), &mut rcu); + let gpioa = p.GPIOA.split(&mut rcu); + let led = LED::new(gpioa.pa7); let mut blink = blink::Task::new(timer, Hertz(5), led); + + // TODO: figure out how to use the usb serial on the start board. + // + // this version has to be wired up physically. + let serial = Serial::new( + p.USART1, + (gpioa.pa2, gpioa.pa3), + Default::default(), + &mut afio, + &mut rcu, + ); + let (tx, _rx) = serial.split(); + log::new(tx); + loop { - if blink.poll() == PollResult::WouldBlock { + let mut can_sleep = true; + + can_sleep &= blink.poll() == PollResult::WouldBlock; + log::log("hi\r\n"); + + if can_sleep { unsafe { wfi() }; } } |