From 25324ae0e2811d0ea169a7b42222dfc15311f4bb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 7 Oct 2021 12:47:41 +1100 Subject: [PATCH] HAL_ChibiOS: support SDMMC2 for sdcard --- .../hwdef/common/stm32f47_mcuconf.h | 4 ++- .../hwdef/scripts/chibios_hwdef.py | 7 +++++ libraries/AP_HAL_ChibiOS/sdcard.cpp | 29 +++++++++++++------ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/stm32f47_mcuconf.h b/libraries/AP_HAL_ChibiOS/hwdef/common/stm32f47_mcuconf.h index b9620b76b8..84c44b6623 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/stm32f47_mcuconf.h +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/stm32f47_mcuconf.h @@ -476,4 +476,6 @@ // limit ISR count per byte #define STM32_I2C_ISR_LIMIT 6 - +#ifndef STM32_SDC_USE_SDMMC2 +#define STM32_SDC_USE_SDMMC2 FALSE +#endif diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py index deccc30986..65a7a9e38f 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py @@ -706,6 +706,13 @@ def write_mcu_config(f): f.write('#define HAL_USE_SDC TRUE\n') build_flags.append('USE_FATFS=yes') 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'): f.write('// SDMMC available, enable POSIX filesystem support\n') f.write('#define USE_POSIX\n\n') diff --git a/libraries/AP_HAL_ChibiOS/sdcard.cpp b/libraries/AP_HAL_ChibiOS/sdcard.cpp index c01804636f..7e02243000 100644 --- a/libraries/AP_HAL_ChibiOS/sdcard.cpp +++ b/libraries/AP_HAL_ChibiOS/sdcard.cpp @@ -55,10 +55,16 @@ bool sdcard_init() uint8_t sd_slowdown = AP_BoardConfig::get_sdcard_slowdown(); #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 // AP_Logger - bouncebuffer_init(&SDCD1.bouncebuffer, 4096, true); + bouncebuffer_init(&sdcd.bouncebuffer, 4096, true); } if (sdcard_running) { @@ -68,14 +74,14 @@ bool sdcard_init() const uint8_t tries = 3; for (uint8_t i=0; i