HAL_ChibiOS: support SDMMC2 for sdcard

This commit is contained in:
Andrew Tridgell 2021-10-07 12:47:41 +11:00
parent 281b8eb234
commit 25324ae0e2
3 changed files with 30 additions and 10 deletions

View File

@ -476,4 +476,6 @@
// limit ISR count per byte // limit ISR count per byte
#define STM32_I2C_ISR_LIMIT 6 #define STM32_I2C_ISR_LIMIT 6
#ifndef STM32_SDC_USE_SDMMC2
#define STM32_SDC_USE_SDMMC2 FALSE
#endif

View File

@ -706,6 +706,13 @@ def write_mcu_config(f):
f.write('#define HAL_USE_SDC TRUE\n') f.write('#define HAL_USE_SDC TRUE\n')
build_flags.append('USE_FATFS=yes') build_flags.append('USE_FATFS=yes')
env_vars['WITH_FATFS'] = "1" env_vars['WITH_FATFS'] = "1"
elif have_type_prefix('SDMMC2'):
f.write('// SDMMC2 available, enable POSIX filesystem support\n')
f.write('#define USE_POSIX\n\n')
f.write('#define HAL_USE_SDC TRUE\n')
f.write('#define STM32_SDC_USE_SDMMC2 TRUE\n')
build_flags.append('USE_FATFS=yes')
env_vars['WITH_FATFS'] = "1"
elif have_type_prefix('SDMMC'): elif have_type_prefix('SDMMC'):
f.write('// SDMMC available, enable POSIX filesystem support\n') f.write('// SDMMC available, enable POSIX filesystem support\n')
f.write('#define USE_POSIX\n\n') f.write('#define USE_POSIX\n\n')

View File

@ -55,10 +55,16 @@ bool sdcard_init()
uint8_t sd_slowdown = AP_BoardConfig::get_sdcard_slowdown(); uint8_t sd_slowdown = AP_BoardConfig::get_sdcard_slowdown();
#if HAL_USE_SDC #if HAL_USE_SDC
if (SDCD1.bouncebuffer == nullptr) { #if STM32_SDC_USE_SDMMC2 == TRUE
auto &sdcd = SDCD2;
#else
auto &sdcd = SDCD1;
#endif
if (sdcd.bouncebuffer == nullptr) {
// allocate 4k bouncebuffer for microSD to match size in // allocate 4k bouncebuffer for microSD to match size in
// AP_Logger // AP_Logger
bouncebuffer_init(&SDCD1.bouncebuffer, 4096, true); bouncebuffer_init(&sdcd.bouncebuffer, 4096, true);
} }
if (sdcard_running) { if (sdcard_running) {
@ -68,14 +74,14 @@ bool sdcard_init()
const uint8_t tries = 3; const uint8_t tries = 3;
for (uint8_t i=0; i<tries; i++) { for (uint8_t i=0; i<tries; i++) {
sdcconfig.slowdown = sd_slowdown; sdcconfig.slowdown = sd_slowdown;
sdcStart(&SDCD1, &sdcconfig); sdcStart(&sdcd, &sdcconfig);
if(sdcConnect(&SDCD1) == HAL_FAILED) { if(sdcConnect(&sdcd) == HAL_FAILED) {
sdcStop(&SDCD1); sdcStop(&sdcd);
continue; continue;
} }
if (f_mount(&SDC_FS, "/", 1) != FR_OK) { if (f_mount(&SDC_FS, "/", 1) != FR_OK) {
sdcDisconnect(&SDCD1); sdcDisconnect(&sdcd);
sdcStop(&SDCD1); sdcStop(&sdcd);
continue; continue;
} }
printf("Successfully mounted SDCard (slowdown=%u)\n", (unsigned)sd_slowdown); printf("Successfully mounted SDCard (slowdown=%u)\n", (unsigned)sd_slowdown);
@ -140,9 +146,14 @@ void sdcard_stop(void)
f_mount(nullptr, "/", 1); f_mount(nullptr, "/", 1);
#endif #endif
#if HAL_USE_SDC #if HAL_USE_SDC
#if STM32_SDC_USE_SDMMC2 == TRUE
auto &sdcd = SDCD2;
#else
auto &sdcd = SDCD1;
#endif
if (sdcard_running) { if (sdcard_running) {
sdcDisconnect(&SDCD1); sdcDisconnect(&sdcd);
sdcStop(&SDCD1); sdcStop(&sdcd);
sdcard_running = false; sdcard_running = false;
} }
#elif HAL_USE_MMC_SPI #elif HAL_USE_MMC_SPI