Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rtic serial interrupt example #363

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions examples/rtic-serial-interrupt/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.thumbv7em-none-eabihf]
runner = "arm-none-eabi-gdb -tui"
10 changes: 10 additions & 0 deletions examples/rtic-serial-interrupt/.gdbinit
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions examples/rtic-serial-interrupt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
name = "rtic-serial-interrupt"
version = "0.1.0"
authors = ["René Rössler <rene@freshx.de>"]
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"]
3 changes: 3 additions & 0 deletions examples/rtic-serial-interrupt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# RTIC serial interrupt

Receive an interrupt on serial input. Uses RTIC.
80 changes: 80 additions & 0 deletions examples/rtic-serial-interrupt/src/main.rs
Original file line number Diff line number Diff line change
@@ -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<UARTE0>,
}

#[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);
}
}
};