Skip to content

embassy-rp: Add the has_rx_data and read_until_blocking functions to rp20xx uart implementation #6443

Open
HenriqueDomiciano wants to merge 15 commits into
embassy-rs:mainfrom
HenriqueDomiciano:add-read-until-and-has-rx-data-to-rp-2040
Open

embassy-rp: Add the has_rx_data and read_until_blocking functions to rp20xx uart implementation #6443
HenriqueDomiciano wants to merge 15 commits into
embassy-rs:mainfrom
HenriqueDomiciano:add-read-until-and-has-rx-data-to-rp-2040

Conversation

@HenriqueDomiciano

@HenriqueDomiciano HenriqueDomiciano commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Attempt to implement feature requested on the issue #6331. Fixes #6331 if any new HALs need to be implemented

@HenriqueDomiciano

HenriqueDomiciano commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Still not tested, will stress as soon as possible, will put evidence here

@HenriqueDomiciano HenriqueDomiciano changed the title Add the has_rx_data and read_until_blocking functions to rp2040 uart implementation rp: Add the has_rx_data and read_until_blocking functions to rp2040 uart implementation Jul 3, 2026
@HenriqueDomiciano HenriqueDomiciano changed the title rp: Add the has_rx_data and read_until_blocking functions to rp2040 uart implementation embassy-rp: Add the has_rx_data and read_until_blocking functions to rp2040 uart implementation Jul 3, 2026
@HenriqueDomiciano HenriqueDomiciano changed the title embassy-rp: Add the has_rx_data and read_until_blocking functions to rp2040 uart implementation [wip] embassy-rp: Add the has_rx_data and read_until_blocking functions to rp2040 uart implementation Jul 3, 2026
@HenriqueDomiciano

HenriqueDomiciano commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Did the following to test the implementation used the code below

`
#![no_std]
#![no_main]
use embassy_time::{Duration, Timer};
use embassy_executor::Spawner;
use embassy_rp::uart;
use {defmt_rtt as _, panic_probe as _};

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_rp::init(Default::default());

let config = uart::Config::default();
let mut uart = uart::Uart::new_blocking(
    p.UART0,
    p.PIN_0, // TX
    p.PIN_1, // RX
    config,
);

let (mut tx, mut rx) = uart.split();

defmt::info!("Starting program!!!");
tx.blocking_write(b"UART Echo Ready\r\n").unwrap();

let mut buf = [0u8; 1];

loop {
    let there_is_data = rx.has_rx_data(); 
    if there_is_data
    {
        tx.blocking_write(b"Data Received \r\n");
        let there_is_data = rx.has_rx_data();
        defmt::info!("result of there is data {}",there_is_data); 
        let bytes = rx.blocking_read(&mut buf); 
        defmt::info!("received {:x}", buf[0]);
    }
    else{ 
        defmt::info!("Result of there is data {}",there_is_data); 
    }
    Timer::after(Duration::from_secs(1)).await;
    
    let number_of_bytes = rx.read_until_character_with_timeout(&mut buf, b"\r", 5_000_000);
    match number_of_bytes 
    {
        Ok(n) => defmt::info!("Received {} bytes to buff {:x}",n, buf[..n]),
        Err(e) => defmt::info!("An error happened {:?}",e)
    }

    tx.blocking_write(&buf).unwrap();
}

}`

The results on the defmt logs are the following

image

The changed the code on the loop to something like

`
let mut buf = [0u8; 1024];

loop {
    let number_of_bytes = rx.read_until_character_with_timeout(&mut buf, b"\r", 50_000_000);
    match number_of_bytes {
        Ok(n) => defmt::info!("Received {} bytes to buff {:x}", n, buf[..n]),
        Err(e) => defmt::info!("An error happened {:?}", e),
    }

    tx.blocking_write(&buf).unwrap();
}`

And the results are the following
Minicom image
image
dfmt logs image
image

So the implementation of the function for the purpose requested are working any points to be fixed i will be welcome to do.

@HenriqueDomiciano
HenriqueDomiciano marked this pull request as ready for review July 3, 2026 19:40
@HenriqueDomiciano HenriqueDomiciano changed the title [wip] embassy-rp: Add the has_rx_data and read_until_blocking functions to rp2040 uart implementation embassy-rp: Add the has_rx_data and read_until_blocking functions to rp2040 uart implementation Jul 3, 2026
@HenriqueDomiciano HenriqueDomiciano changed the title embassy-rp: Add the has_rx_data and read_until_blocking functions to rp2040 uart implementation embassy-rp: Add the has_rx_data and read_until_blocking functions to rp20xx uart implementation Jul 3, 2026
@xoviat xoviat added the e-rp Issues for the RP family of chips label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e-rp Issues for the RP family of chips

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please create an UART "data available" function

2 participants