From f7d3969116f4efe9bb1b49aff9ec0b7617a4f17f Mon Sep 17 00:00:00 2001 From: bugobliterator Date: Fri, 26 May 2023 17:03:30 +1000 Subject: [PATCH] AP_HAL_ChibiOS: enable write protection on USB msd also fixes support for MSD on FS --- libraries/AP_HAL_ChibiOS/hwdef/common/board.c | 9 --------- .../AP_HAL_ChibiOS/hwdef/common/usbcfg_cdc_msd.c | 4 ++++ .../AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py | 3 +++ libraries/AP_HAL_ChibiOS/sdcard.cpp | 13 +++++++++++++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/board.c b/libraries/AP_HAL_ChibiOS/hwdef/common/board.c index 0e0424f123..9a244f807e 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/board.c +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/board.c @@ -304,15 +304,6 @@ bool sdc_lld_is_card_inserted(SDCDriver *sdcp) { (void)sdcp; return true; } - -/** - * @brief SDC card write protection detection. - */ -bool sdc_lld_is_write_protected(SDCDriver *sdcp) { - - (void)sdcp; - return false; -} #endif /* HAL_USE_SDC */ #if HAL_USE_MMC_SPI || defined(__DOXYGEN__) diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/usbcfg_cdc_msd.c b/libraries/AP_HAL_ChibiOS/hwdef/common/usbcfg_cdc_msd.c index e81af62e07..aac9f720a4 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/usbcfg_cdc_msd.c +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/usbcfg_cdc_msd.c @@ -27,7 +27,11 @@ /* * must be 64 for full speed and 512 for high speed */ +#if STM32_USB_HS #define USB_MSD_EP_SIZE 512U +#else +#define USB_MSD_EP_SIZE 64U +#endif #define USB_DATA_REQUEST_EP 2 #define USB_DATA_AVAILABLE_EP 2 #define USB_INTERRUPT_REQUEST_EP 3 diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py index 3770f7348f..7eafa8d79e 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py @@ -929,11 +929,14 @@ class ChibiOSHWDef(object): f.write('#define STM32_OTG2_IS_OTG1 FALSE\n') f.write('#define HAL_USE_USB TRUE\n') f.write('#define HAL_USE_SERIAL_USB TRUE\n') + f.write('#define STM32_USB_HS FALSE\n') if 'OTG2' in self.bytype: f.write('#define STM32_USB_USE_OTG2 TRUE\n') + f.write('#define STM32_USB_HS FALSE\n') if 'OTG_HS' in self.bytype: f.write('#define STM32_OTG2_IS_OTG1 FALSE\n') f.write('#define STM32_USB_USE_OTG2 TRUE\n') + f.write('#define STM32_USB_HS TRUE\n') f.write('#define HAL_USE_USB TRUE\n') f.write('#define HAL_USE_SERIAL_USB TRUE\n') f.write('#define BOARD_OTG2_USES_ULPI\n') diff --git a/libraries/AP_HAL_ChibiOS/sdcard.cpp b/libraries/AP_HAL_ChibiOS/sdcard.cpp index 65bb19107c..92b70c9206 100644 --- a/libraries/AP_HAL_ChibiOS/sdcard.cpp +++ b/libraries/AP_HAL_ChibiOS/sdcard.cpp @@ -30,13 +30,16 @@ extern const AP_HAL::HAL& hal; #if HAL_HAVE_USB_CDC_MSD +bool write_protected = false; static void block_filesys_access() { AP::FS().block_access(); + write_protected = true; } static void free_filesys_access() { + write_protected = false; AP::FS().free_access(); } #endif @@ -193,6 +196,16 @@ bool sdcard_init() return false; } +#if HAL_USE_SDC +bool sdc_lld_is_write_protected(SDCDriver *sdcp) { +#if HAL_HAVE_USB_CDC_MSD + return write_protected; +#else + return false; +#endif +} +#endif + /* stop sdcard interface (for reboot) */