From 317e06551744f1584f0d001fa48787735c2ca1b8 Mon Sep 17 00:00:00 2001
From: nerwalt <tlawren@gmail.com>
Date: Fri, 28 Jun 2024 08:59:22 -0600
Subject: [PATCH] Adding uart example to 9151-ns Updated README

---
 examples/nrf9151/ns/README.md       |  6 ++---
 examples/nrf9151/ns/src/bin/uart.rs | 37 +++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 3 deletions(-)
 create mode 100644 examples/nrf9151/ns/src/bin/uart.rs

diff --git a/examples/nrf9151/ns/README.md b/examples/nrf9151/ns/README.md
index a413dab85..a3f81d24e 100644
--- a/examples/nrf9151/ns/README.md
+++ b/examples/nrf9151/ns/README.md
@@ -1,4 +1,4 @@
 You must flash the TFM before running any non-secure examples. The TFM
-configures the secure and non-secure execution environments. After
-configuration, the TFM loads the non-secure application. A reference TFM is
-included, and you can use the provided helper script to flash it.
+configures the secure and non-secure execution environments and then loads the
+non-secure application. A reference TFM is included, and you can use the
+provided helper script to flash it.
diff --git a/examples/nrf9151/ns/src/bin/uart.rs b/examples/nrf9151/ns/src/bin/uart.rs
new file mode 100644
index 000000000..2220dccfb
--- /dev/null
+++ b/examples/nrf9151/ns/src/bin/uart.rs
@@ -0,0 +1,37 @@
+#![no_std]
+#![no_main]
+
+use defmt::*;
+use embassy_executor::Spawner;
+use embassy_nrf::{bind_interrupts, peripherals, uarte};
+use {defmt_rtt as _, panic_probe as _};
+
+bind_interrupts!(struct Irqs {
+    SPIM0_SPIS0_TWIM0_TWIS0_UARTE0 => uarte::InterruptHandler<peripherals::SERIAL0>;
+});
+
+#[embassy_executor::main]
+async fn main(_spawner: Spawner) {
+    let p = embassy_nrf::init(Default::default());
+    let mut config = uarte::Config::default();
+    config.parity = uarte::Parity::EXCLUDED;
+    config.baudrate = uarte::Baudrate::BAUD115200;
+
+    let mut uart = uarte::Uarte::new(p.SERIAL0, Irqs, p.P0_26, p.P0_27, config);
+
+    info!("uarte initialized!");
+
+    // Message must be in SRAM
+    let mut buf = [0; 8];
+    buf.copy_from_slice(b"Hello!\r\n");
+
+    unwrap!(uart.write(&buf).await);
+    info!("wrote hello in uart!");
+
+    loop {
+        info!("reading...");
+        unwrap!(uart.read(&mut buf).await);
+        info!("writing...");
+        unwrap!(uart.write(&buf).await);
+    }
+}