- Use RTIC in UART IRQ example - Add RTIC template
This commit is contained in:
parent
d5b12c8343
commit
d458a81635
@ -27,6 +27,7 @@ version = "0.2.4"
|
|||||||
rt = ["va108xx/rt"]
|
rt = ["va108xx/rt"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
cortex-m-rtic = "0.6.0-rc.4"
|
||||||
panic-rtt-target = { version = "0.1", features = ["cortex-m"] }
|
panic-rtt-target = { version = "0.1", features = ["cortex-m"] }
|
||||||
rtt-target = { version = "0.3", features = ["cortex-m"] }
|
rtt-target = { version = "0.3", features = ["cortex-m"] }
|
||||||
panic-halt = "0.2"
|
panic-halt = "0.2"
|
||||||
@ -57,3 +58,7 @@ required-features = ["rt"]
|
|||||||
[[example]]
|
[[example]]
|
||||||
name = "cascade"
|
name = "cascade"
|
||||||
required-features = ["rt"]
|
required-features = ["rt"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "uart-irq-rtic"
|
||||||
|
required-features = ["rt"]
|
||||||
|
29
examples/rtic-empty.rs
Normal file
29
examples/rtic-empty.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
//! Empty RTIC project template
|
||||||
|
#![no_main]
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
#[rtic::app(device = pac)]
|
||||||
|
mod app {
|
||||||
|
use panic_rtt_target as _;
|
||||||
|
use rtt_target::{rprintln, rtt_init_default};
|
||||||
|
use va108xx_hal::pac;
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[init]
|
||||||
|
fn init(_ctx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
|
rtt_init_default!();
|
||||||
|
rprintln!("-- Vorago RTIC template --");
|
||||||
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
|
}
|
||||||
|
|
||||||
|
// `shared` cannot be accessed from this context
|
||||||
|
#[idle]
|
||||||
|
fn idle(_cx: idle::Context) -> ! {
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
}
|
64
examples/uart-irq-rtic.rs
Normal file
64
examples/uart-irq-rtic.rs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
//! UART example application. Sends a test string over a UART and then enters
|
||||||
|
//! echo mode
|
||||||
|
#![no_main]
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
#[rtic::app(device = pac)]
|
||||||
|
mod app {
|
||||||
|
use core::fmt::Write;
|
||||||
|
use panic_rtt_target as _;
|
||||||
|
use rtt_target::{rprintln, rtt_init_print};
|
||||||
|
use va108xx_hal::{gpio::PinsB, pac, prelude::*, uart};
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[init]
|
||||||
|
fn init(_ctx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
|
rtt_init_print!();
|
||||||
|
rprintln!("-- VA108xx UART example application--");
|
||||||
|
|
||||||
|
let mut dp = pac::Peripherals::take().unwrap();
|
||||||
|
|
||||||
|
let gpiob = PinsB::new(&mut dp.SYSCONFIG, Some(dp.IOCONFIG), dp.PORTB);
|
||||||
|
let tx = gpiob.pb21.into_funsel_1();
|
||||||
|
let rx = gpiob.pb20.into_funsel_1();
|
||||||
|
|
||||||
|
let uartb = uart::Uart::uartb(
|
||||||
|
dp.UARTB,
|
||||||
|
(tx, rx),
|
||||||
|
115200.bps(),
|
||||||
|
&mut dp.SYSCONFIG,
|
||||||
|
50.mhz(),
|
||||||
|
);
|
||||||
|
let (mut tx, mut _rx) = uartb.split();
|
||||||
|
writeln!(tx, "Hello World\r").unwrap();
|
||||||
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
|
}
|
||||||
|
|
||||||
|
// `shared` cannot be accessed from this context
|
||||||
|
#[idle]
|
||||||
|
fn idle(_cx: idle::Context) -> ! {
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// #[entry]
|
||||||
|
// fn main() -> ! {
|
||||||
|
|
||||||
|
// loop {
|
||||||
|
// // Echo what is received on the serial link.
|
||||||
|
// match rx.read() {
|
||||||
|
// Ok(recv) => {
|
||||||
|
// nb::block!(tx.write(recv)).expect("TX send error");
|
||||||
|
// }
|
||||||
|
// Err(nb::Error::WouldBlock) => (),
|
||||||
|
// Err(nb::Error::Other(uart_error)) => {
|
||||||
|
// rprintln!("UART receive error {:?}", uart_error);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
@ -1,44 +0,0 @@
|
|||||||
//! UART example application. Sends a test string over a UART and then enters
|
|
||||||
//! echo mode
|
|
||||||
#![no_main]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
use core::fmt::Write;
|
|
||||||
use cortex_m_rt::entry;
|
|
||||||
use panic_rtt_target as _;
|
|
||||||
use rtt_target::{rprintln, rtt_init_print};
|
|
||||||
use va108xx_hal::{gpio::PinsB, pac, prelude::*, uart};
|
|
||||||
|
|
||||||
#[entry]
|
|
||||||
fn main() -> ! {
|
|
||||||
rtt_init_print!();
|
|
||||||
rprintln!("-- VA108xx UART example application--");
|
|
||||||
|
|
||||||
let mut dp = pac::Peripherals::take().unwrap();
|
|
||||||
|
|
||||||
let gpiob = PinsB::new(&mut dp.SYSCONFIG, Some(dp.IOCONFIG), dp.PORTB);
|
|
||||||
let tx = gpiob.pb21.into_funsel_1();
|
|
||||||
let rx = gpiob.pb20.into_funsel_1();
|
|
||||||
|
|
||||||
let uartb = uart::Uart::uartb(
|
|
||||||
dp.UARTB,
|
|
||||||
(tx, rx),
|
|
||||||
115200.bps(),
|
|
||||||
&mut dp.SYSCONFIG,
|
|
||||||
50.mhz(),
|
|
||||||
);
|
|
||||||
let (mut tx, mut rx) = uartb.split();
|
|
||||||
writeln!(tx, "Hello World\r").unwrap();
|
|
||||||
loop {
|
|
||||||
// Echo what is received on the serial link.
|
|
||||||
match rx.read() {
|
|
||||||
Ok(recv) => {
|
|
||||||
nb::block!(tx.write(recv)).expect("TX send error");
|
|
||||||
}
|
|
||||||
Err(nb::Error::WouldBlock) => (),
|
|
||||||
Err(nb::Error::Other(uart_error)) => {
|
|
||||||
rprintln!("UART receive error {:?}", uart_error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user