diff --git a/README.md b/README.md index 71d1fd2d..2507b795 100644 --- a/README.md +++ b/README.md @@ -63,26 +63,27 @@ dual licensed as above, without any additional terms or conditions. Here follows a brief description of each demo for quick reference. For a more in-depth explanation on how the peripherals work please refer to the device reference manuals linked above, the readme for each demo and the comments in the demo code itself. -| Demo | Category | Description | -|-------------------------------------------------------|-------------------|-----------------------------------------------------------------------| -| [blinky-button-demo](./examples/blinky-button-demo/README.md) | Hello World | Blinky button demo | -| [ccm-demo](./examples/ccm-demo/README.md) | Encryption | Cipher block chaining - message authentication code (CCM) mode demo | -| [comp-demo](./examples/comp-demo/README.md) | Analog Pins | Voltage comparator peripheral demo | -| [ecb-demo](./examples/ecb-demo/README.md) | Encryption | AES electronic codebook mode encryption demo | -| [gpiote-demo](./examples/gpiote-demo/README.md) | Digital Pins | General-Purpose Input Output Tasks and Events module demo | -| [i2s-controller-demo](./examples/i2s-controller-demo/README.md)| Audio | Inter-IC Sound interface "controller mode (aka master mode)" demo | -| [i2s-peripheral-demo](./examples/i2s-peripheral-demo/README.md)| Audio | Inter-IC Sound interface "peripheral mode (aka slave mode)" demo | -| [lpcomp-demo](./examples/lpcomp-demo/README.md) | Analog Pins | Low power voltage comparator demo | -| [ppi-demo](./examples/ppi-demo/README.md) | Channels | Programmable peripheral interconnect (PPI) demo | -| [pwm-demo](./examples/pwm-demo/README.md) | Digital Pins | Pulse width modulation demo | -| [qdec-demo](./examples/qdec-demo/README.md) | Sensor Decoding | Quadrature sensor decoder (QDEC) demo | -| [rtic-demo](./examples/rtic-demo/README.md) | Framework | The Real-Time Interrupt-driven Concurrency framework demo | -| [spi-demo](./examples/spi-demo/README.md) | Digital Pins | Serial peripheral interface master (SPIM) with EasyDMA demo | -| [spis-demo](./examples/spis-demo/README.md) | Digital Pins | Serial peripheral interface slave (SPIS) demo | -| [twi-ssd1306](./examples/twi-ssd1306/README.md) | Digital Pins | I2C compatible Two-Wire Interface with the SSD1306 OLED Display demo | -| [twim-demo](./examples/twim-demo/README.md) | Digital Pins | I2C compatible Two-Wire Interface Master mode demo | -| [twis-demo](./examples/twis-demo/README.md) | Digital Pins | I2C compatible Two-Wire Interface Slave mode demo | -| [wdt-demo](./examples/wdt-demo/README.md) | Timer | Watchdog timer demo | +| Demo | Category | Description | +|---------------------------------------------------------------------|-------------------|-----------------------------------------------------------------------| +| [blinky-button-demo](./examples/blinky-button-demo/README.md) | Hello World | Blinky button demo | +| [ccm-demo](./examples/ccm-demo/README.md) | Encryption | Cipher block chaining - message authentication code (CCM) mode demo | +| [comp-demo](./examples/comp-demo/README.md) | Analog Pins | Voltage comparator peripheral demo | +| [ecb-demo](./examples/ecb-demo/README.md) | Encryption | AES electronic codebook mode encryption demo | +| [gpiote-demo](./examples/gpiote-demo/README.md) | Digital Pins | General-Purpose Input Output Tasks and Events module demo | +| [i2s-controller-demo](./examples/i2s-controller-demo/README.md) | Audio | Inter-IC Sound interface "controller mode (aka master mode)" demo | +| [i2s-peripheral-demo](./examples/i2s-peripheral-demo/README.md) | Audio | Inter-IC Sound interface "peripheral mode (aka slave mode)" demo | +| [lpcomp-demo](./examples/lpcomp-demo/README.md) | Analog Pins | Low power voltage comparator demo | +| [ppi-demo](./examples/ppi-demo/README.md) | Channels | Programmable peripheral interconnect (PPI) demo | +| [pwm-demo](./examples/pwm-demo/README.md) | Digital Pins | Pulse width modulation demo | +| [qdec-demo](./examples/qdec-demo/README.md) | Sensor Decoding | Quadrature sensor decoder (QDEC) demo | +| [rtic-demo](./examples/rtic-demo/README.md) | Framework | The Real-Time Interrupt-driven Concurrency framework demo | +| [rtic-serial-interrupt](./examples/rtic-serial-interrupt/README.md) | Interrupt | Register for UARTE0 interrupt with RTIC | +| [spi-demo](./examples/spi-demo/README.md) | Digital Pins | Serial peripheral interface master (SPIM) with EasyDMA demo | +| [spis-demo](./examples/spis-demo/README.md) | Digital Pins | Serial peripheral interface slave (SPIS) demo | +| [twi-ssd1306](./examples/twi-ssd1306/README.md) | Digital Pins | I2C compatible Two-Wire Interface with the SSD1306 OLED Display demo | +| [twim-demo](./examples/twim-demo/README.md) | Digital Pins | I2C compatible Two-Wire Interface Master mode demo | +| [twis-demo](./examples/twis-demo/README.md) | Digital Pins | I2C compatible Two-Wire Interface Slave mode demo | +| [wdt-demo](./examples/wdt-demo/README.md) | Timer | Watchdog timer demo | ## Running the Examples diff --git a/examples/rtic-serial-interrupt/.cargo/config b/examples/rtic-serial-interrupt/.cargo/config new file mode 100644 index 00000000..90b5200a --- /dev/null +++ b/examples/rtic-serial-interrupt/.cargo/config @@ -0,0 +1,2 @@ +[target.thumbv7em-none-eabihf] +runner = "arm-none-eabi-gdb -tui" diff --git a/examples/rtic-serial-interrupt/.gdbinit b/examples/rtic-serial-interrupt/.gdbinit new file mode 100644 index 00000000..ec068055 --- /dev/null +++ b/examples/rtic-serial-interrupt/.gdbinit @@ -0,0 +1,10 @@ +set remotetimeout 60000 +target remote :2331 +set arm force-mode thumb + +# Uncomment to enable semihosting, when necessary +monitor semihosting enable + +layout split +monitor reset +load diff --git a/examples/rtic-serial-interrupt/Cargo.toml b/examples/rtic-serial-interrupt/Cargo.toml new file mode 100644 index 00000000..ea468007 --- /dev/null +++ b/examples/rtic-serial-interrupt/Cargo.toml @@ -0,0 +1,45 @@ +[package] +name = "rtic-serial-interrupt" +version = "0.1.0" +authors = ["René Rössler "] +edition = "2018" +publish = false + +[dependencies] +cortex-m-rtic = { version = "0.5.9", default-features = false, features = [ + "cortex-m-7", +] } +panic-semihosting = "0.5.3" +cortex-m-semihosting = "0.3.5" + +[dependencies.nrf51-hal] +path = "../../nrf51-hal" +optional = true + +[dependencies.nrf52810-hal] +path = "../../nrf52810-hal" +optional = true + +[dependencies.nrf52811-hal] +path = "../../nrf52811-hal" +optional = true + +[dependencies.nrf52832-hal] +path = "../../nrf52832-hal" +optional = true + +[dependencies.nrf52833-hal] +path = "../../nrf52833-hal" +optional = true + +[dependencies.nrf52840-hal] +path = "../../nrf52840-hal" +optional = true + +[features] +51 = ["nrf51-hal"] +52810 = ["nrf52810-hal"] +52811 = ["nrf52811-hal"] +52832 = ["nrf52832-hal"] +52833 = ["nrf52833-hal"] +52840 = ["nrf52840-hal"] diff --git a/examples/rtic-serial-interrupt/README.md b/examples/rtic-serial-interrupt/README.md new file mode 100644 index 00000000..5b62b58a --- /dev/null +++ b/examples/rtic-serial-interrupt/README.md @@ -0,0 +1,3 @@ +# RTIC serial interrupt + +Receive an interrupt on serial input. Uses RTIC. \ No newline at end of file diff --git a/examples/rtic-serial-interrupt/src/main.rs b/examples/rtic-serial-interrupt/src/main.rs new file mode 100644 index 00000000..b1999b09 --- /dev/null +++ b/examples/rtic-serial-interrupt/src/main.rs @@ -0,0 +1,80 @@ +#![no_main] +#![no_std] + +#[allow(unused_imports)] +use panic_semihosting; + +use cortex_m_semihosting::hprintln; +use rtic::app; + +#[cfg(feature = "51")] +use nrf51_hal as hal; + +#[cfg(feature = "52810")] +use nrf52810_hal as hal; + +#[cfg(feature = "52811")] +use nrf52811_hal as hal; + +#[cfg(feature = "52832")] +use nrf52832_hal as hal; + +#[cfg(feature = "52833")] +use nrf52833_hal as hal; + +#[cfg(feature = "52840")] +use nrf52840_hal as hal; + +use crate::hal::{ + gpio::{p0, Level}, + pac::{Interrupt::UARTE0_UART0, UARTE0}, + prelude::_embedded_hal_serial_Read, + uarte::{self, UarteRx}, +}; + +#[app(device = crate::hal::pac, peripherals = true)] +const APP: () = { + struct Resources { + serial0: UarteRx, + } + + #[init] + fn init(cx: init::Context) -> init::LateResources { + let p = cx.device; + let p0parts = p0::Parts::new(p.P0); + + // enable UARTE0 endrx interrupt + p.UARTE0.intenset.modify(|_, w| w.endrx().set_bit()); + + static mut SERIAL0_TX_BUF: [u8; 1] = [0; 1]; + static mut SERIAL0_RX_BUF: [u8; 1] = [0; 1]; + let (_, serial0) = uarte::Uarte::new( + p.UARTE0, + uarte::Pins { + txd: p0parts.p0_00.into_push_pull_output(Level::High).degrade(), + rxd: p0parts.p0_01.into_floating_input().degrade(), + cts: None, + rts: None, + }, + uarte::Parity::EXCLUDED, + uarte::Baudrate::BAUD115200, + ) + .split(unsafe { &mut SERIAL0_TX_BUF }, unsafe { + &mut SERIAL0_RX_BUF + }) + .expect("Could not split serial0"); + + // on NRF* serial interrupts are only called after the first read + rtic::pend(UARTE0_UART0); + + init::LateResources { serial0 } + } + + #[task(binds = UARTE0_UART0, resources = [serial0])] + fn uarte0_interrupt(cx: uarte0_interrupt::Context) { + hprintln!("uarte0 interrupt"); + while let Ok(b) = cx.resources.serial0.read() { + hprintln!("Byte on serial0: {}", b); + } + } +};