2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
29 #include "pg/pg_ids.h"
32 #include "drivers/bus_spi.h"
33 #include "drivers/io.h"
34 #include "drivers/dma.h"
35 #include "drivers/dma_reqmap.h"
37 PG_REGISTER_WITH_RESET_FN(sdcardConfig_t
, sdcardConfig
, PG_SDCARD_CONFIG
, 2);
39 void pgResetFn_sdcardConfig(sdcardConfig_t
*config
)
41 config
->cardDetectTag
= IO_TAG(SDCARD_DETECT_PIN
);
42 config
->cardDetectInverted
= SDCARD_DETECT_IS_INVERTED
;
44 // We can safely handle SPI and SDIO cases separately on custom targets, as these are exclusive per target.
45 // On generic targets, SPI has precedence over SDIO; SDIO must be post-flash configured.
46 config
->device
= SPI_DEV_TO_CFG(SPIINVALID
);
48 #ifdef CONFIG_IN_SDCARD
49 // CONFIG_ID_SDDCARD requires a default mode.
50 #if defined(USE_SDCARD_SDIO)
51 config
->mode
= SDCARD_MODE_SDIO
;
52 #elif defined(USE_SDCARD_SPI)
53 config
->mode
= SDCARD_MODE_SPI
;
56 config
->mode
= SDCARD_MODE_NONE
;
59 #if defined(STM32H7) && defined(USE_SDCARD_SDIO) // H7 only for now, likely should be applied to F4/F7 too
60 config
->mode
= SDCARD_MODE_SDIO
;
64 // These settings do not work for Unified Targets
65 // They are only left in place to support legacy targets
66 SPIDevice spidevice
= spiDeviceByInstance(SDCARD_SPI_INSTANCE
);
67 config
->device
= SPI_DEV_TO_CFG(spidevice
);
68 config
->chipSelectTag
= IO_TAG(SDCARD_SPI_CS_PIN
);
70 if (spidevice
!= SPIINVALID
&& config
->chipSelectTag
) {
71 config
->mode
= SDCARD_MODE_SPI
;