From 2246228df80eb9e0682e4bd8f1ca628b47c362b4 Mon Sep 17 00:00:00 2001
From: Per Lindgren <per.lindgren@ltu.se>
Date: Tue, 13 Feb 2018 21:43:39 +0100
Subject: [PATCH] bare6 84hmz

---
 examples/bare7.rs | 95 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)
 create mode 100644 examples/bare7.rs

diff --git a/examples/bare7.rs b/examples/bare7.rs
new file mode 100644
index 0000000..97f5d21
--- /dev/null
+++ b/examples/bare7.rs
@@ -0,0 +1,95 @@
+//! Serial interface loopback
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![feature(proc_macro)]
+#![no_std]
+
+extern crate cortex_m_rtfm as rtfm;
+extern crate f4;
+
+use f4::prelude::*;
+use f4::Serial;
+use f4::serial::Event;
+use f4::time::Hertz;
+use rtfm::{app, Threshold};
+
+// CONFIGURATION
+const BAUD_RATE: Hertz = Hertz(115_200);
+
+// TASKS & RESOURCES
+app! {
+    device: f4::stm32f40x,
+
+    tasks: {
+        USART2: {
+            path: loopback,
+            resources: [USART2],
+        },
+    }
+}
+
+// INITIALIZATION PHASE
+fn init(p: init::Peripherals) {
+    let serial = Serial(p.USART2);
+
+    serial.init(BAUD_RATE.invert(), None, p.GPIOA, p.RCC);
+    serial.listen(Event::Rxne);
+}
+
+// IDLE LOOP
+fn idle() -> ! {
+    // Sleep
+    loop {
+        rtfm::wfi();
+    }
+}
+
+// TASKS
+// Send back the received byte
+fn loopback(_t: &mut Threshold, r: USART2::Resources) {
+    let serial = Serial(&**r.USART2);
+
+    let byte = serial.read().unwrap();
+    serial.write(byte).unwrap();
+}
+
+// 1. compile and run the project at 16MHz
+// make sure its running (not paused)
+// start a terminal program, e.g., `moserial`
+// connect to the port
+//
+// Device       /dev/ttyACM0
+// Baude Rate   115200
+// Data Bits    8
+// Stop Bits    1
+// Parity       None
+// Handshake    None
+//
+// (this is also known in short as 15200 8N1)
+//
+// you should now be able to send data and recive an echo from the MCU
+//
+// try sending: "abcd"
+//
+// what did you receive
+// ** your answer here **
+//
+// try changing to baud rate 57600, both in the program and terminal settings,
+// recompile and run
+//
+// try sending: "abcd"
+// what did you receive
+// ** your answer here **
+//
+// commit your answers as (bare7_1)
+//
+// 2. now you should make a buffer
+// static BUFFER [u8;8]
+// to store the incoming data
+//
+// this can be done in a resource
+// app
+//
+// when the buffer is full you should write the complete buffer
+//
+//
-- 
GitLab