Skip to content

sdio: initial SDIO HAL implementation #3503

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rmsyn
Copy link

@rmsyn rmsyn commented May 20, 2025

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 developer guidelines

Extra:

Pull Request Details 📖

Description

Provides the initial skeleton for the embedded_hal::mmc::MmcOps implementation for the SDIO peripherals on the ESP32C6 microcontroller.

Testing

Doc tests for now.

Integration tests via examples program is WIP.

@rmsyn rmsyn marked this pull request as draft May 20, 2025 01:12
}

/// Releases the inner SDIO peripherals back to the caller.
pub const fn release(self) -> (SLC, SLCHOST) {
Copy link
Member

Choose a reason for hiding this comment

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

FYI this pattern goes against our guidelines in esp-hal: https://github.com/esp-rs/esp-hal/blob/main/documentation/DEVELOPER-GUIDELINES.md.

We use peripheral singletons with lifetime parameters, you can "borrow" (our method is called reborrow, but now I'm wondering if borrow makes more sense cc: @bugadani) a peripheral to allow drivers to automatically "release" the peripheral singleton again once the driver has been dropped.

Copy link
Author

@rmsyn rmsyn May 21, 2025

Choose a reason for hiding this comment

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

I almost completely refactored using your advice, and the developer guidelines. Also took a look at some other peripheral implementations, and hopefully got closer to the intended style of esp-hal.

Still more to implement for the Info structs, and will likely add State + Configuration structs. Though, I'm not sure if those would find a better home inside the Sdio struct, or the peripheral Slc* structs.

//! Error and result types for SDIO peripherals.

/// Convenience alias for the SDIO peripheral [Result](core::result::Result) type.
pub type Result<T> = core::result::Result<T, Error>;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is something that we want, if you need it for the eh impl then please inline it close to where the eh impl will live

Copy link
Author

Choose a reason for hiding this comment

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

I removed the Result alias, but did keep the Error type. Error currently only holds one variant, but the plan is to implement more for specific failure conditions for the hal::mmc implementation.

@rmsyn rmsyn force-pushed the esp32c6/sdmmc-impl branch 2 times, most recently from b7eeb4c to 2142d4d Compare May 22, 2025 03:31

impl core::error::Error for Error {}

impl<'d> MmcOps for Sdio<'d> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something is not quite right here. MmcOps is meant for the master side of this protocol, but you've implemented this on the slave peripheral.

I think you want the SD/MMC peripheral (#1928) and not the SDIO peripheral, right?

Copy link
Author

Choose a reason for hiding this comment

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

Something is not quite right here. MmcOps is meant for the master side of this protocol, but you've implemented this on the slave peripheral.

I think you want the SD/MMC peripheral (#1928) and not the SDIO peripheral, right?

Correct, the MmcOps trait is currently for the host, and I need to split the trait into potentially three traits:

  • MmcCommon
  • MmcHost
  • MmcDevice

I'll keep working on the e-h trait along with the work in this pull request. Thanks for the review.

@rmsyn rmsyn force-pushed the esp32c6/sdmmc-impl branch 3 times, most recently from dddf388 to c3a7b0d Compare May 30, 2025 03:17
@rmsyn
Copy link
Author

rmsyn commented May 30, 2025

Running the CI / * checks are failing, partially due to some weird dependency resolution.

As I get closer to a full implementation, I may need to bring in the embedded-hal::mmc::* stuff locally to avoid the git dependency.

What's strange is that running cargo clippy ... directly passes, but the xtask lint-packages can't resolve the embedded_hal::mmc::MmcCommon trait, and fails to build the embassy-hal-async examples.

I'll keep debugging.

@rmsyn rmsyn force-pushed the esp32c6/sdmmc-impl branch from c3a7b0d to f017518 Compare May 30, 2025 04:14
@bugadani
Copy link
Contributor

It would be best to not block this PR on embedded-hal, as it'll likely take months to stabilize a new set of traits. You should instead demonstrate new functionality in a new crate, like embedded-sdmmc in the embedded-hal repository, so that it can be released unstably and implemented by esp-hal and one other required implementor.

That way you wouldn't have to patch around the dependency issues with multiple embedded-hal versions in the same project.

@MabezDev
Copy link
Member

To expand on @bugadani's comment, we can't merge this with git dependencies, so I would take the suggestion to split this into a separate crate and then work on upstreaming to eh proper. Feel free to iterate here in the mean time, but if you want this merged it won't be with a fork of embedded-hal.

@rmsyn
Copy link
Author

rmsyn commented May 31, 2025

It would be best to not block this PR on embedded-hal, as it'll likely take months to stabilize a new set of traits. You should instead demonstrate new functionality in a new crate, like embedded-sdmmc in the embedded-hal repository, so that it can be released unstably and implemented by esp-hal and one other required implementor.

This sounds like a good plan. I'll bring it up in next week's meeting, and see what the rest of the HAL team thinks.

To expand on @bugadani's comment, we can't merge this with git dependencies, so I would take the suggestion to split this into a separate crate and then work on upstreaming to eh proper. Feel free to iterate here in the mean time, but if you want this merged it won't be with a fork of embedded-hal.

Right, I had no intention of trying to get this PR merged with the git dependency. My original thought process was to prove the implementation here and in jh71xx-hal, iterate on the trait in embedded-hal, stabilize in embedded-hal, and take this PR out of Draft status after an embedded-hal release that includes the mmc module + traits.

However, the solution discussed above sounds like a better plan. We could do a embedded-hal-sdmmc v0.1.0-alpha.whatever release, and base the work off that crate until mmc stuff gets merged upstream (if ever).

Without trying to bikeshed too much, we would probably need to call it embedded-hal-sdmmc, since @thejpster already has embedded-sdmmc-rs. embedded-hal-sdmmc also keeps with the naming convention of embedded-hal-[async, io, nb, ...].

rmsyn added a commit to rmsyn/esp-hal that referenced this pull request Jun 4, 2025
Uses the experimental `embedded-hal-sdmmc` crate for SD/MMC traits.

See discussion for reasoning:

- <esp-rs#3503 (comment)>
- <esp-rs#3503 (comment)>
- <esp-rs#3503 (comment)>
rmsyn added 3 commits June 4, 2025 02:06
Provides the initial skeleton for the `embedded_hal::mmc::MmcOps`
implementation for the SDIO peripherals on the ESP32C6 microcontroller.
Adds `Pins` + `Mode` type for SDIO GPIO pin configuration.
Adds the `State` type to represent the SDIO states + transitions.
@rmsyn rmsyn force-pushed the esp32c6/sdmmc-impl branch from fb552b8 to b0058c0 Compare June 4, 2025 02:06
rmsyn added a commit to rmsyn/esp-hal that referenced this pull request Jun 4, 2025
Uses the experimental `embedded-hal-sdmmc` crate for SD/MMC traits.

See discussion for reasoning:

- <esp-rs#3503 (comment)>
- <esp-rs#3503 (comment)>
- <esp-rs#3503 (comment)>
rmsyn added a commit to rmsyn/esp-hal that referenced this pull request Jun 4, 2025
Uses the experimental `embedded-hal-sdmmc` crate for SD/MMC traits.

See discussion for reasoning:

- <esp-rs#3503 (comment)>
- <esp-rs#3503 (comment)>
- <esp-rs#3503 (comment)>
@rmsyn rmsyn force-pushed the esp32c6/sdmmc-impl branch from b0058c0 to a53f104 Compare June 4, 2025 02:07
rmsyn added a commit to rmsyn/esp-hal that referenced this pull request Jun 4, 2025
Uses the experimental `embedded-hal-sdmmc` crate for SD/MMC traits.

See discussion for reasoning:

- <esp-rs#3503 (comment)>
- <esp-rs#3503 (comment)>
- <esp-rs#3503 (comment)>
@rmsyn rmsyn force-pushed the esp32c6/sdmmc-impl branch from a53f104 to 5ec5792 Compare June 4, 2025 02:19
Uses the experimental `embedded-hal-sdmmc` crate for SD/MMC traits.

See discussion for reasoning:

- <esp-rs#3503 (comment)>
- <esp-rs#3503 (comment)>
- <esp-rs#3503 (comment)>
@rmsyn rmsyn force-pushed the esp32c6/sdmmc-impl branch from 5ec5792 to ec42929 Compare June 4, 2025 02:29
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.

4 participants