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

Fix LCD_CAM i8080 potentially sending garbage data to display #1301

Merged

Conversation

yanshay
Copy link
Contributor

@yanshay yanshay commented Mar 16, 2024

LCD_CAM i8080 sometime outputs garbage to the display.

This is due to a race condition when LCD_CAM starts sending data to display before the DMA had time to get data to the FIFO. The solution is quite simple, adding a short delay (delay based on what's used in esp-idf) between starting the DMA and activating LCD_CAM send.

For more info - #1086 (comment)

Thank you!

Thank you for your contribution.
Please make sure that your submission includes the following:

Must

  • The code compiles without errors or warnings.
  • All examples work.
  • cargo fmt was run.
  • Your changes were added to the CHANGELOG.md in the proper section.
  • [N/A ] You updated existing examples or added examples (if applicable).
  • [N/A] Added examples are checked in CI

Nice to have

  • You add a description of your work to this PR.
  • You added proper docs for your newly added features and code.

@yanshay
Copy link
Contributor Author

yanshay commented Mar 16, 2024

I don't understand what's going on.
I added a single line of code and everything fails, not related to my change.
Will need assistance here from maintainers.

@jessebraham
Copy link
Member

I'm not 100% sure what's happening here, I think it may be a regression in nightly, possibly related to TAIT.

It was building yesterday and nothing in the repo has changed since then. I re-ran CI on the main branch of my fork (which is up-to-date with upstream) and it is now failing too. So, fairly certain this isn't an us-problem.

With that said, it's Saturday morning and I'm not sure how deep I'll dig into this right now. 😅 I will spend at least a few minutes investigating today and update you if I do find anything, but otherwise this will likely have to wait until Monday. Sorry for the inconvenience, unfortunately this is the price we pay for living on the bleeding edge 😁

@yanshay
Copy link
Contributor Author

yanshay commented Mar 16, 2024

From my perspective this can easily wait, enjoy the weekend.

@jessebraham
Copy link
Member

Just to add some additional information from my (brief) investigation:

I ran cargo-expand with all the required arguments on one of the failing examples, in this case embassy_serial:

$ cd examples/
$ cargo expand --features=esp32c2,async,embassy,embassy-executor-thread,embassy-time-timg0,embassy-generic-timers --target=riscv32imc-unknown-none-elf --bin=embassy_serial

From the resulting output, we'll look at this excerpt:

#[doc(hidden)]
async fn __writer_task(
    mut tx: UartTx<'static, UART0>,
    signal: &'static Signal<NoopRawMutex, usize>,
) {
    use core::fmt::Write;
    embedded_io_async::Write::write(
            &mut tx,
            b"Hello async serial. Enter something ended with EOT (CTRL-D).\r\n",
        )
        .await
        .unwrap();
    embedded_io_async::Write::flush(&mut tx).await.unwrap();
    loop {
        let bytes_read = signal.wait().await;
        signal.reset();
        (&mut tx)
            .write_fmt(format_args!("\r\n-- received {0} bytes --\r\n", bytes_read))
            .unwrap();
        embedded_io_async::Write::flush(&mut tx).await.unwrap();
    }
}
fn writer(
    tx: UartTx<'static, UART0>,
    signal: &'static Signal<NoopRawMutex, usize>,
) -> ::embassy_executor::SpawnToken<impl Sized> {
    type Fut = impl ::core::future::Future + 'static;
    const POOL_SIZE: usize = 1;
    static POOL: ::embassy_executor::raw::TaskPool<Fut, POOL_SIZE> = ::embassy_executor::raw::TaskPool::new();
    unsafe { POOL._spawn_async_fn(move || __writer_task(tx, signal)) }
}

The first of our two build errors for this example (they're both the same root issue):

error: concrete type differs from previous defining opaque type use
  --> src/bin/embassy_serial.rs:31:1
   |
31 | #[embassy_executor::task]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `writer::Fut`, got `impl Future<Output = ()>`
   |
note: previous use here
  --> src/bin/embassy_serial.rs:31:1
   |
31 | #[embassy_executor::task]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info)

So, as far as I can tell (this is sort of a guess at this point), it's upset with type Fut = impl ::core::future::Future + 'static; (which is generated via the embassy-executor package). But, possibly something else is going on here.

@yanshay
Copy link
Contributor Author

yanshay commented Mar 18, 2024

@Dominaezzz : I added the delay to fix the garbage data sent sometimes to the display. It fixed the issues for my app. Basically a single line of code.
It didn't fix the issue where the example flashes different colors in release and debug mode and I couldn't find how to fix that.

Anyway, @bjoernQ asked that someone tests this change to work (or I guess at least doesn't break the example or anything else) since he doesn't have a compatible device to test with.

Can you help by testing this so it can be merged?

Thanks

@yanshay yanshay closed this Mar 19, 2024
@yanshay yanshay reopened this Mar 19, 2024
@Dominaezzz
Copy link
Collaborator

Hello! I'll have some time later this week to run the example again on this PR.

@jessebraham
Copy link
Member

jessebraham commented Mar 20, 2024

Sorry for the delays with fixing CI, if you rebase CI should be green now.

Also just FYI, @JurajSadel and/or @playfulFence will attempt to hunt down a devkit with an appropriate display to keep in the office, so that we can hopefully test this functionality in the future.

esp-hal/CHANGELOG.md Outdated Show resolved Hide resolved
@Dominaezzz
Copy link
Collaborator

Just ran the example and it still works the same for me.

@bjoernQ
Copy link
Contributor

bjoernQ commented Mar 25, 2024

@yanshay Really sorry for the huge delay here. I think we will need another rebase to get the "HIL Test" steps pass

- Fixed LCD_CAM i8080 potentially sending garbage to display (#1301)
- ESP32: Apply fix for Errata 3.6 in all the places necessary. (#1315)
- ESP32 & ESP32-S2: Fix I²C frequency (#1306)
- Fixed LCD_CAM i8080 potentially sending garbage to display (#1301)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this line insists on duplicating itself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rebased, it went strange (but then I'm not a git expert), and now I see it doesn't compile in the build. Maybe I did something wrong.

But then I tried taking main and building the i8080 example and It doesn't compile either on my machine, so maybe it's not me but rather something that changed on the main branch?

I could try fixing the example but I don't want to make a mess.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried compile the example on current main and it compiled fine for me 🤔

@yanshay yanshay closed this Mar 26, 2024
@yanshay yanshay force-pushed the yanshay_fix_lcd_cam_i8080_sending_garbage_try2 branch from ac3187a to fd4f559 Compare March 26, 2024 10:25
@yanshay yanshay reopened this Mar 26, 2024
@yanshay
Copy link
Contributor Author

yanshay commented Mar 26, 2024

I redid the change from scratch based on main, tested, now it seems to be fine.

Copy link
Contributor

@bjoernQ bjoernQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bjoernQ
Copy link
Contributor

bjoernQ commented Mar 26, 2024

Sorry, this took so long to get merged! Thanks!

@bjoernQ bjoernQ added this pull request to the merge queue Mar 26, 2024
Merged via the queue into esp-rs:main with commit f18e8ae Mar 26, 2024
21 checks passed
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.

5 participants