Documented CSD parsing expectations for SDIO lower-half#18543
Open
arjav1528 wants to merge 4 commits intoapache:masterfrom
Open
Documented CSD parsing expectations for SDIO lower-half#18543arjav1528 wants to merge 4 commits intoapache:masterfrom
arjav1528 wants to merge 4 commits intoapache:masterfrom
Conversation
a20aa66 to
7616424
Compare
linguini1
requested changes
Mar 16, 2026
| The MMCSD upper-half (``drivers/mmcsd/mmcsd_sdio.c``) interacts with the | ||
| lower-half by sending commands and receiving responses: | ||
|
|
||
| 1. ``SDIO_SENDCMD``: Send the command (e.g., CMD2, CMD9). |
Contributor
There was a problem hiding this comment.
I believe the call flow is more complex than this.
Contributor
Author
There was a problem hiding this comment.
correct, the original list read like a full call flow, but my intent was to only sketch the minimal interaction around CMD9/R2 and the CSD that the SDIO lower-half must return, however I'll update push them
drivers/mmcsd/mmcsd_sdio.c
Outdated
| * lower-half is responsible for returning the correct 128-bit layout. | ||
| */ | ||
|
|
||
| DEBUGASSERT(csd[0] != 0); |
Contributor
There was a problem hiding this comment.
This is not correct. First , csd[0] is 32 bits, so this doesn't just check that the first byte is 0.
Second, is it ever possible that the first byte (the CRC) is 0 naturally?
Are you able to test this on any targets?
Contributor
Author
There was a problem hiding this comment.
my bad, I have removed the DEBUGASSERT and kept the PR on documenting the R@/CID/CSD expectations for SDIO lower halves
xiaoxiang781216
previously approved these changes
Mar 17, 2026
This update adds comprehensive documentation regarding the 136-bit response format for SDIO, including the structure of the response, CRC handling, and necessary byte-shifting for alignment. This information is crucial for developers implementing or maintaining SDIO drivers. Signed-off-by: Arjav Patel <arjav1528@gmail.com>
This update expands the documentation for implementing an SDIO lower-half driver, detailing the required interface, call-flow, and handling of the R2 response format. It emphasizes the importance of byte-shifting when the CRC is stripped by the hardware, providing reference implementations for clarity. Signed-off-by: Arjav Patel <arjav1528@gmail.com>
…ation This update adds a reference to the SDIO Driver Documentation for implementers of SDIO lower-half drivers, emphasizing the importance of understanding R2/CSD response handling and the correct implementation of the lower-half interface. Signed-off-by: Arjav Patel <arjav1528@gmail.com>
This update clarifies the call-flow for the SDIO lower-half driver implementation by providing a simplified example of the interaction between the MMCSD upper-half and the lower-half. It details the command sequence for handling R2 responses, improving the understanding of the expected behavior during card identification and initialization. Signed-off-by: Arjav Patel <arjav1528@gmail.com>
7616424 to
91ea749
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #17248
Summary
Addressed the issue by documenting how SDIO lower-half drivers must provide R2 (CID/CSD) responses and by adding a small sanity check in the MMCSD upper-half.
include/nuttx/sdio.hnow explains the R2 format, states that the upper-half expects a 128‑bit CID/CSD payload in the standard layout, and notes that controllers which strip the CRC must shift the four 32‑bit words left by one byte (withbcm2711_sdio.candimx9_usdhc.cas examples).mmcsd_decode_csdindrivers/mmcsd/mmcsd_sdio.cgains aDEBUGASSERT(csd[0] != 0);underCONFIG_DEBUG_FEATURESto catch obviously invalid or misaligned CSDs, and the SDIO/MMCSD docs now describe the SDIO lower-half call-flow and R2/CSD expectations and point implementers to this guidance.Impact
DEBUGASSERTinmmcsd_decode_csdis added; there is no behavior or performance change in non‑debug builds.recv_r2/R2 handling (including CRC‑stripping controllers), and MMCSD docs direct SDIO lower‑half implementers there./dev/mmcsd*users is unchanged.Testing
make htmlinDocumentation/to verify the updated RST documentation builds successfully.DEBUGASSERTbehavior is validated by static inspection only.