Repository navigation
Fix SPI SD single-sector write busy wait and sdWait idle check - #3092
Open
pingequalab wants to merge 1 commit into
Open
pingequalab wants to merge 1 commit into
pingequalab wants to merge 1 commit into
Conversation
After clocking MISO release in sdDeselectCard(), re-selecting CS during internal NAND programming can return an initial non-zero transition byte before the card drives DO low. Require two 0xFF samples in sdWait(), release MISO via sdDeselectCard() on sdSelectCard() timeout, and wait for programming completion while CS is held low in sdWriteSector(). Verified: pio run -e m5stack-sticks3 (exit 0); 20/20 shared-SPI + multi/single-sector MD5/CRC32 hardware stress rounds (exit 0).
This branch has not been deployed
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.
Summary
Follow-up to #3082 (
fefc13b). Fixes silent single-sector / tail-sector write drops (CMD24/sdWriteSector()) and prematuresdWait()return on shared-SPI / pulled-upMISObuses inlib/HAL/sd_card/sd_diskio.cpp.(#3082 was merged into
devshortly before our 20-round byte-level MD5 single-sector hardware stress test finished; this PR submits the companion busy-wait fix6beb4aecaught and verified by that stress suite.)Hardware Tested
m5stack-sticks3with external shared-SPI module (CC1101+NRF24+32GB MicroSDsharingSCK=5, MISO=4, MOSI=6), verified under both USB power and standalone internal battery power.lib/HAL/sd_card/sd_diskio.cpp.Root Cause
0xFFclock insdDeselectCard()so the SD card properly releasesDAT0/MISOto pulled-up0xFF(1 kOhmpull-up on the shared SPI bus),sdWriteSector()(CMD24) still deassertedCSimmediately after reading the data-response token (0x05) without waiting for internal NAND programming to finish.sdTransaction(SEND_STATUS)(CMD13) re-assertedCSand calledsdWait(pdrv, 500). BecausesdWait()previously exited as soon as a single byte was non-zero (while (resp == 0x00)with signedchar resp, returningresp > 0x00), the initial non-zeroN_CStransition byte sampled on the pulled-upMISOline before the card droveDOlow (0x00busy) causedsdWait()to returntrueprematurely.CMD13/CMD24commands collided with active NAND programming, silently dropping<512 Bfiles, tail sectors, and directory-entry updates without logging an error.Changes (
lib/HAL/sd_card/sd_diskio.cpp)sdWait(): Useuint8_t respand require two0xFFidle bytes (resp == 0xFF && ++ff_count == 2) before returningtrue, so an initialN_CStransition byte afterCSassertion cannot prematurely pass a busy check.sdSelectCard(): CallsdDeselectCard(pdrv)instead of rawdigitalWrite(card->ssPin, HIGH)onsdWait()timeout soMISOis cleanly clocked to Hi-Z.sdWriteSector()(CMD24): Checkuint8_t token == 0x05(deselecting and retrying on0x0A/0x0BCRC error), callsdWait(pdrv, 500)whileCSis still heldLOWbeforesdDeselectCard(pdrv)(matching multi-sectorsdWriteSectors()/CMD25), and initializeunsigned int resp = 0.Verification
pio run -e m5stack-sticks3->SUCCESS(RAM: 40.2% / 131,748 B,Flash: 56.5% / 4,736,991 B).OVERALL=PASS | S0=True | S1_PureSD=5/5 | S2_Stress=15/15 | Clean=True):S0 + S1 (5 rounds): Multi-sector (CMD25) + tail single-sector (CMD24) writes (2,880 B&1,920 B), byte-level MD5 verification, 12-sector golden reference CRC32 readback, and directory-entryremove->5/5 PASS,0SPI/SD errors.S2 (15 rounds): Continuous shared-SPI switching acrossCC1101 RSSI Spectrum->NRF24 80-ch 10MHz Spectrum->UI Files -> SD Carddirectory browse -> dynamic multi/single-sector SD write + MD5 + 12-sector CRC32 +remove->15/15 PASS,0Card Failed/Select Failed/Wait Failed, stable heap (113,219 B -> 111,123 B) and PSRAM (8,370,212 B -> 8,370,212 B).PASS.