usbstm32stm32f3

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


I need to use the macro PCD_GET_EP_TX_ADDRESS from stm32f3xx_hal_pcd.h.

It is defined with:

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

but using it causes a compilation error as PCD_EP_TX_ADDRESS is not defined.

I have grepped the whole project and the string PCD_EP_TX_ADDRESS with the results:

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)))

The presence of the string in many object files, suggests that it is defined in some location.

Where is PCD_EP_TX_ADDRESS defined?


Solution

  • It seems to be declared inside of 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)))))
    

    It probably wasn't included by CubeMX because CubeMX is crap sometimes. There are options in the export though to allow you to include more parts of the library be exported than the ones used by cubemx.

    please don't forget to set the right HAL include defines inside of stm32<xx>xx_hal_conf.h