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 SPI DMA write/read for ESP32, ESP32-S2 #2131

Merged
merged 3 commits into from
Sep 10, 2024

Conversation

bjoernQ
Copy link
Contributor

@bjoernQ bjoernQ commented Sep 10, 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.
  • I have added necessary changes to user code to the Migration Guide.
  • My changes are in accordance to the esp-rs API guidelines

Extra:

Pull Request Details 📖

Description

On ESP32 and ESP32-S2 something like this didn't work

        embedded_hal_async::spi::SpiBus::write(&mut spi, &send_buffer)
            .await
            .unwrap();

        embedded_hal_async::spi::SpiBus::read(&mut spi, &mut buffer)
            .await
            .unwrap();

As already found in #2059 ESP32 needs some special handling to make it work.
For ESP32-S2 the solution was found by "trial and error" (also the problem there was a bit different: on S2 the first iteration worked but then it stopped working)

Testing

I added tests and you can modify embassy_spi.rs example to perform write and read in the loop like above

@bjoernQ bjoernQ linked an issue Sep 10, 2024 that may be closed by this pull request
@plaes
Copy link
Contributor

plaes commented Sep 10, 2024

Yes, this fixes at least my issue on regular ESP32 and I can now send and receive full LoRa P2P packets..

@bugadani
Copy link
Contributor

Is there a chance the new test can be merged into one of the existing ones?

@bjoernQ bjoernQ marked this pull request as ready for review September 10, 2024 12:05
@bjoernQ
Copy link
Contributor Author

bjoernQ commented Sep 10, 2024

Is there a chance the new test can be merged into one of the existing ones?

Unfortunately, we need a different init - not sure embedded-test supports multiple test modules (which probably would be flashed as a separate executable anyways). There are two which in theory might be useable but then the names of the tests are awkward and misleading .... that's why I went with a separate test. Not too happy with that but the other options don't feel great

let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let sclk = io.pins.gpio0;
let (miso, gpio) = hil_test::common_test_pins!(io);
let _gpio = Output::new(gpio.degrade(), Level::High);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let _gpio = Output::new(gpio.degrade(), Level::High);
let _gpio = Output::new(gpio, Level::High);

Copy link
Contributor

@JurajSadel JurajSadel left a comment

Choose a reason for hiding this comment

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

Thanks!

@JurajSadel JurajSadel added this pull request to the merge queue Sep 10, 2024
Merged via the queue into esp-rs:main with commit 7332f58 Sep 10, 2024
27 checks passed
@bjoernQ bjoernQ deleted the fix/spi-dma-write-read branch November 26, 2024 08:42
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.

Async SPI transaction with [write, read] operation broken on esp32
4 participants