Rahix / avr-hal

embedded-hal abstractions for AVR microcontrollers
Apache License 2.0
1.32k stars 223 forks source link

Panic while trying to write to serial using `ufmt::uwriteln` #515

Closed BiasedKiwi closed 8 months ago

BiasedKiwi commented 8 months ago

When I'm trying to write to serial using ufmt::uwriteln I get

thread '<unnamed>' panicked at C:\Users\Alexandre\.cargo\registry\src\index.crates.io-6f17d22bba15001f\ravedude-0.1.7\src\console.rs:35:32:
called `Result::unwrap()` on an `Err` value: Error { kind: InvalidData, message: "Windows stdio in console mode does not support writing non-UTF-8 byte sequences" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Code:

#![no_std]
#![no_main]

use arduino_hal::prelude::*;
use panic_halt as _;

#[arduino_hal::entry]
fn main() -> ! {
    let dp = arduino_hal::Peripherals::take().unwrap();
    let pins = arduino_hal::pins!(dp);
    let mut serial = arduino_hal::default_serial!(dp, pins, 9600);

    ufmt::uwriteln!(&mut serial, "Hello, World!");

    loop {}
}

(follow up to #512)

Rahix commented 8 months ago

Hi, there are two things happening here, I think: First of all, ravedude is crashing with the error message you printed. This is a bug and I've prepared #516 to hopefully fix it. Please give this a try and report back what happens.

The second problem is that garbage data is received by ravedude in the first place. This shouldn't be happening either. I assume it is some problem with the serial connection, but let's wait on the output of the fixed ravedude from #516 - it will most likely make the issue easier to spot.

BiasedKiwi commented 8 months ago

I switched to using #516 and this is what I got ????????????????????????? so all characters in my string are bad apparently

Rahix commented 8 months ago

Hm, alright. Are you sure ravedude is using the same baudrate as your board? In your code I see that you are using 9600 baud:

arduino_hal::default_serial!(dp, pins, 9600);

Is ravedude using the same? In .cargo/config.toml where ravedude is specified as the runner, it should be called with a -b 9600 argument.

BiasedKiwi commented 8 months ago

That was it! It does print Hello, World! now. Thanks for helping me out