diff --git a/examples/blinky-await.rs b/examples/blinky-await.rs
index 84b200c7478e923b3a7018c7e3bd6fdc707fd9a7..5ce6fbfa03da2a7f48bdfebea572f98caa8b934a 100644
--- a/examples/blinky-await.rs
+++ b/examples/blinky-await.rs
@@ -1,6 +1,7 @@
 //! Blinky using `await!`
 
 #![allow(unreachable_code)] // for the `await!` macro
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(const_fn)]
 #![feature(used)]
diff --git a/examples/blinky-blocking.rs b/examples/blinky-blocking.rs
index 048caa409ae720e7198ff50fe713aa5edebbb110..8f581601935538d8254b286c76dbd2d137097b7b 100644
--- a/examples/blinky-blocking.rs
+++ b/examples/blinky-blocking.rs
@@ -1,6 +1,7 @@
 //! Blocking version of blinky
 
 #![allow(unreachable_code)] // for the `block!` macro
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(const_fn)]
 #![feature(used)]
diff --git a/examples/blinky-futures.rs b/examples/blinky-futures.rs
index ada6e4e156312edf8e0a39129f14d34716c2d678..3d9e2353e8b60e5894481755e6c5bb4e860afc68 100644
--- a/examples/blinky-futures.rs
+++ b/examples/blinky-futures.rs
@@ -1,6 +1,7 @@
 //! Blinky using futures
 
 #![allow(unreachable_code)] // for the `try_nb!` macro
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(const_fn)]
 #![feature(used)]
diff --git a/examples/blinky.rs b/examples/blinky.rs
index baaa52c340a4904a062c786deb6ef8a68b8571ed..ad3e749f02bea220152fe2e70b4f6f28a6eba26f 100644
--- a/examples/blinky.rs
+++ b/examples/blinky.rs
@@ -1,6 +1,8 @@
 //! Blinks the user LED
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
+#![feature(const_fn)]
 #![feature(proc_macro)]
 #![no_std]
 
@@ -42,14 +44,14 @@ fn idle() -> ! {
 }
 
 // TASKS
-task!(SYS_TICK, blink, Local {
-    state: bool = false;
+task!(SYS_TICK, blink, Locals {
+    static STATE: bool = false;
 });
 
-fn blink(_t: Threshold, l: &mut Local, _r: SYS_TICK::Resources) {
-    l.state = !l.state;
+fn blink(_t: &mut Threshold, l: &mut Locals, _r: SYS_TICK::Resources) {
+    *l.STATE = !*l.STATE;
 
-    if l.state {
+    if *l.STATE {
         Green.on();
     } else {
         Green.off();
diff --git a/examples/capture1.rs b/examples/capture1.rs
index be63206585153a1a8e7786c9844f0977bb0a88af..00ec6e7ddb29d0c5ba8f2ae089599df219d7505f 100644
--- a/examples/capture1.rs
+++ b/examples/capture1.rs
@@ -1,5 +1,6 @@
 //! Input capture using TIM1
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
@@ -36,7 +37,7 @@ fn idle(r: idle::Resources) -> ! {
     const CHANNELS: [Channel; 4] =
         [Channel::_1, Channel::_2, Channel::_3, Channel::_4];
 
-    let capture = Capture(r.TIM1);
+    let capture = Capture(&**r.TIM1);
 
     for c in &CHANNELS {
         capture.enable(*c);
diff --git a/examples/capture2.rs b/examples/capture2.rs
index e81137f9d4fbb42f4eee307e989055f15728af2c..f3936e5b89189df7643f338c897676e0cedab407 100644
--- a/examples/capture2.rs
+++ b/examples/capture2.rs
@@ -1,5 +1,6 @@
 //! Input capture using TIM2
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
@@ -36,7 +37,7 @@ fn idle(r: idle::Resources) -> ! {
     const CHANNELS: [Channel; 4] =
         [Channel::_1, Channel::_2, Channel::_3, Channel::_4];
 
-    let capture = Capture(r.TIM2);
+    let capture = Capture(&**r.TIM2);
 
     for c in &CHANNELS {
         capture.enable(*c);
diff --git a/examples/capture3.rs b/examples/capture3.rs
index e806202002933926ee3e0aaaf22ebe467a4c842e..835d0af302fe8e8563de5d7f49661c47b17daf4a 100644
--- a/examples/capture3.rs
+++ b/examples/capture3.rs
@@ -1,5 +1,6 @@
 //! Input capture using TIM3
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
@@ -35,7 +36,7 @@ fn init(p: init::Peripherals) {
 fn idle(r: idle::Resources) -> ! {
     const CHANNELS: [Channel; 2] = [Channel::_1, Channel::_2];
 
-    let capture = Capture(r.TIM3);
+    let capture = Capture(&**r.TIM3);
 
     for c in &CHANNELS {
         capture.enable(*c);
diff --git a/examples/capture4.rs b/examples/capture4.rs
index 2074c9662a747504739a682493e5bcd8a62cb86d..b156b6cb49caa84a331ddc520fb2f0341a401c25 100644
--- a/examples/capture4.rs
+++ b/examples/capture4.rs
@@ -1,5 +1,6 @@
 //! Input capture using TIM4
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
@@ -36,7 +37,7 @@ fn idle(r: idle::Resources) -> ! {
     const CHANNELS: [Channel; 4] =
         [Channel::_1, Channel::_2, Channel::_3, Channel::_4];
 
-    let capture = Capture(r.TIM4);
+    let capture = Capture(&**r.TIM4);
 
     for c in &CHANNELS {
         capture.enable(*c);
diff --git a/examples/concurrent-await.rs b/examples/concurrent-await.rs
index 991c76c1ea4973db434c5b367e87e6ed461d8ea7..1bed02101deec040bbc838a0c7bdeddf5a6cdf30 100644
--- a/examples/concurrent-await.rs
+++ b/examples/concurrent-await.rs
@@ -1,6 +1,7 @@
 //! Two concurrent tasks using `await!`
 
 #![allow(unreachable_code)] // for the `await!` macro
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(const_fn)]
 #![feature(used)]
diff --git a/examples/concurrent-futures.rs b/examples/concurrent-futures.rs
index fad6df95dfa52d90960e316fb74a93295f1ac238..f95960804e32fe31324974ee6367ec74e86ec944 100644
--- a/examples/concurrent-futures.rs
+++ b/examples/concurrent-futures.rs
@@ -1,6 +1,7 @@
 //! Two concurrent tasks using futures
 
 #![allow(unreachable_code)] // for the `try_nb!` macro
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(const_fn)]
 #![feature(used)]
diff --git a/examples/concurrent.rs b/examples/concurrent.rs
index 004a2196867ea45a8afdb476525da5e5c131af24..28dffaebe026054700e61c33a3762f27aebd8de2 100644
--- a/examples/concurrent.rs
+++ b/examples/concurrent.rs
@@ -1,6 +1,8 @@
 //! Serial loopback
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
+#![feature(const_fn)]
 #![feature(proc_macro)]
 #![no_std]
 
@@ -14,7 +16,7 @@ use blue_pill::prelude::*;
 use blue_pill::serial::Event;
 use blue_pill::time::Hertz;
 use blue_pill::{Serial, Timer, stm32f103xx};
-use rtfm::{Threshold, app};
+use rtfm::{app, Threshold};
 
 app! {
     device: stm32f103xx,
@@ -62,17 +64,17 @@ fn idle() -> ! {
 
 // TASKS
 task!(TIM2, blinky, Local {
-    state: bool = false;
+    static STATE: bool = false;
 });
 
-fn blinky(_t: Threshold, l: &mut Local, r: TIM2::Resources) {
-    let timer = Timer(r.TIM2);
+fn blinky(_t: &mut Threshold, l: &mut Local, r: TIM2::Resources) {
+    let timer = Timer(&**r.TIM2);
 
     timer.wait().unwrap();
 
-    l.state = !l.state;
+    *l.STATE = !*l.STATE;
 
-    if l.state {
+    if *l.STATE {
         Green.on();
     } else {
         Green.off();
@@ -81,8 +83,8 @@ fn blinky(_t: Threshold, l: &mut Local, r: TIM2::Resources) {
 
 task!(USART1, loopback);
 
-fn loopback(_t: Threshold, r: USART1::Resources) {
-    let serial = Serial(r.USART1);
+fn loopback(_t: &mut Threshold, r: USART1::Resources) {
+    let serial = Serial(&**r.USART1);
 
     let byte = serial.read().unwrap();
     serial.write(byte).unwrap();
diff --git a/examples/cpu.rs b/examples/cpu.rs
index d7804c3692e183c9897ff5d511f65f6d880d3183..b81ef4ed6aa0b409b3404e9a5db1057239230ebc 100644
--- a/examples/cpu.rs
+++ b/examples/cpu.rs
@@ -1,5 +1,6 @@
 //! CPU usage monitor
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(const_fn)]
 #![feature(proc_macro)]
@@ -17,13 +18,13 @@ use blue_pill::Timer;
 use blue_pill::stm32f103xx;
 use blue_pill::time::Hertz;
 use blue_pill::prelude::*;
-use rtfm::{Threshold, app};
+use rtfm::{app, Resource, Threshold};
 
 app! {
     device: stm32f103xx,
 
     resources: {
-        SLEEP_TIME: u32 = 0;
+        static SLEEP_TIME: u32 = 0;
     },
 
     idle: {
@@ -53,7 +54,7 @@ fn init(p: init::Peripherals, _r: init::Resources) {
 }
 
 // IDLE LOOP
-fn idle(_t: Threshold, mut r: idle::Resources) -> ! {
+fn idle(_t: &mut Threshold, mut r: idle::Resources) -> ! {
     loop {
         // For the span of this critical section the processor will not service
         // interrupts (tasks)
@@ -77,8 +78,8 @@ fn idle(_t: Threshold, mut r: idle::Resources) -> ! {
 
 task!(TIM2, periodic);
 
-fn periodic(_t: Threshold, r: TIM2::Resources) {
-    let timer = Timer(r.TIM2);
+fn periodic(_t: &mut Threshold, r: TIM2::Resources) {
+    let timer = Timer(&**r.TIM2);
 
     timer.wait().unwrap();
 
diff --git a/examples/gpio.rs b/examples/gpio.rs
index c9d434826a0f2b4e190e97b48e3c31c6aebc57d9..0b5a5b31d20190a4d78f9aba26132f95b40adc0a 100644
--- a/examples/gpio.rs
+++ b/examples/gpio.rs
@@ -1,5 +1,6 @@
 //! Sets PB12 high
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
diff --git a/examples/hello.rs b/examples/hello.rs
index 27d3e35238d921501ecb52642a90b40e39bc8003..f2c0938c400f26d6f29d91fba7fd5c2d67c91e90 100644
--- a/examples/hello.rs
+++ b/examples/hello.rs
@@ -1,5 +1,6 @@
 //! Prints "Hello" and then "World" on the OpenOCD console
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(const_fn)]
 #![feature(proc_macro)]
@@ -19,7 +20,7 @@ app! {
     device: blue_pill::stm32f103xx,
 
     resources: {
-        HSTDOUT: Option<HStdout> = None;
+        static HSTDOUT: Option<HStdout> = None;
     },
 
     idle: {
diff --git a/examples/itm.rs b/examples/itm.rs
index 76dc7b9973c775cf2c31049020430a3a8246911b..9c31f71e6636f54242942b38d1777b9c24203d7f 100644
--- a/examples/itm.rs
+++ b/examples/itm.rs
@@ -19,6 +19,7 @@
 //! World
 //! ```
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
diff --git a/examples/led.rs b/examples/led.rs
index 1e8b552222a1cc92c6b577e807b4aac9e6f440cd..64143f46a4c87c7b7284ddd6f28fa09f37a35a3c 100644
--- a/examples/led.rs
+++ b/examples/led.rs
@@ -1,5 +1,6 @@
 //! Turns the user LED on
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
diff --git a/examples/loopback.rs b/examples/loopback.rs
index a2981d912f4b52b1237fe8d1642f67a7c26ab8e3..6e19cf2c180dce5ceba6811a451c846b7663dea8 100644
--- a/examples/loopback.rs
+++ b/examples/loopback.rs
@@ -1,5 +1,6 @@
 //! Serial loopback via USART1
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
@@ -12,7 +13,7 @@ use blue_pill::Serial;
 use blue_pill::prelude::*;
 use blue_pill::serial::Event;
 use blue_pill::time::Hertz;
-use rtfm::{Threshold, app};
+use rtfm::{app, Threshold};
 
 // CONFIGURATION
 pub const BAUD_RATE: Hertz = Hertz(115_200);
@@ -44,8 +45,8 @@ fn idle() -> ! {
 
 task!(USART1, loopback);
 
-fn loopback(_t: Threshold, r: USART1::Resources) {
-    let serial = Serial(r.USART1);
+fn loopback(_t: &mut Threshold, r: USART1::Resources) {
+    let serial = Serial(&**r.USART1);
 
     let byte = serial.read().unwrap();
     serial.write(byte).unwrap();
diff --git a/examples/pwm-control.rs b/examples/pwm-control.rs
index 4b92475d34f583d23be3556d28d72074da9213f1..70ba754a92fdb6aed33236976adeaf53f80a44f2 100644
--- a/examples/pwm-control.rs
+++ b/examples/pwm-control.rs
@@ -5,6 +5,7 @@
 //! - '-' decrease duty by 1
 //! - '/' decrease duty by a factor of 2
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
@@ -18,7 +19,7 @@ use core::u16;
 use blue_pill::prelude::*;
 use blue_pill::time::Hertz;
 use blue_pill::{Channel, Pwm, Serial};
-use rtfm::{Threshold, app};
+use rtfm::{app, Threshold};
 
 const BAUD_RATE: Hertz = Hertz(115_200);
 const FREQUENCY: Hertz = Hertz(1_000);
@@ -55,9 +56,9 @@ fn idle() -> ! {
 
 task!(USART1, rx);
 
-fn rx(_t: Threshold, r: USART1::Resources) {
-    let pwm = Pwm(r.TIM2);
-    let serial = Serial(r.USART1);
+fn rx(_t: &mut Threshold, r: USART1::Resources) {
+    let pwm = Pwm(&**r.TIM2);
+    let serial = Serial(&**r.USART1);
 
     let byte = serial.read().unwrap();
     // Echo back to signal we are alive
diff --git a/examples/pwm1.rs b/examples/pwm1.rs
index 27f89e255aca01de1654791715166ffccefa9455..60d520cb8598a045597e87ba3e8df53b127ff8a8 100644
--- a/examples/pwm1.rs
+++ b/examples/pwm1.rs
@@ -1,6 +1,7 @@
 //! Output a PWM with a duty cycle of ~6% on all the channels of TIM1
 // FIXME doesn't seem to work :-(
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
diff --git a/examples/pwm2.rs b/examples/pwm2.rs
index b90b7c6b45859b19be00b2211183e708593707a5..5b6773fc5bd4b3b46ce0f88f680496ad80aac555 100644
--- a/examples/pwm2.rs
+++ b/examples/pwm2.rs
@@ -1,5 +1,6 @@
 //! Output a PWM with a duty cycle of ~6% on all the channels of TIM2
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
diff --git a/examples/pwm3.rs b/examples/pwm3.rs
index 514945b946ca4a50f79a3263f3f278990649e899..a5ddfed67cd9f8d14dbd20e395951ac0957e6a4d 100644
--- a/examples/pwm3.rs
+++ b/examples/pwm3.rs
@@ -1,5 +1,6 @@
 //! Output a PWM with a duty cycle of ~6% on all the channels of TIM3
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
diff --git a/examples/pwm4.rs b/examples/pwm4.rs
index c32ecb2cf70e5fed27b6cb42d05b5e569bda84ba..c5d6b7fb073852337d60c1fef6dcad9cf3a22516 100644
--- a/examples/pwm4.rs
+++ b/examples/pwm4.rs
@@ -1,5 +1,6 @@
 //! Output a PWM with a duty cycle of ~6% on all the channels of TIM4
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
diff --git a/examples/qei1.rs b/examples/qei1.rs
index 203c681862e3a5939084e8094292abb97e4c7566..ba49f09d320458f62b02a492628adbc861d6b697 100644
--- a/examples/qei1.rs
+++ b/examples/qei1.rs
@@ -2,7 +2,9 @@
 //!
 //! Periodically reports the readings of the QEI
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
+#![feature(const_fn)]
 #![feature(proc_macro)]
 #![no_std]
 
@@ -15,7 +17,7 @@ extern crate cortex_m_rtfm as rtfm;
 use blue_pill::prelude::*;
 use blue_pill::time::Hertz;
 use blue_pill::{Qei, Timer};
-use rtfm::{Threshold, app};
+use rtfm::{app, Threshold};
 
 // CONFIGURATION
 const FREQUENCY: Hertz = Hertz(1);
@@ -49,24 +51,23 @@ fn idle() -> ! {
 }
 
 task!(TIM4, periodic, Locals {
-    previous: Option<u16> = None;
+    static PREVIOUS: Option<u16> = None;
 });
 
-fn periodic(_t: Threshold, l: &mut Locals, r: TIM4::Resources) {
-    let qei = Qei(r.TIM1);
-    let timer = Timer(r.TIM4);
+fn periodic(_t: &mut Threshold, l: &mut Locals, r: TIM4::Resources) {
+    let qei = Qei(&**r.TIM1);
+    let timer = Timer(&**r.TIM4);
 
-    // NOTE(unwrap) timeout should have already occurred
-    timer.wait().unwrap_or_else(|_| unreachable!());
+    timer.wait().unwrap();
 
     let curr = qei.count();
     let dir = qei.direction();
 
-    if let Some(prev) = l.previous.take() {
+    if let Some(prev) = l.PREVIOUS.take() {
         let speed = (curr as i16).wrapping_sub(prev as i16);
 
         iprintln!(&r.ITM.stim[0], "{} - {} - {:?}", curr, speed, dir);
     }
 
-    l.previous = Some(curr);
+    *l.PREVIOUS = Some(curr);
 }
diff --git a/examples/qei2.rs b/examples/qei2.rs
index 701f8fa8e835b827e4f8fa47ff7251292d30f8ad..edba974778b0ac3741c70af67580111bbe52856e 100644
--- a/examples/qei2.rs
+++ b/examples/qei2.rs
@@ -2,7 +2,9 @@
 //!
 //! Periodically reports the readings of the QEI
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
+#![feature(const_fn)]
 #![feature(proc_macro)]
 #![no_std]
 
@@ -15,7 +17,7 @@ extern crate cortex_m_rtfm as rtfm;
 use blue_pill::prelude::*;
 use blue_pill::time::Hertz;
 use blue_pill::{Qei, Timer};
-use rtfm::{Threshold, app};
+use rtfm::{app, Threshold};
 
 const FREQUENCY: Hertz = Hertz(1);
 
@@ -48,12 +50,12 @@ fn idle() -> ! {
 }
 
 task!(TIM4, periodic, Locals {
-    previous: Option<u16> = None;
+    static PREVIOUS: Option<u16> = None;
 });
 
-fn periodic(_t: Threshold, l: &mut Locals, r: TIM4::Resources) {
-    let qei = Qei(r.TIM2);
-    let timer = Timer(r.TIM4);
+fn periodic(_t: &mut Threshold, l: &mut Locals, r: TIM4::Resources) {
+    let qei = Qei(&**r.TIM2);
+    let timer = Timer(&**r.TIM4);
 
     // NOTE(unwrap) timeout should have already occurred
     timer.wait().unwrap();
@@ -61,11 +63,11 @@ fn periodic(_t: Threshold, l: &mut Locals, r: TIM4::Resources) {
     let curr = qei.count();
     let dir = qei.direction();
 
-    if let Some(prev) = l.previous.take() {
+    if let Some(prev) = l.PREVIOUS.take() {
         let speed = (curr as i16).wrapping_sub(prev as i16);
 
         iprintln!(&r.ITM.stim[0], "{} - {} - {:?}", curr, speed, dir);
     }
 
-    l.previous = Some(curr);
+    *l.PREVIOUS = Some(curr);
 }
diff --git a/examples/qei3.rs b/examples/qei3.rs
index 5a28a921ccdb36eaece8c1200b01936580cc567d..e0ed7dec48435f0179598972c2a17dba86e5c0ae 100644
--- a/examples/qei3.rs
+++ b/examples/qei3.rs
@@ -2,7 +2,9 @@
 //!
 //! Periodically reports the readings of the QEI
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
+#![feature(const_fn)]
 #![feature(proc_macro)]
 #![no_std]
 
@@ -15,7 +17,7 @@ extern crate cortex_m_rtfm as rtfm;
 use blue_pill::time::Hertz;
 use blue_pill::{Qei, Timer};
 use blue_pill::prelude::*;
-use rtfm::{Threshold, app};
+use rtfm::{app, Threshold};
 
 const FREQUENCY: Hertz = Hertz(1);
 
@@ -48,23 +50,23 @@ fn idle() -> ! {
 }
 
 task!(TIM4, periodic, Locals {
-    previous: Option<u16> = None;
+    static PREVIOUS: Option<u16> = None;
 });
 
-fn periodic(_t: Threshold, l: &mut Locals, r: TIM4::Resources) {
-    let qei = Qei(r.TIM3);
-    let timer = Timer(r.TIM4);
+fn periodic(_t: &mut Threshold, l: &mut Locals, r: TIM4::Resources) {
+    let qei = Qei(&**r.TIM3);
+    let timer = Timer(&**r.TIM4);
 
     timer.wait().unwrap();
 
     let curr = qei.count();
     let dir = qei.direction();
 
-    if let Some(prev) = l.previous.take() {
+    if let Some(prev) = l.PREVIOUS.take() {
         let speed = (curr as i16).wrapping_sub(prev as i16);
 
         iprintln!(&r.ITM.stim[0], "{} - {} - {:?}", curr, speed, dir);
     }
 
-    l.previous = Some(curr);
+    *l.PREVIOUS = Some(curr);
 }
diff --git a/examples/qei4.rs b/examples/qei4.rs
index e5ccb7340be1524fb04924f001014c75721a80b3..b04c7eadb90a1fb422bc89c938ef7e9fc343310b 100644
--- a/examples/qei4.rs
+++ b/examples/qei4.rs
@@ -2,7 +2,9 @@
 //!
 //! Periodically reports the readings of the QEI
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
+#![feature(const_fn)]
 #![feature(proc_macro)]
 #![no_std]
 
@@ -15,7 +17,7 @@ extern crate cortex_m_rtfm as rtfm;
 use blue_pill::time::Hertz;
 use blue_pill::{Qei, Timer};
 use blue_pill::prelude::*;
-use rtfm::{Threshold, app};
+use rtfm::{app, Threshold};
 
 const FREQUENCY: Hertz = Hertz(1);
 
@@ -48,23 +50,23 @@ fn idle() -> ! {
 }
 
 task!(TIM1_UP_TIM10, periodic, Locals {
-    previous: Option<u16> = None;
+    static PREVIOUS: Option<u16> = None;
 });
 
-fn periodic(_t: Threshold, l: &mut Locals, r: TIM1_UP_TIM10::Resources) {
-    let qei = Qei(r.TIM4);
-    let timer = Timer(r.TIM1);
+fn periodic(_t: &mut Threshold, l: &mut Locals, r: TIM1_UP_TIM10::Resources) {
+    let qei = Qei(&**r.TIM4);
+    let timer = Timer(&**r.TIM1);
 
     timer.wait().unwrap();
 
     let curr = qei.count();
     let dir = qei.direction();
 
-    if let Some(prev) = l.previous.take() {
+    if let Some(prev) = l.PREVIOUS.take() {
         let speed = (curr as i16).wrapping_sub(prev as i16);
 
         iprintln!(&r.ITM.stim[0], "{} - {} - {:?}", curr, speed, dir);
     }
 
-    l.previous = Some(curr);
+    *l.PREVIOUS = Some(curr);
 }
diff --git a/examples/spi1.rs b/examples/spi1.rs
index e573a4164f451bbef9a7d68b1e96382dc7a806ef..0b8b2c6da29ccaa0325689898f9b16b3c836cd24 100644
--- a/examples/spi1.rs
+++ b/examples/spi1.rs
@@ -1,5 +1,6 @@
 //! Interfacing the MPU9250 using SPI1
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
@@ -40,7 +41,7 @@ fn idle(r: idle::Resources) -> ! {
     // Read mode
     pub const R: u8 = 1 << 7;
 
-    let spi = Spi(r.SPI1);
+    let spi = Spi(&**r.SPI1);
 
     rtfm::bkpt();
 
diff --git a/examples/spi2.rs b/examples/spi2.rs
index 47ea42cda6a20ab6756b350a1371bbd3990301a7..2f352f0337c5dcd6a0420782c18e8be359ea1817 100644
--- a/examples/spi2.rs
+++ b/examples/spi2.rs
@@ -1,5 +1,6 @@
 //! Interfacing the MPU9250 using SPI2
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
@@ -40,7 +41,7 @@ fn idle(r: idle::Resources) -> ! {
     // Read mode
     pub const R: u8 = 1 << 7;
 
-    let spi = Spi(r.SPI2);
+    let spi = Spi(&**r.SPI2);
 
     rtfm::bkpt();
 
diff --git a/examples/usart1-rx-dma.rs b/examples/usart1-rx-dma.rs
index 041a234e44f39a56d5e222fcea8c6cc7a03df75d..7f3c0b3cd88767376b0e8669ceb93057b62ff17d 100644
--- a/examples/usart1-rx-dma.rs
+++ b/examples/usart1-rx-dma.rs
@@ -1,5 +1,6 @@
 //! Test receiving serial data using the DMA
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(const_fn)]
 #![feature(proc_macro)]
@@ -13,7 +14,7 @@ extern crate nb;
 use blue_pill::Serial;
 use blue_pill::dma::{Buffer, Dma1Channel5};
 use blue_pill::time::Hertz;
-use rtfm::{Threshold, app};
+use rtfm::{app, Threshold};
 
 pub const BAUD_RATE: Hertz = Hertz(115_200);
 
@@ -21,7 +22,7 @@ app! {
     device: blue_pill::stm32f103xx,
 
     resources: {
-        BUFFER: Buffer<[u8; 8], Dma1Channel5> = Buffer::new([0; 8]);
+        static BUFFER: Buffer<[u8; 8], Dma1Channel5> = Buffer::new([0; 8]);
     },
 
     tasks: {
@@ -49,7 +50,7 @@ fn idle() -> ! {
 
 task!(DMA1_CHANNEL5, transfer_done);
 
-fn transfer_done(_t: Threshold, r: DMA1_CHANNEL5::Resources) {
+fn transfer_done(_t: &mut Threshold, r: DMA1_CHANNEL5::Resources) {
     r.BUFFER.release(r.DMA1).unwrap();
 
     rtfm::bkpt();
diff --git a/examples/usart1-tx-dma.rs b/examples/usart1-tx-dma.rs
index c5ccc3a1eaa79d5cd03b3602c2ca15da942118d3..06f209e6b5d73395b04b06598a548846c7213781 100644
--- a/examples/usart1-tx-dma.rs
+++ b/examples/usart1-tx-dma.rs
@@ -1,5 +1,6 @@
 //! Test sending serial data using the DMA
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(const_fn)]
 #![feature(proc_macro)]
@@ -13,7 +14,7 @@ extern crate nb;
 use blue_pill::Serial;
 use blue_pill::dma::{Buffer, Dma1Channel4};
 use blue_pill::time::Hertz;
-use rtfm::{Threshold, app};
+use rtfm::{app, Threshold};
 
 pub const BAUD_RATE: Hertz = Hertz(115_200);
 
@@ -21,7 +22,7 @@ app! {
     device: blue_pill::stm32f103xx,
 
     resources: {
-        BUFFER: Buffer<[u8; 14], Dma1Channel4> = Buffer::new([0; 14]);
+        static BUFFER: Buffer<[u8; 14], Dma1Channel4> = Buffer::new([0; 14]);
     },
 
     tasks: {
@@ -50,7 +51,7 @@ fn idle() -> ! {
 
 task!(DMA1_CHANNEL4, transfer_done);
 
-fn transfer_done(_t: Threshold, r: DMA1_CHANNEL4::Resources) {
+fn transfer_done(_t: &mut Threshold, r: DMA1_CHANNEL4::Resources) {
     r.BUFFER.release(r.DMA1).unwrap();
 
     rtfm::bkpt();
diff --git a/examples/usart1.rs b/examples/usart1.rs
index b4962195118d7e5016e2e6f47d498a93c57a53ea..9abd07de932e81215039213f6cbbb611b60e70dc 100644
--- a/examples/usart1.rs
+++ b/examples/usart1.rs
@@ -2,6 +2,7 @@
 //!
 //! Connect the TX and RX pins to run this test
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
diff --git a/examples/usart2.rs b/examples/usart2.rs
index 55ae04ea900ed2fa0c0283fe57cad6a4e4d0c629..2af3b2e40c89f3aa0d5a352fdc102fef351f1f0e 100644
--- a/examples/usart2.rs
+++ b/examples/usart2.rs
@@ -2,6 +2,7 @@
 //!
 //! Connect the TX and RX pins to run this test
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
diff --git a/examples/usart3.rs b/examples/usart3.rs
index 75599723c190affdbac2c21b32de67e7e7c578c2..5d5815fe55dff265064c470def7a79e3a9ba172f 100644
--- a/examples/usart3.rs
+++ b/examples/usart3.rs
@@ -2,6 +2,7 @@
 //!
 //! Connect the TX and RX pins to run this test
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
diff --git a/examples/wait1.rs b/examples/wait1.rs
index 931076931104faf511a8377609646419b78f0c4f..4b3a8118e97f33b09512b7fb0b964b7ab2d84ff4 100644
--- a/examples/wait1.rs
+++ b/examples/wait1.rs
@@ -1,5 +1,6 @@
 //! Periodic timeouts with TIM1
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
@@ -33,7 +34,7 @@ fn init(p: init::Peripherals) {
 }
 
 fn idle(r: idle::Resources) -> ! {
-    let timer = Timer(r.TIM1);
+    let timer = Timer(&**r.TIM1);
 
     let mut state = false;
     loop {
diff --git a/examples/wait2.rs b/examples/wait2.rs
index 36af50d96328058a48218a61e378b1ad182558a9..61e0403d54e9f565c2fabca8004efd28d929d673 100644
--- a/examples/wait2.rs
+++ b/examples/wait2.rs
@@ -1,5 +1,6 @@
 //! Periodic timeouts with TIM2
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
@@ -32,7 +33,7 @@ fn init(p: init::Peripherals) {
 }
 
 fn idle(r: idle::Resources) -> ! {
-    let timer = Timer(r.TIM2);
+    let timer = Timer(&**r.TIM2);
 
     let mut state = false;
     loop {
diff --git a/examples/wait3.rs b/examples/wait3.rs
index 1dc2d8fc6aa797c59eb9b47d33f7638149cda61e..8b058617230265b17e36a6daf63f2d5b874131be 100644
--- a/examples/wait3.rs
+++ b/examples/wait3.rs
@@ -1,5 +1,6 @@
 //! Periodic timeouts with TIM3
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
@@ -33,7 +34,7 @@ fn init(p: init::Peripherals) {
 }
 
 fn idle(r: idle::Resources) -> ! {
-    let timer = Timer(r.TIM3);
+    let timer = Timer(&**r.TIM3);
 
     let mut state = false;
     loop {
diff --git a/examples/wait4.rs b/examples/wait4.rs
index 98beb7bc0831bc6789f628c31d77f95c71b5bbde..cc6b2dfcda47f8452e1f76806be7e0a177c9b92d 100644
--- a/examples/wait4.rs
+++ b/examples/wait4.rs
@@ -1,5 +1,6 @@
 //! Periodic timeouts with TIM4
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(proc_macro)]
 #![no_std]
@@ -33,7 +34,7 @@ fn init(p: init::Peripherals) {
 }
 
 fn idle(r: idle::Resources) -> ! {
-    let timer = Timer(r.TIM4);
+    let timer = Timer(&**r.TIM4);
 
     let mut state = false;
     loop {
diff --git a/examples/ws2812.rs b/examples/ws2812.rs
index 449ef093513c5a76154d37b16919766664b5f29b..59dc20bb7249a49a09630018ce4eb051d3485be8 100644
--- a/examples/ws2812.rs
+++ b/examples/ws2812.rs
@@ -2,6 +2,7 @@
 //!
 //! To test this demo connect the data-in pin of the LED ring to pin PA0
 
+#![deny(unsafe_code)]
 #![deny(warnings)]
 #![feature(const_fn)]
 #![feature(proc_macro)]
@@ -27,7 +28,7 @@ app! {
     device: blue_pill::stm32f103xx,
 
     resources: {
-        BUFFER: Buffer<[u8; 577], Dma1Channel2> = Buffer::new([_0; 577]);
+        static BUFFER: Buffer<[u8; 577], Dma1Channel2> = Buffer::new([_0; 577]);
     },
 
     idle: {
@@ -51,7 +52,7 @@ fn init(p: init::Peripherals, r: init::Resources) {
 }
 
 fn idle(r: idle::Resources) -> ! {
-    let pwm = Pwm(r.TIM2);
+    let pwm = Pwm(&**r.TIM2);
 
     pwm.set_duties(r.DMA1, Channel::_1, r.BUFFER).unwrap();