diff options
| author | Damien George <damien.p.george@gmail.com> | 2018-05-28 10:46:49 +1000 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2018-05-28 21:45:46 +1000 |
| commit | aa4a7a8732a8594c932503b50152f8e60053e498 (patch) | |
| tree | 7c28259799942ccbc675410114257767943082ff | |
| parent | ef4c8e6e971da0aa40d555f6875003290d1d4c3f (diff) | |
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.
| -rw-r--r-- | ports/stm32/stm32_it.c | 4 | ||||
| -rw-r--r-- | ports/stm32/usbd_cdc_interface.c | 4 | ||||
| -rw-r--r-- | ports/stm32/usbd_conf.c | 4 | ||||
| -rw-r--r-- | ports/stm32/usbdev/class/src/usbd_cdc_msc_hid.c | 4 |
4 files changed, 16 insertions, 0 deletions
diff --git a/ports/stm32/stm32_it.c b/ports/stm32/stm32_it.c index d2cd0788a..b7124de89 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 4c464dbf3..91ae81bb3 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 7829dcce6..41a835304 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 b75e5d0c5..c5aac037d 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 |
