From fbf7be27cdb24b4862d23e86d287ea962a80f5d5 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Mon, 12 Jun 2017 13:58:32 +0200 Subject: [PATCH] trezorhal/usb: add some support for hs-in-fs --- micropython/trezorhal/usb.c | 10 +++++++++- micropython/trezorhal/usbd_conf.c | 23 +++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/micropython/trezorhal/usb.c b/micropython/trezorhal/usb.c index c91fb1a4..89b4e7f5 100644 --- a/micropython/trezorhal/usb.c +++ b/micropython/trezorhal/usb.c @@ -16,6 +16,14 @@ #define USB_MAX_STR_SIZE 62 #define USB_MAX_STR_DESC_SIZE (USB_MAX_STR_SIZE * 2 + 2) +#if defined(USE_USB_FS) +#define USB_PHY_ID USB_PHY_FS_ID +#elif defined(USE_USB_HS) && defined(USE_USB_HS_IN_FS) +#define USB_PHY_ID USB_PHY_HS_ID +#else +#error Unable to determine proper USB_PHY_ID to use +#endif + static usb_device_descriptor_t usb_dev_desc; // Config descriptor @@ -86,7 +94,7 @@ int usb_init(const usb_dev_info_t *dev_info) { // Pointer to interface descriptor data usb_next_iface_desc = (usb_interface_descriptor_t *)(usb_config_buf + usb_config_desc->wTotalLength); - if (0 != USBD_Init(&usb_dev_handle, (USBD_DescriptorsTypeDef*)&usb_descriptors, USB_PHY_FS_ID)) { + if (0 != USBD_Init(&usb_dev_handle, (USBD_DescriptorsTypeDef*)&usb_descriptors, USB_PHY_ID)) { return 1; } if (0 != USBD_RegisterClass(&usb_dev_handle, (USBD_ClassTypeDef*)&usb_class)) { diff --git a/micropython/trezorhal/usbd_conf.c b/micropython/trezorhal/usbd_conf.c index d2179b88..ef25a58c 100644 --- a/micropython/trezorhal/usbd_conf.c +++ b/micropython/trezorhal/usbd_conf.c @@ -698,19 +698,27 @@ void USBD_LL_Delay(uint32_t Delay) *******************************************************************************/ /** - * @brief This function handles USB-On-The-Go FS global interrupt request. + * @brief This function handles USB-On-The-Go FS/HS global interrupt request. * @param None * @retval None */ +#if defined(USE_USB_FS) void OTG_FS_IRQHandler(void) { HAL_PCD_IRQHandler(&pcd_fs_handle); } +#endif +#if defined(USE_USB_HS) +void OTG_HS_IRQHandler(void) { + HAL_PCD_IRQHandler(&pcd_hs_handle); +} +#endif /** * @brief This function handles USB OTG Common FS/HS Wakeup functions. * @param *pcd_handle for FS or HS * @retval None */ +#if defined(USE_USB_FS) || defined(USE_USB_HS) static void OTG_CMD_WKUP_Handler(PCD_HandleTypeDef *pcd_handle) { if (!(pcd_handle->Init.low_power_enable)) { return; @@ -741,17 +749,28 @@ static void OTG_CMD_WKUP_Handler(PCD_HandleTypeDef *pcd_handle) { /* ungate PHY clock */ __HAL_PCD_UNGATE_PHYCLOCK(pcd_handle); } +#endif /** - * @brief This function handles USB OTG FS Wakeup IRQ Handler. + * @brief This function handles USB OTG FS/HS Wakeup IRQ Handler. * @param None * @retval None */ +#if defined(USE_USB_FS) void OTG_FS_WKUP_IRQHandler(void) { OTG_CMD_WKUP_Handler(&pcd_fs_handle); /* Clear EXTI pending Bit*/ __HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG(); } +#endif +#if defined(USE_USB_HS) +void OTG_HS_WKUP_IRQHandler(void) { + OTG_CMD_WKUP_Handler(&pcd_hs_handle); + + /* Clear EXTI pending Bit*/ + __HAL_USB_HS_EXTI_CLEAR_FLAG(); +} +#endif /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/