embassy-rs / embassy

Modern embedded framework, using Rust and async.
https://embassy.dev
Apache License 2.0
5.52k stars 767 forks source link

embassy-nrf: can't get uarte to work on nrf5340 #2767

Open stikkanen opened 7 months ago

stikkanen commented 7 months ago

With the minimal example below, I can't get any output from uarte. Anything more complex trying to read or using BufferedUarte doesn't work either. I'm using nrf5340-app-s and embassy from git with the nightly-2024-03-20 toolchain.

#![feature(type_alias_impl_trait)]
#![no_std]
#![no_main]

use {defmt_rtt as _, panic_probe as _};
use embassy_executor::Spawner;
use embassy_nrf::{
    bind_interrupts,
    peripherals,
    uarte::{self, Parity, Baudrate, Uarte},
};
use embassy_time::Timer;

bind_interrupts!(struct Irqs {
    SERIAL0 => 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 = Parity::EXCLUDED;
    config.baudrate = Baudrate::BAUD115200;
    let mut uart = Uarte::new(
        p.SERIAL0, Irqs,
        p.P1_15, p.P0_13,
        config,
    );
    uart.write(b"AT\r\n").await.unwrap();

    loop {
        Timer::after_millis(300).await;
    };
}

I have also tested a variation of this on the nRF52833 devkit (SERIAL0 => UARTE1, P1_15 => P0_07, P0_13 => P0_08) and have a similar result of no output on the TX pin when observed with a logic analyzer. The TX pin is pulled high on the nRF5340, but not on the nRF52833. Logs from nRF5340 below.

0.000000 TRACE Copying UARTE tx buffer into RAM for DMA
└─ embassy_nrf::uarte::{impl#4}::write::{async_fn#0} @ /home/stikkanen/.local/share/cargo/git/checkouts/embassy-9312dcb0ed774b29/027a1e6/embassy-nrf/src/fmt.rs:117 
0.000091 TRACE starttx
└─ embassy_nrf::uarte::{impl#4}::write_from_ram::{async_fn#0}::{closure#0} @ /home/stikkanen/.local/share/cargo/git/checkouts/embassy-9312dcb0ed774b29/027a1e6/embassy-nrf/src/fmt.rs:117 

Am I missing something here about how to setup Uarte?

igiona commented 1 month ago

This example https://github.com/embassy-rs/embassy/blob/main/examples/nrf5340/src/bin/uart.rs works for me