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

Logging using UART0 alongside println does not work #1531

Closed
apollolabsdev opened this issue May 2, 2024 · 1 comment
Closed

Logging using UART0 alongside println does not work #1531

apollolabsdev opened this issue May 2, 2024 · 1 comment
Labels
peripheral:uart UART peripheral

Comments

@apollolabsdev
Copy link

apollolabsdev commented May 2, 2024

Using version 0.17.0 of the esp-hal, and the code below, attempting to log using UART0 alongside println does not work.

Hardware behavior: Only "println output" is printed to the console with every loop iteration. The code was executed on the ESP32-C3 using the Rust DevKit.
Wokwi behavior: No output printed at all. println works only if uart instantiation is removed.

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

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

    let mut uart = Uart::new_with_config(
        peripherals.UART0,
        Config::default(),
        None::<TxRxPins<gpio::NoPinType, gpio::NoPinType>>,
        &clocks,
        None,
    );

    loop {
        println!("println output");
        uart.write_bytes("uart output".as_bytes()).unwrap();
        delay.delay_millis(1000u32);
    }
}

Update:
The same issue occurs when testing using the embassy_serial example in the esp-rs repo.

@SergioGasquez SergioGasquez added the peripheral:uart UART peripheral label May 15, 2024
@MabezDev
Copy link
Member

If you're using the Rust board, it means you are printing via USB serial jtag, not uart.

The confusion here is that esp println is using the ROM code to print, which will also detect if the USB serial jtag is connected and output to there too (Note that this only applies to esp32c3 ROM code, the other chips don't do this) which is why you see the println! output. If you have a devkitC, you can take a look at the serial output from that and you'll see that this is working correctly.

Closing for now, but maybe we can do better to make it more clear what's happening in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
peripheral:uart UART peripheral
Projects
Status: Done
Development

No branches or pull requests

3 participants