Skip to content

Comments

Support eMMC devices via SDMMC (STM32)#4016

Merged
Dirbaio merged 9 commits intoembassy-rs:mainfrom
antonok-edm:emmc
Apr 6, 2025
Merged

Support eMMC devices via SDMMC (STM32)#4016
Dirbaio merged 9 commits intoembassy-rs:mainfrom
antonok-edm:emmc

Conversation

@antonok-edm
Copy link
Contributor

I've added support for eMMC memory devices in embassy-stm32 using the SDMMC peripheral.

I've confirmed that this code works correctly for basic initialization, reads, and writes on a device that I've previously been using under stm32f4xx-hal, using 1, 4, and 8 data lanes, each with several different operating frequencies up to 24MHz.

Note that I don't have any appropriate hardware to test:

  • gpio_v1 config
  • sdmmc_v2 config
  • SD card regressions

@antonok-edm antonok-edm force-pushed the emmc branch 2 times, most recently from 9c530bc to 6165fc4 Compare March 27, 2025 07:31
@Dirbaio
Copy link
Member

Dirbaio commented Mar 27, 2025

Thanks for the PR!

Could you not add a new trait + generic param for the mode, track it at runtime instead (with e.g. an enum?). Reasons are:

  • There's code duplication in init_emmc/init_card and read_sd_status/read_ext_csd. With an enum you can easily "if emmc do this, if sd do that" in the few things that do change without having to copypaste the entire methods.
  • Less generics makes the API simpler for the user.

@antonok-edm
Copy link
Contributor Author

@Dirbaio sure, I'll try that. Poor timing on my part - right after I submitted this PR, I already had to rebase it because of #4005 doing the same thing for DMA 😅

@antonok-edm antonok-edm force-pushed the emmc branch 2 times, most recently from 10ed25f to 065108a Compare March 28, 2025 04:55
@antonok-edm
Copy link
Contributor Author

@Dirbaio I just pushed a new enum-based implementation in case you'd like to generally check over it. There are a couple of things that I think are slightly less clean than with traits but it's not too bad overall. I didn't attempt to address the code duplication you mentioned yet; will get to that tomorrow hopefully.

(previous implementation is still in antonok-edm/embassy#emmc-trait if needed)

@antonok-edm antonok-edm force-pushed the emmc branch 4 times, most recently from 3c63f66 to 5f750a4 Compare March 28, 2025 23:07
@antonok-edm
Copy link
Contributor Author

@Dirbaio ok, should be ready for review now - I've deduplicated the init methods and pulled common code out from all the block read/write functions into complete_datapath_transfer.

Copy link
Member

@Dirbaio Dirbaio left a comment

Choose a reason for hiding this comment

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

thank you!

@Dirbaio Dirbaio added this pull request to the merge queue Mar 30, 2025
@Dirbaio
Copy link
Member

Dirbaio commented Mar 30, 2025

Seems this breaks the sdcard test

bender run

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 30, 2025
@Dirbaio
Copy link
Member

Dirbaio commented Mar 30, 2025

hm I think the "task arena is full" error is a red herring. Task arena is gone since #4020. Try rebasing on latest main, you'll likely get the same error in PR CI as in the merge queue CI, which is "waiting for card: NoCard".

@antonok-edm antonok-edm force-pushed the emmc branch 12 times, most recently from dafbed1 to 70783bd Compare March 31, 2025 19:45
@antonok-edm
Copy link
Contributor Author

@Dirbaio SD card CI is now fixed, but there is still a usart_rx_ringbuffered error which seems unrelated, even after rebasing on main. Not sure if you have any ideas there.

@Dirbaio Dirbaio removed the trusted label Apr 6, 2025
@Dirbaio
Copy link
Member

Dirbaio commented Apr 6, 2025

yeah it's just flaky, i've removed it in #4054

bender run

@Dirbaio Dirbaio enabled auto-merge April 6, 2025 22:01
@Dirbaio Dirbaio added this pull request to the merge queue Apr 6, 2025
Merged via the queue into embassy-rs:main with commit 717fbc1 Apr 6, 2025
7 checks passed
@chemicstry
Copy link
Contributor

chemicstry commented Apr 25, 2025

Hey, thank you for implementing this right when I need it!

I, however, am having problems and would appreciate any help. I'm using STM32F429ZIT6 with EMMC16G-MW28-03022 flash on 8 bit bus and it just freezes on init_emmc(). Seems like an infinite loop as no other async tasks are being executed. What is strange, is that when I set breakpoints anywhere in the code it manages to initialize the eMMC and reports correct capacity. Any read after that fails with panicked at embassy-stm32\src\dma\dma_bdma.rs:289:21: DMA: error on DMA@40026400 channel 6. I tried using 1, 4 and 8 bit buses with no luck.

Have you experienced anything similar and could nudge me where to look?

EDIT: Nevermind, got it to work. It was some weird interraction with my logging buffer getting full and fatfs crashing due to empty emmc.

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.

3 participants