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

UsbSerialJtag embedd_io_async Write after signal wait not working #1560

Closed
PGIII opened this issue May 16, 2024 · 0 comments
Closed

UsbSerialJtag embedd_io_async Write after signal wait not working #1560

PGIII opened this issue May 16, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@PGIII
Copy link

PGIII commented May 16, 2024

Hardware

ESP32-S3-DevKitC-1 v1.1

Issue

I've been building an application based on The USB Async Example and have been debugging an issue where only the first packet gets responded to. The issue only arises when using the embedded_io_async Write trait after waiting on a signal. I'm able to reproduce this issue by modifying the example to call the async write-all instead of the regular synchronous version that the write! macro uses. Adding additional write_alls before the signal.wait work fine also.

The only modification is in the writer function. There seems to be some issue with the async write trait that the regular one isn't running into. However, I'm not sure yet why it's no longer responding. Seems like the reader never receives any more bytes after the write_all call but I haven't been able to nail down why yet.

Working Code

#[embassy_executor::task]
async fn writer(
    mut tx: UsbSerialJtagTx<'static, Async>,
    signal: &'static Signal<NoopRawMutex, heapless::String<MAX_BUFFER_SIZE>>,
) {
    use core::fmt::Write;
    embedded_io_async::Write::write_all(
        &mut tx,
        b"Hello async USB Serial JTAG. Type something.\r\n",
    )
    .await
    .unwrap();
    loop {
        let message = signal.wait().await;
        signal.reset();
        write!(&mut tx, "-- received '{}' --\r\n", message).unwrap();
        embedded_io_async::Write::flush(&mut tx).await.unwrap();
    }
}

Non Working Code

#[embassy_executor::task]
async fn writer(
    mut tx: UsbSerialJtagTx<'static, Async>,
    signal: &'static Signal<NoopRawMutex, heapless::String<MAX_BUFFER_SIZE>>,
) {
    use core::fmt::Write;
    embedded_io_async::Write::write_all(
        &mut tx,
        b"Hello async USB Serial JTAG. Type something.\r\n",
    )
    .await
    .unwrap();
    loop {
        let message = signal.wait().await;
        signal.reset();
        //write!(&mut tx, "-- received '{}' --\r\n", message).unwrap();
        embedded_io_async::Write::write_all(&mut tx, b"Got Stuff")
            .await
            .unwrap();
        embedded_io_async::Write::flush(&mut tx).await.unwrap();
    }
}
@bjoernQ bjoernQ self-assigned this May 17, 2024
@bjoernQ bjoernQ added the bug Something isn't working label May 17, 2024
@bjoernQ bjoernQ mentioned this issue May 17, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

3 participants