Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esp_hal: Add read_bytes() to Uart #1697

Closed
wants to merge 1 commit into from

Conversation

JurajSadel
Copy link
Contributor

@JurajSadel JurajSadel commented Jun 19, 2024

Thank you for your contribution!

We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • My changes were added to the CHANGELOG.md in the proper section.
  • My changes are in accordance to the esp-rs API guidelines

Extra:

Pull Request Details 📖

Description

Please provide a clear and concise description of your changes, including the motivation behind these changes. The context is crucial for the reviewers.

Testing

//! This shows how to configure UART
//! You can short the TX and RX pin and see it reads what was written.
//! Additionally you can connect a logic analyzer to TX and see how the changes
//! of the configuration change the output signal.
//!
//! The following wiring is assumed:
//! - TX => GPIO4
//! - RX => GPIO5

//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3

#![no_std]
#![no_main]

use esp_backtrace as _;
use esp_hal::{
    clock::ClockControl,
    delay::Delay,
    gpio::Io,
    peripherals::Peripherals,
    prelude::*,
    system::SystemControl,
    uart::Uart,
};
use esp_println::println;

#[entry]
fn main() -> ! {
    let peripherals = Peripherals::take();
    let system = SystemControl::new(peripherals.SYSTEM);
    let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

    let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

    let mut serial1 = Uart::new(peripherals.UART1, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap();

    let delay = Delay::new(&clocks);

    let mut buf = &mut [0; 32];

    println!("Start");
    delay.delay_millis(10);
    loop {
        let written = serial1.write_bytes(&[5; 30]).ok().unwrap();
        // delay.delay_millis(1);
        let mut buf = &mut [0; 32];
        let read = serial1.read_bytes(buf, written);

        println!("read: {}", read);

        delay.delay_millis(500);
    }
}

Opening as a draft because I'm not sure if this is the correct approach (definitely not the best). The get_rx_fifo_count() is pretty slow for "bigger" transfers and I'm not sure how to block until all bytes are written. Other option would be to "play" a bit with delay before calling read_bytes but that seems hacky as well.

Any idea/input here would be appreciated.

closes #1567

@jessebraham
Copy link
Member

Any updates here?

@MabezDev
Copy link
Member

Closing in favour of #1784

@MabezDev MabezDev closed this Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uart: Add blocking read_bytes method
3 participants