在 CubeMX 生成的项目中,PCD_EP_TX_ADDRESS 定义在哪里?

In a CubeMX-generated project, where is PCD_EP_TX_ADDRESS defined?

我需要使用 stm32f3xx_hal_pcd.h 中的宏 PCD_GET_EP_TX_ADDRESS

定义为:

#define PCD_GET_EP_TX_ADDRESS(USBx, bEpNum) ((uint16_t)*PCD_EP_TX_ADDRESS((USBx), (bEpNum)))

但使用它会导致编译错误,因为 PCD_EP_TX_ADDRESS 未定义。

我已经对整个项目和字符串 PCD_EP_TX_ADDRESS 进行了 grep,结果为:

fadedbee@host:~/cubeide/f3-hid$ grep -R "PCD_EP_TX_ADDRESS" *
Binary file Debug/Middlewares/ST/STM32_USB_Device_Library/Class/HID/Src/usbd_hid.o matches
Binary file Debug/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.o matches
Binary file Debug/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.o matches
Binary file Debug/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.o matches
Binary file Debug/USB_DEVICE/App/usb_device.o matches
Binary file Debug/USB_DEVICE/App/usbd_desc.o matches
Binary file Debug/USB_DEVICE/Target/usbd_conf.o matches
Binary file Debug/Core/Src/stm32f3xx_it.o matches
Binary file Debug/Core/Src/system_stm32f3xx.o matches
Binary file Debug/Core/Src/main.o matches
Binary file Debug/Core/Src/stm32f3xx_hal_msp.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_i2c.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_spi_ex.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_gpio.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_uart.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_flash_ex.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_i2c_ex.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_flash.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_pcd_ex.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_pwr.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_tim.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_tim_ex.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_dma.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_spi.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_uart_ex.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_cortex.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_rcc.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_rcc_ex.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_pwr_ex.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_pcd.o matches
Binary file Debug/Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_exti.o matches
Drivers/STM32F3xx_HAL_Driver/Inc/stm32f3xx_hal_pcd.h:#define PCD_GET_EP_TX_ADDRESS(USBx, bEpNum) ((uint16_t)*PCD_EP_TX_ADDRESS((USBx), (bEpNum)))

该字符串出现在许多目标文件中,表明它是在某个位置定义的。

PCD_EP_TX_ADDRESS定义在哪里?

好像是在stm32f3xx_hal_pcd_ex.h里面声明的。

#define PCD_EP_TX_ADDRESS(USBx, bEpNum) ((uint16_t *)((uint32_t)((((USBx)->BTABLE+(bEpNum)*8)*2+     ((uint32_t)(USBx) + 0x400U)))))

它可能没有包含在 CubeMX 中,因为 CubeMX 有时很糟糕。尽管在导出中有一些选项允许您包含比 cubemx 使用的库更多的导出部分。

请不要忘记在 stm32<xx>xx_hal_conf.h

中设置正确的 HAL 包含定义