Fix H743 USB MSC regression and SDIO reliability issues#11194
Merged
sensei-hacker merged 3 commits intoiNavFlight:maintenance-9.xfrom Dec 21, 2025
Merged
Conversation
Issue: USB Mass Storage mode broken on H743 in INAV 8.0.1+ due to USB library update v2.5.3 → v2.11.3. Windows shows 'Virtual COM Port in FS Mode' error instead of enumerating MSC device. Root Cause: H7 MSC initialization used VCP_Desc (CDC descriptor) then added MSC class. New USB library interprets this as composite mode but INAV wasn't configured for composite, causing descriptor conflicts that Windows rejects. Solution: Standalone MSC Mode (not composite) - Created MSC_Desc descriptor structure for pure MSC device - MSC mode now uses MSC descriptors (device class 0x00, PID 22314) - Normal VCP mode unchanged (still uses VCP_Desc) - No CDC functionality during MSC mode - Simpler than composite mode, no API changes needed Changes: - src/main/vcp_hal/usbd_desc.c: Add MSC_Desc and descriptor functions - src/main/vcp_hal/usbd_desc.h: Export MSC_Desc - src/main/drivers/usb_msc_h7xx.c: Use MSC_Desc instead of VCP_Desc Testing Results: ✅ USB enumeration works on Linux ✅ Device detected as 'STM32 Mass Storage in FS Mode' ✅ SCSI device created (sda) ✅ Size detected correctly (31.3 GB)⚠️ Requires SD card inserted for storage backend to work Benefits: - Normal VCP operation completely unaffected - MSC mode enumerates properly on Windows/Linux - No composite mode complexity - Matches F4 architecture (MSC-only mode) References: - Issue: iNavFlight#10800
This commit fixes two critical issues with H7 SDIO SD card access: 1. **USB MSC alignment bug**: H7 SDIO DMA requires 32-byte aligned buffers, but the USB MSC library's bot_data buffer is only 16-byte aligned. This caused all USB MSC read/write operations to fail with SD_ADDR_MISALIGNED errors. Fix: Use an aligned intermediate buffer for H7+SDIO in USB MSC mode. 2. **Aggressive error handling**: Any SDIO DMA failure immediately triggered a full card reset, causing recording gaps and reliability issues. This was particularly problematic when USB interrupts interfered with SDIO DMA. Fix: Retry operations up to 3 times with 1ms delays before resetting card. Technical details: - Added __attribute__((aligned(32))) buffer for H7 USB MSC SDIO operations - Added operationRetries counter and SDCARD_MAX_OPERATION_RETRIES constant - Both read and write paths now retry transient failures - Retry counter reset on successful operations and card init This should significantly improve H7 SDIO reliability for both blackbox logging and USB mass storage mode. Fixes iNavFlight#10800
Contributor
|
You are nearing your monthly Qodo Merge usage quota. For more information, please visit here. PR Compliance Guide 🔍All compliance sections have been disabled in the configurations. |
Implements Qodo bot suggestion to prevent infinite hangs if SD card becomes unresponsive during USB MSC operations. Changes: - Added 5-second timeout to all polling loops in STORAGE_Read() - Added 5-second timeout to all polling loops in STORAGE_Write() - Returns error (-1) to USB host if timeout occurs - Timeout applies to both 'waiting for operation to start' and 'waiting for operation to complete' phases This prevents system hangs when: - SD card becomes unresponsive - SDIO DMA completion interrupts are blocked - Card is removed during operation Timeout is generous (5 seconds per block) to handle slow cards while still providing protection against total system freeze.
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.
User description
Summary
Fixes USB Mass Storage mode on H743 boards and improves SDIO SD card reliability.
Problem Statement
USB MSC mode is broken on H743 flight controllers in INAV 8.0.1+:
Root Causes Identified
1. USB Descriptor Mismatch
The USB library update (v2.5.3 → v2.11.3) in commit 16ebb27 introduced stricter descriptor requirements. H7 MSC mode was attemtpoing to use composite mode with both mass storage (MSC) and CDC (VCP) descriptors, but that failed because the HAL changed between 2018 and 2024. This caused Windows enumeration to fail.
2. SDIO DMA Alignment Requirements
H7 SDIO DMA requires 32-byte aligned buffers, but the USB MSC library's
bot_databuffer is only 16-byte aligned (at offset 16 in the structure). This caused USB MSC read operations to fail withSD_ADDR_MISALIGNEDerrors.3. Aggressive Error Handling
Any SDIO operation failure immediately triggered a full card reset, causing recording gaps. This was also problematic when USB interrupts interfered with SDIO DMA completion.
Changes
USB MSC Descriptor Fix (
src/main/vcp_hal/usbd_desc.c,usbd_desc.h)MSC_Desc) separate from VCP descriptorsMSC_Descinstead ofVCP_DescSDIO DMA Alignment Fix (
src/main/msc/usbd_storage_sd_spi.c)STORAGE_Read()andSTORAGE_Write()to copy data through aligned buffer#if defined(STM32H7) && defined(USE_SDCARD_SDIO)Retry Logic (
src/main/drivers/sdcard/sdcard_impl.h,sdcard_sdio.c)operationRetriescounter to sdcard state structureTesting
Technical Details
#ifndef STM32F7)Benefits
Platform Impact
Fixes
Closes #10800
Related Issues
PR Type
Bug fix, Enhancement
Description
This description is generated by an AI tool. It may have inaccuracies
Fix H743 USB MSC regression by using standalone MSC descriptors instead of VCP descriptors
Add 32-byte aligned intermediate buffer for H7 SDIO DMA operations
Implement retry logic for transient SDIO operation failures
Improve SD card initialization with timeout and existing state checks
Diagram Walkthrough
File Walkthrough
sdcard_impl.h
Add operation retry counter to SD card statesrc/main/drivers/sdcard/sdcard_impl.h
SDCARD_MAX_OPERATION_RETRIESconstant set to 3operationRetriesfield to sdcard state structure to track retryattempts
sdcard_sdio.c
Add retry logic for transient SDIO failuressrc/main/drivers/sdcard/sdcard_sdio.c
sdcardSdio_writeBlock()with 1ms delaysbefore card reset
sdcardSdio_readBlock()with same retrymechanism
sdcardSdio_init()usbd_desc.c
Add standalone MSC descriptor structure and callbackssrc/main/vcp_hal/usbd_desc.c
MSC_Descdescriptor structure for standalone MSC modeproduct, config, and interface strings
number
USE_USB_MSCguard
usbd_desc.h
Export MSC descriptor for USB MSC modesrc/main/vcp_hal/usbd_desc.h
MSC_Descdescriptor structure for use in USB MSCinitialization
usb_msc_h7xx.c
Use MSC descriptor for H7 USB MSC modesrc/main/drivers/usb_msc_h7xx.c
VCP_DesctoMSC_Descforstandalone MSC mode
USB library v2.11.3
usbd_storage_sd_spi.c
Add aligned buffer for H7 SDIO DMA operationssrc/main/msc/usbd_storage_sd_spi.c
STORAGE_Read()to copy data through aligned buffer on H7 SDIOSTORAGE_Write()to copy data through aligned buffer on H7SDIO
STORAGE_Init()with timeout and existing initializationchecks
string.handdrivers/time.h