diff options
| -rw-r--r-- | examples/nrf9151/ns/README.md | 6 | ||||
| -rw-r--r-- | examples/nrf9151/ns/src/bin/uart.rs | 37 |
2 files changed, 40 insertions, 3 deletions
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 @@ | |||
| 1 | You must flash the TFM before running any non-secure examples. The TFM | 1 | You must flash the TFM before running any non-secure examples. The TFM |
| 2 | configures the secure and non-secure execution environments. After | 2 | configures the secure and non-secure execution environments and then loads the |
| 3 | configuration, the TFM loads the non-secure application. A reference TFM is | 3 | non-secure application. A reference TFM is included, and you can use the |
| 4 | included, and you can use the provided helper script to flash it. | 4 | 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 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::*; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_nrf::{bind_interrupts, peripherals, uarte}; | ||
| 7 | use {defmt_rtt as _, panic_probe as _}; | ||
| 8 | |||
| 9 | bind_interrupts!(struct Irqs { | ||
| 10 | SPIM0_SPIS0_TWIM0_TWIS0_UARTE0 => uarte::InterruptHandler<peripherals::SERIAL0>; | ||
| 11 | }); | ||
| 12 | |||
| 13 | #[embassy_executor::main] | ||
| 14 | async fn main(_spawner: Spawner) { | ||
| 15 | let p = embassy_nrf::init(Default::default()); | ||
| 16 | let mut config = uarte::Config::default(); | ||
| 17 | config.parity = uarte::Parity::EXCLUDED; | ||
| 18 | config.baudrate = uarte::Baudrate::BAUD115200; | ||
| 19 | |||
| 20 | let mut uart = uarte::Uarte::new(p.SERIAL0, Irqs, p.P0_26, p.P0_27, config); | ||
| 21 | |||
| 22 | info!("uarte initialized!"); | ||
| 23 | |||
| 24 | // Message must be in SRAM | ||
| 25 | let mut buf = [0; 8]; | ||
| 26 | buf.copy_from_slice(b"Hello!\r\n"); | ||
| 27 | |||
| 28 | unwrap!(uart.write(&buf).await); | ||
| 29 | info!("wrote hello in uart!"); | ||
| 30 | |||
| 31 | loop { | ||
| 32 | info!("reading..."); | ||
| 33 | unwrap!(uart.read(&mut buf).await); | ||
| 34 | info!("writing..."); | ||
| 35 | unwrap!(uart.write(&buf).await); | ||
| 36 | } | ||
| 37 | } | ||
