I'm not trying to start a HAL holy war, I'm curious if this bit of code has some higher functionality.
When using the GPIOs on the a STM32 device you need to enable to GPIO clock using __HAL_RCC_GPIOA_CLK_ENABLE()
. Digging into the code a bit more I found what exactly that function is doing shown below. From what I can tell the only useful part of that code is the SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);
, the rest just seems like useless bloat.
I can see why __IO uint32_t tmpreg;
and UNUSED(tmpreg);
could be used, but the line tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);
doesn't really do anything so all three seem pointless. Am I missing something?
#define __HAL_RCC_GPIOA_CLK_ENABLE() \
do { \
__IO uint32_t tmpreg; \
SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
UNUSED(tmpreg); \
} while(0)
SET_BIT
#define SET_BIT(REG, BIT) ((REG) |= (BIT))
READ_BIT
#define READ_BIT(REG, BIT) ((REG) & (BIT))
UNUSED
#define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */