From aa4a7a8732a8594c932503b50152f8e60053e498 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 28 May 2018 10:46:49 +1000 Subject: [PATCH] stm32/usb: Guard USB device code with #if for whether USB is enabled. With this change, all the USB source code can now be passed through the compiler even if the MCU does not have a USB peripheral. --- ports/stm32/stm32_it.c | 4 ++++ ports/stm32/usbd_cdc_interface.c | 4 ++++ ports/stm32/usbd_conf.c | 4 ++++ ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/ports/stm32/stm32_it.c b/ports/stm32/stm32_it.c index d2cd0788a4..b7124de894 100644 --- a/ports/stm32/stm32_it.c +++ b/ports/stm32/stm32_it.c @@ -84,8 +84,12 @@ #include "usb.h" extern void __fatal_error(const char*); +#if defined(MICROPY_HW_USB_FS) extern PCD_HandleTypeDef pcd_fs_handle; +#endif +#if defined(MICROPY_HW_USB_HS) extern PCD_HandleTypeDef pcd_hs_handle; +#endif /******************************************************************************/ /* Cortex-M4 Processor Exceptions Handlers */ diff --git a/ports/stm32/usbd_cdc_interface.c b/ports/stm32/usbd_cdc_interface.c index 4c464dbf33..91ae81bb32 100644 --- a/ports/stm32/usbd_cdc_interface.c +++ b/ports/stm32/usbd_cdc_interface.c @@ -45,6 +45,8 @@ #include "lib/utils/interrupt_char.h" #include "irq.h" +#if MICROPY_HW_ENABLE_USB + // CDC control commands #define CDC_SEND_ENCAPSULATED_COMMAND 0x00 #define CDC_GET_ENCAPSULATED_RESPONSE 0x01 @@ -360,3 +362,5 @@ int usbd_cdc_rx(usbd_cdc_itf_t *cdc, uint8_t *buf, uint32_t len, uint32_t timeou // Success, return number of bytes read return len; } + +#endif diff --git a/ports/stm32/usbd_conf.c b/ports/stm32/usbd_conf.c index 7829dcce68..41a8353047 100644 --- a/ports/stm32/usbd_conf.c +++ b/ports/stm32/usbd_conf.c @@ -35,6 +35,8 @@ #include "irq.h" #include "usb.h" +#if MICROPY_HW_USB_FS || MICROPY_HW_USB_HS + #if MICROPY_HW_USB_FS PCD_HandleTypeDef pcd_fs_handle; #endif @@ -663,4 +665,6 @@ void USBD_LL_Delay(uint32_t Delay) { HAL_Delay(Delay); } +#endif // MICROPY_HW_USB_FS || MICROPY_HW_USB_HS + /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c b/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c index b75e5d0c54..c5aac037d3 100644 --- a/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c +++ b/ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c @@ -28,6 +28,8 @@ #include "usbd_ioreq.h" #include "usbd_cdc_msc_hid.h" +#if MICROPY_HW_ENABLE_USB + #define MSC_TEMPLATE_CONFIG_DESC_SIZE (32) #define MSC_TEMPLATE_MSC_DESC_OFFSET (9) #define CDC_TEMPLATE_CONFIG_DESC_SIZE (67) @@ -1312,3 +1314,5 @@ const USBD_ClassTypeDef USBD_CDC_MSC_HID = { USBD_CDC_MSC_HID_GetCfgDesc, USBD_CDC_MSC_HID_GetDeviceQualifierDescriptor, }; + +#endif