cancel
Showing results for 
Search instead for 
Did you mean: 

Different macro definition for stm32f0xx_hal_pcd.h

hatem_ch
Associate II
Posted on November 09, 2017 at 17:06

Hi,

I'm wondering why a different macro definition is used for the stm32f0xx_hal_pcd.h header file of the USB HAL driver than the other HAL drivers. Macro definition of multiple C statements shall be placed within a ''do {} while()'' dummy loop as it is already done for all the HAL drivers except for PCD driver. In the case of HAL_PCD driver, macros are defined using enclosing curly brackets. This may cause some C translation units to not compile. Someone may think that the below line of C code should compile correctly but it will not do to the way the function-like macro is defined.

0690X0000060PCKQA2.png

// This will not compile

if(1==1) PCD_FreeUserBuffer(USB,1,1); else PCD_FreeUserBuffer(USB,1,1);

// HAL_PCDwrong function-like macro definition

#define PCD_FreeUserBuffer(USBx, bEpNum, bDir)\

{\

if ((bDir) == PCD_EP_DBUF_OUT)\

{ /* OUT double buffered endpoint */\

PCD_TX_DTOG((USBx), (bEpNum));\

}\

else if ((bDir) == PCD_EP_DBUF_IN)\

{ /* IN double buffered endpoint */\

PCD_RX_DTOG((USBx), (bEpNum));\

}\

}

// correct function-like macro definition (as used on other HAL driver headers)

#define PCD_FreeUserBuffer(USBx, bEpNum, bDir)\

do {\

if ((bDir) == PCD_EP_DBUF_OUT)\

{ /* OUT double buffered endpoint */\

PCD_TX_DTOG((USBx), (bEpNum));\

}\

else if ((bDir) == PCD_EP_DBUF_IN)\

{ /* IN double buffered endpoint */\

PCD_RX_DTOG((USBx), (bEpNum));\

}\

} while(0U)

Best Regards,

0 REPLIES 0