Conversation
|
Hardware test update: I tested this change on a flight controller supported by the PX4 community, using an STM32H743 with the SD card connected to SDMMC1. I ran the following tests using the PX4 port of this PR on the flight controller, with firmware based on PX4 My build enables IDMA, a 4096-byte bounce buffer (8 × 512),
For the unaligned 4 KiB test, the printed write/read pointers are Before these changes, I observed approximately 300 KB/s. My current write averages are approximately 3.2–4.2 times that baseline. I do not have the original command, exact configuration or raw baseline log available, so I am treating this as an indicative comparison rather than a controlled before/after benchmark. I am not drawing a performance conclusion from the unaligned run being faster than the ordinary run. All three of my runs completed readback verification without reported verification errors. The 8 KiB test also used D2 write/read pointers ( My test console outputWhitespace normalized. I included the remaining 8 KiB readback output from my follow-up test log. |
5155774 to
9388370
Compare
|
@msli-dev please fix the conflict |
Add an optional maxrequest callback at the end of sdio_dev_s. A zero or unset callback adds no host-specific limit; nonzero values are byte limits that apply to all request buffers. Combine the host limit with MMCSD_MULTIBLOCK_LIMIT when splitting block reads and writes. Reject a host limit smaller than one block and oversized raw multi-block commands before starting the transfer. Cancel receive setup after a failed CMD23, attempt CMD12 after failed open-ended multi-block reads, and propagate stop-command failures. Keep these generic MMC/SD changes separate from the STM32H7 driver. Assisted-by: Codex:GPT-6 Signed-off-by: msli-dev <747640013@qq.com>
Use per-instance aligned buffers for memory that SDMMC IDMA cannot access directly or that does not meet cache alignment requirements. Copy writes before IDMA and copy successful bounced reads in the waiting thread. Report the configured capacity through maxrequest. Keep a positive IDMA RAM allow-list and runtime setup validation. Invalidate only the actual DMA destination, prioritize errors over DATAEND, and stop data access before releasing buffer ownership. Reset an active data path on abort while restoring host bus settings; clear cancellation state and handle immediate/watchdog-start errors. This commit contains the STM32H7 driver and its Kconfig changes only. The preceding commit supplies the common SDIO/MMCSD functionality. Assisted-by: Codex:GPT-6 Signed-off-by: msli-dev <747640013@qq.com>
9388370 to
294c46f
Compare
Summary
STM32H743 SDMMC1 cannot directly DMA to client buffers in D2/D3 SRAM or DTCM. Add optional, per-instance aligned IDMA bounce buffers so these buffers, and unaligned buffers, can use multi-block transfers. Writes are copied before IDMA; successful bounced reads are copied in the waiting thread rather than copying the full request in interrupt context.
Add an optional
sdio_dev_s::maxrequest()callback, returning bytes (zero/unset means no additional host limit). MMC/SD combines the host capacity withCONFIG_MMCSD_MULTIBLOCK_LIMITand splits normal block reads/writes before DMA setup. With eight 512-byte bounce blocks, a 32 KiB request becomes eight 4 KiB host requests.The series is organized into two commits:
44f3bccddf— common SDIO/MMCSD changes: optional host request limit, block splitting, and generic multi-block error cleanup. All changes todrivers/mmcsd/mmcsd_sdio.care in this first commit, together withinclude/nuttx/sdio.handdrivers/mmcsd/Kconfig.294c46fc37— STM32H7 driver and Kconfig changes: per-instance IDMA bounce buffers, cache handling, runtime checks and transfer cleanup. This commit depends on the common interface introduced by the first commit.The upstream ioctl formatting cleanup is retained, so there is no separate formatting-only commit. The rebase also preserves upstream checks of non-DMA RECVSETUP/SENDSETUP return values.
IDMAENis writable only with inactive DPSM. If abort finds an active data state machine, the driver resets that host peripheral and restores its bus configuration before returning buffer ownership. Card-side recovery still requires STOP_TRANSMISSION or reinitialization. See RM0433, SDMMC_IDMACTRLR. The branch is rebased ontoapache/nuttxmaster at8df6e2a3f45bf4a6cef791fb3cf9fb36e34cdb30.Hardware reference: ST AN5200, section 1.1 and Table 2.
Impact
CONFIG_STM32_SDMMC_IDMA_BOUNCE_BUFFER, withCONFIG_STM32_SDMMC_IDMA_BOUNCE_BLOCKS=8by default when enabled. Each enabled SDMMC instance has a separate buffer.-E2BIG; commands are not implicitly split. A host cap smaller than one sector is rejected before normal block I/O, including single-block-only configurations.Testing
Validation after the review update
I rebuilt the first (common-only) commit with
stm32f746-ws:nsh, then rebuilt the complete series withweact-stm32h743:sdcardand the 4 KiB bounce buffer both enabled and disabled. All three builds linked successfully with no compiler warnings using GNU Arm Embedded GCC 10.2.1 and nuttx-apps00b6e59123363d7fc92d0a08cb43f449d438e4bc. Full-filetools/checkpatch.shandgit diff --checkalso pass. These are build checks of the rebased series; the hardware results below remain from the previously tested PX4 port.Build host: Linux x86_64, WSL2 kernel
6.6.114.1-microsoft-standard-WSL2.Compiler: GNU Arm Embedded Toolchain
10.2.1 20201103 (10-2020-q4-major).Apps revision:
apache/nuttx-appsb66303e26aa537dd74d6abaeeeded81c151a7e35.Built in a separate worktree. Full builds used
make olddefconfigandmake -j8.MMCSD_MULTIBLOCK_LIMIT=1MMCSD_MULTIBLOCK_LIMIT=4MMCSD_MULTIBLOCK_LIMIT=16, Debug assertionsstm32f746-ws:nsh, SDMMC1 DMA, no maxrequest callbackExcept for the intentional pre-existing no-IDMA warning, these builds produced no warnings. H743 bounce-enabled builds place
g_sdmmc1_idmabufferat0x24002c20, with size0x1000, in AXI SRAM. Bounce-disabled builds retain a0x200buffer. F7 build linkednuttxand generatednuttx.bin.Local host-side tests compile the actual function bodies extracted from the edited sources with mocked registers, semaphores, watchdogs and lower-level block transfers, using GCC and UndefinedBehaviorSanitizer:
Hardware results: PX4 community flight controller
Hardware test update: I tested this change on a flight controller supported by the PX4 community, using an STM32H743 with the SD card connected to SDMMC1.
I ran the following tests using the PX4 port of this PR on the flight controller, with firmware based on PX4
ea495a418eand its NuttX030417d09b(the console reports NuttX 12.12.0), with this PR's changes through51557742ecadapted to the olderSTM32H7_*configuration names. This is hardware evidence from that port, rather than a standalone upstream NuttX firmware run.My build enables IDMA, a 4096-byte bounce buffer (8 × 512),
MMCSD_MULTIBLOCK_LIMIT=0, and D-cache write-back. Its linked bounce buffer is at0x2400eea0in AXI SRAM, size0x1000.sd_bench -v -b 4096 -r 3 -d 3000sd_bench -U -v -b 4096 -r 3 -d 3000sd_bench -U -v -b 8192 -r 3 -d 3000For the unaligned 4 KiB test, the printed write/read pointers are
0x300170a1and0x300180a9: both are byte-unaligned addresses in D2 SRAM1. Thus the completed file-I/O test exercises D2 caller buffers and reports successful readback verification. The ordinary 4 KiB run does not print an address, so it is not being labeled a verified direct-AXI comparison.Before these changes, I observed approximately 300 KB/s. My current write averages are approximately 3.2–4.2 times that baseline. I do not have the original command, exact configuration or raw baseline log available, so I am treating this as an indicative comparison rather than a controlled before/after benchmark. I am not drawing a performance conclusion from the unaligned run being faster than the ordinary run.
All three of my runs completed readback verification without reported verification errors. The 8 KiB test also used D2 write/read pointers (
0x300170a1/0x300190a9) and completed successfully with the configured 4 KiB host cap. File-system I/O does not by itself prove the exact host-level split pattern. Neighboring-buffer guards, D3/DTCM coverage and timeout/cancellation/card-removal recovery remain outstanding. I am submitting this PR for review.Full console logs: hardware test update.
Review notes
Extend the completed D2 unaligned file-I/O verification with explicit direct-AXI comparison, D3/DTCM coverage, neighboring-memory guards and host-level request-size tracing.
Validate the active-transfer reset/abort timing, card reinitialization if necessary, and next-request recovery after timeout, cancellation and card removal. Model tests cannot establish those hardware properties.
Measure direct versus bounced multi-block performance and the cost of the global request cap.
This build matrix does not establish support for every H7 family or board, or on-board SDMMC2 behavior.
The commits include
Signed-off-byand retain theAssisted-byattribution.Software cleanup and request-boundary fixes implemented and locally tested.
PR is ready for review.
H743/SDMMC1 PX4-port file-I/O verification completed for 4 KiB, unaligned 4 KiB and unaligned 8 KiB buffers.
Remaining hardware recovery, guard-buffer and coverage validation complete.
PR is ready to merge.