Commit 34676ad
committed
fix(sdcard): migrate dmaInit() to ownership-checked dmaAllocate()
sdcard.c (SPI-mode) and sdio_f4xx.c/sdio_f7xx.c (SDIO-mode) called
dmaInit(), which silently overwrites any existing DMA owner. Replace
with dmaAllocate() + dmaEnable(), matching the pattern already used
by ADC, transponder, LED strip, and motors.
sdcard.c falls back to polled SPI (clearing useDMAForTx) on claim
failure instead of aborting card init entirely -- useDMAForTx is
already checked as a runtime gate at every transfer/completion site,
so this is a supported fallback, not a new code path. Losing DMA
acceleration is preferable to losing the SD card (and blackbox
logging) over an unrelated DMA conflict.
sdio_f4xx.c/sdio_f7xx.c change SD_Initialize_LL() from void to bool,
matching BF's return type, with the claim check moved to the very
top before any RCC/GPIO/DMA register access. sdio_h7xx.c's no-op
stub (H7 uses internal IDMA) is now bool too, matching BF exactly.
The claim intentionally resolves the DMA identifier from the `dma`
parameter, not a file-scope static -- BF 4.5-maintenance's own
equivalent computes it from a stale static assigned only after the
check, making dmaAllocate() operate on an invalid identifier and the
function always return false. That bug was fixed in BF master
(PR#14990, function since renamed SD_InitialiseHardware) as a side
effect of an unrelated DMA-API refactor, not a targeted fix. Not
filed upstream per explicit instruction; tracked in
BF45-SDIO-DMASTREAM-BUG.md instead.
Two callers (usbd_storage_sdio.c, sdcard_sdio_baremetal.c) previously
ignored SD_Initialize_LL()'s return value entirely. Since neither
caller configures the DMA stream itself, a claim failure would leave
the file-scope dma_stream pointer NULL, and the first real card
transfer would dereference it in SD_StartBlockTransfert() -- both
callers now check the return and bail to SDCARD_STATE_NOT_PRESENT
(or an equivalent failure return) instead.
sdcard_init() and SD_Initialize_LL() can each be called twice per
boot (once from fc_init.c, once from the USB MSC passthrough path)
for the same logical OWNER_SDCARD. Added sdcardDmaClaim()/
sdioDmaClaim(), matching the existing uartDmaClaim()/dshotDmaClaim()
pattern: a stream already held by the same owner+resourceIndex is
treated as an already-successful claim, so the second call is not
mistaken for a real conflict.1 parent a4ca6ad commit 34676ad
7 files changed
Lines changed: 58 additions & 14 deletions
File tree
- src/main
- drivers
- msc
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
473 | 473 | | |
474 | 474 | | |
475 | 475 | | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
476 | 485 | | |
477 | 486 | | |
478 | 487 | | |
| |||
489 | 498 | | |
490 | 499 | | |
491 | 500 | | |
| 501 | + | |
492 | 502 | | |
493 | | - | |
| 503 | + | |
494 | 504 | | |
495 | | - | |
496 | | - | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
497 | 512 | | |
498 | 513 | | |
499 | 514 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
289 | | - | |
| 289 | + | |
290 | 290 | | |
291 | | - | |
| 291 | + | |
292 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
293 | 297 | | |
294 | 298 | | |
295 | 299 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1305 | 1305 | | |
1306 | 1306 | | |
1307 | 1307 | | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
1308 | 1317 | | |
1309 | 1318 | | |
1310 | 1319 | | |
1311 | 1320 | | |
1312 | | - | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
1313 | 1326 | | |
1314 | 1327 | | |
1315 | 1328 | | |
| |||
1362 | 1375 | | |
1363 | 1376 | | |
1364 | 1377 | | |
1365 | | - | |
1366 | 1378 | | |
1367 | 1379 | | |
1368 | 1380 | | |
| |||
1375 | 1387 | | |
1376 | 1388 | | |
1377 | 1389 | | |
1378 | | - | |
1379 | 1390 | | |
1380 | 1391 | | |
| 1392 | + | |
1381 | 1393 | | |
1382 | 1394 | | |
1383 | 1395 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1326 | 1326 | | |
1327 | 1327 | | |
1328 | 1328 | | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
1329 | 1338 | | |
1330 | 1339 | | |
1331 | 1340 | | |
1332 | 1341 | | |
1333 | | - | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
1334 | 1347 | | |
1335 | 1348 | | |
1336 | 1349 | | |
| |||
1386 | 1399 | | |
1387 | 1400 | | |
1388 | 1401 | | |
1389 | | - | |
1390 | 1402 | | |
1391 | 1403 | | |
1392 | 1404 | | |
| |||
1399 | 1411 | | |
1400 | 1412 | | |
1401 | 1413 | | |
1402 | | - | |
1403 | 1414 | | |
1404 | 1415 | | |
| 1416 | + | |
1405 | 1417 | | |
1406 | 1418 | | |
1407 | 1419 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
734 | 734 | | |
735 | 735 | | |
736 | 736 | | |
737 | | - | |
| 737 | + | |
738 | 738 | | |
739 | 739 | | |
| 740 | + | |
740 | 741 | | |
741 | 742 | | |
742 | 743 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
219 | | - | |
| 219 | + | |
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
| 155 | + | |
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| |||
0 commit comments