Skip to content

Commit

Permalink
USB Device driver: correct PMA configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
MiloradCvjetkovic committed Nov 7, 2024
1 parent b10490b commit 8d81e2c
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions Drivers/USBD_STM32.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* -----------------------------------------------------------------------------
*
* $Date: 5. November 2024
* $Date: 7. November 2024
* $Revision: V3.1
*
* Project: USB Device Driver for STMicroelectronics STM32 devices
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8d81e2c

Please sign in to comment.