diff --git a/Drivers/USBD_STM32.c b/Drivers/USBD_STM32.c index d85c6e4..9e3286e 100644 --- a/Drivers/USBD_STM32.c +++ b/Drivers/USBD_STM32.c @@ -17,7 +17,7 @@ * * ----------------------------------------------------------------------------- * - * $Date: 5. November 2024 + * $Date: 7. November 2024 * $Revision: V3.1 * * Project: USB Device Driver for STMicroelectronics STM32 devices @@ -554,38 +554,38 @@ static int32_t USBDn_EndpointConfigureBuffer (const RO_Info_t * const ptr_ro_inf req_ep = 0U; pcd_addr = ptr_ro_info->ptr_hpcd->Init.dev_endpoints * 8U; // Offset start address for BTABLE for (ep_num = 0U; ep_num < ptr_ro_info->ptr_hpcd->Init.dev_endpoints; ep_num++) { - // IN Endpoint - if (HAL_PCDEx_PMAConfig(ptr_ro_info->ptr_hpcd, 0x80U | ep_num, PCD_SNG_BUF, pcd_addr) != HAL_OK) { + // OUT Endpoint + if (HAL_PCDEx_PMAConfig(ptr_ro_info->ptr_hpcd, ep_num, PCD_SNG_BUF, pcd_addr) != HAL_OK) { return ARM_DRIVER_ERROR_PARAMETER; } - if (ep_addr == (0x80U | ep_num)) { // If this is the requested endpoint (max_packet_size is not in the structure yet) + if (ep_addr == ep_num) { // If this is the requested endpoint (max_packet_size is not in the structure yet) req_ep = 1U; max_packet_size = ep_max_packet_size; } else { // If this is not the requested endpoint (max_packet_size is in the structure) - max_packet_size = ptr_ro_info->ptr_rw_info->ep_info[ep_num][EP_IN_INDEX].max_packet_size; + max_packet_size = ptr_ro_info->ptr_rw_info->ep_info[ep_num][EP_OUT_INDEX].max_packet_size; } pcd_addr += ((max_packet_size + 3U) / 4U) * 4U; // To refresh the PMA configuration the endpoint has to be opened - if ((req_ep != 0U) && (ptr_ro_info->ptr_rw_info->ep_info[ep_num][EP_IN_INDEX].configured != 0U)) { - (void)HAL_PCD_EP_Open(ptr_ro_info->ptr_hpcd, ep_num | 0x80U, ep_max_packet_size, ep_type); + if ((ep_addr != ep_num) && (req_ep != 0U) && (ptr_ro_info->ptr_rw_info->ep_info[ep_num][EP_OUT_INDEX].configured != 0U)) { + (void)HAL_PCD_EP_Open(ptr_ro_info->ptr_hpcd, ep_num, ep_max_packet_size, ep_type); } - // OUT Endpoint - if (HAL_PCDEx_PMAConfig(ptr_ro_info->ptr_hpcd, ep_num, PCD_SNG_BUF, pcd_addr) != HAL_OK) { + // IN Endpoint + if (HAL_PCDEx_PMAConfig(ptr_ro_info->ptr_hpcd, 0x80U | ep_num, PCD_SNG_BUF, pcd_addr) != HAL_OK) { return ARM_DRIVER_ERROR_PARAMETER; } - if (ep_addr == ep_num) { // If this is the requested endpoint (max_packet_size is not in the structure yet) + if (ep_addr == (0x80U | ep_num)) { // If this is the requested endpoint (max_packet_size is not in the structure yet) req_ep = 1U; max_packet_size = ep_max_packet_size; } else { // If this is not the requested endpoint (max_packet_size is in the structure) - max_packet_size = ptr_ro_info->ptr_rw_info->ep_info[ep_num][EP_OUT_INDEX].max_packet_size; + max_packet_size = ptr_ro_info->ptr_rw_info->ep_info[ep_num][EP_IN_INDEX].max_packet_size; } pcd_addr += ((max_packet_size + 3U) / 4U) * 4U; // To refresh the PMA configuration the endpoint has to be opened - if ((req_ep != 0U) && (ptr_ro_info->ptr_rw_info->ep_info[ep_num][EP_OUT_INDEX].configured != 0U)) { - (void)HAL_PCD_EP_Open(ptr_ro_info->ptr_hpcd, ep_num, ep_max_packet_size, ep_type); + if ((ep_addr != (0x80U | ep_num)) && (req_ep != 0U) && (ptr_ro_info->ptr_rw_info->ep_info[ep_num][EP_IN_INDEX].configured != 0U)) { + (void)HAL_PCD_EP_Open(ptr_ro_info->ptr_hpcd, ep_num | 0x80U, ep_max_packet_size, ep_type); } } #endif