diff --git a/firmware/config/boards/prometheus/efifeatures.h b/firmware/config/boards/prometheus/efifeatures.h index 5b6024734a..86b3d1a0b1 100644 --- a/firmware/config/boards/prometheus/efifeatures.h +++ b/firmware/config/boards/prometheus/efifeatures.h @@ -32,9 +32,6 @@ #undef EFI_USB_SERIAL #define EFI_USB_SERIAL FALSE -#undef MMC_CARD_SPI -#define MMC_CARD_SPI SPID1 - #define ADC_CHANNEL_VREF ADC_CHANNEL_IN14 #undef PRIMARY_UART_DMA_MODE diff --git a/firmware/config/boards/subaru_eg33/efifeatures.h b/firmware/config/boards/subaru_eg33/efifeatures.h index 54caadde50..08509f49b8 100644 --- a/firmware/config/boards/subaru_eg33/efifeatures.h +++ b/firmware/config/boards/subaru_eg33/efifeatures.h @@ -84,8 +84,7 @@ #undef EFI_FUEL_PUMP #define EFI_FUEL_PUMP TRUE -#undef MMC_CARD_SPI -#define MMC_CARD_SPI SPID1 +#define EFI_SDC_DEVICE SDCD2 #define ADC_CHANNEL_VREF ADC_CHANNEL_IN14 diff --git a/firmware/hw_layer/mmc_card.cpp b/firmware/hw_layer/mmc_card.cpp index c6a982511b..c18fe3f0ad 100644 --- a/firmware/hw_layer/mmc_card.cpp +++ b/firmware/hw_layer/mmc_card.cpp @@ -78,6 +78,7 @@ spi_device_e mmcSpiDevice = SPI_NONE; static THD_WORKING_AREA(mmcThreadStack, 3 * UTILITY_THREAD_STACK_SIZE); // MMC monitor thread +#if HAL_USE_MMC_SPI /** * MMC driver instance. */ @@ -85,6 +86,7 @@ MMCDriver MMCD1; /* MMC/SD over SPI driver configuration.*/ static MMCConfig mmccfg = { NULL, &mmc_ls_spicfg, &mmc_hs_spicfg }; +#endif /* HAL_USE_MMC_SPI */ /** * fatfs MMC/SPI @@ -310,8 +312,15 @@ static void mmcUnMount(void) { } f_close(&FDLogFile); // close file f_sync(&FDLogFile); // sync ALL + +#if HAL_USE_MMC_SPI mmcDisconnect(&MMCD1); // Brings the driver in a state safe for card removal. mmcStop(&MMCD1); // Disables the MMC peripheral. +#endif +#ifdef EFI_SDC_DEVICE + sdcDisconnect(&EFI_SDC_DEVICE); + sdcStop(&EFI_SDC_DEVICE); +#endif f_mount(NULL, 0, 0); // FATFS: Unregister work area prior to discard it memset(&FDLogFile, 0, sizeof(FIL)); // clear FDLogFile setSdCardReady(false); // status = false @@ -343,6 +352,7 @@ void onUsbConnectedNotifyMmcI() { #endif /* HAL_USE_USB_MSD */ +#if HAL_USE_MMC_SPI /* * Attempts to initialize the MMC card. * Returns a BaseBlockDevice* corresponding to the SD card if successful, otherwise nullptr. @@ -377,8 +387,32 @@ static BaseBlockDevice* initializeMmcBlockDevice() { } UNLOCK_SD_SPI; - return (BaseBlockDevice*)&MMCD1; + return reinterpret_cast(&MMCD1); } +#endif /* HAL_USE_MMC_SPI */ + +// Some ECUs are wired for SDIO/SDMMC instead of SPI +#ifdef EFI_SDC_DEVICE +static const SDCConfig sdcConfig = { + SDC_MODE_4BIT +}; + +static BaseBlockDevice* initializeMmcBlockDevice() { + if (!CONFIG(isSdCardEnabled)) { + return nullptr; + } + + sdcStart(&EFI_SDC_DEVICE, &sdcConfig); + sdStatus = SD_STATE_CONNECTING; + if (sdcConnect(&EFI_SDC_DEVICE) != HAL_SUCCESS) { + sdStatus = SD_STATE_NOT_CONNECTED; + warning(CUSTOM_OBD_MMC_ERROR, "Can't connect or mount MMC/SD"); + return nullptr; + } + + return reinterpret_cast(&EFI_SDC_DEVICE); +} +#endif /* EFI_SDC_DEVICE */ // Initialize and mount the SD card. // Returns true if the filesystem was successfully mounted for writing. diff --git a/firmware/hw_layer/ports/rusefi_halconf.h b/firmware/hw_layer/ports/rusefi_halconf.h index f3213e5a95..ba416348b4 100644 --- a/firmware/hw_layer/ports/rusefi_halconf.h +++ b/firmware/hw_layer/ports/rusefi_halconf.h @@ -13,8 +13,20 @@ #define HAL_USE_USB EFI_USB_SERIAL #define HAL_USE_SERIAL_USB EFI_USB_SERIAL -// If EFI_FILE_LOGGING, enable MMC SPI driver -#define HAL_USE_MMC_SPI EFI_FILE_LOGGING +// If EFI_FILE_LOGGING and SDC, enable SDIO/SDMMC driver +#if defined(EFI_SDC_DEVICE) && EFI_FILE_LOGGING + #define HAL_USE_SDC TRUE + #define FATFS_HAL_DEVICE EFI_SDC_DEVICE +#else + #define HAL_USE_SDC FALSE +#endif + +// If EFI_FILE_LOGGING but not SDC, use SPI instead +#if !defined(EFI_SDC_DEVICE) && EFI_FILE_LOGGING + #define HAL_USE_MMC_SPI TRUE +#else + #define HAL_USE_MMC_SPI FALSE +#endif // If USB and File logging, enable USB Mass Storage & community #define HAL_USE_USB_MSD (EFI_FILE_LOGGING && EFI_USB_SERIAL) diff --git a/firmware/hw_layer/ports/stm32/stm32f7/cfg/mcuconf.h b/firmware/hw_layer/ports/stm32/stm32f7/cfg/mcuconf.h index 18e7cf2a70..36ac024ddd 100644 --- a/firmware/hw_layer/ports/stm32/stm32f7/cfg/mcuconf.h +++ b/firmware/hw_layer/ports/stm32/stm32f7/cfg/mcuconf.h @@ -145,13 +145,17 @@ * SDC driver system settings. */ #define STM32_SDC_USE_SDMMC1 FALSE +#define STM32_SDC_USE_SDMMC2 TRUE #define STM32_SDC_SDMMC_UNALIGNED_SUPPORT TRUE #define STM32_SDC_SDMMC_WRITE_TIMEOUT 1000 #define STM32_SDC_SDMMC_READ_TIMEOUT 1000 #define STM32_SDC_SDMMC_CLOCK_DELAY 10 #define STM32_SDC_SDMMC1_DMA_STREAM STM32_DMA_STREAM_ID(2, 3) +#define STM32_SDC_SDMMC2_DMA_STREAM STM32_DMA_STREAM_ID(2, 0) #define STM32_SDC_SDMMC1_DMA_PRIORITY 3 +#define STM32_SDC_SDMMC2_DMA_PRIORITY 3 #define STM32_SDC_SDMMC1_IRQ_PRIORITY 9 +#define STM32_SDC_SDMMC2_IRQ_PRIORITY 9 #include "mcuconf_common_f4_f7.h"