cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple "expected expression before 'do'" errors

SHoll.1
Associate II

I'm new to STM32 and trying to bring up the STM32L053-DISCO project in STM32CubeIDE. It mostly comiles fine, but has an issue with the HAL defines, such as below:

#define __HAL_RCC_GPIOA_CLK_ENABLE()  do { \

                    __IO uint32_t tmpreg; \

                    SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\

                    /* Delay after an RCC peripheral clock enabling */ \

                    tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\

                    UNUSED(tmpreg); \

                   } while(0)

I really don't see why it is being flagged as an error. I'm sure this must have been seen by someone else...

Best regards,

Stephen

12 REPLIES 12
MBake.3
Associate

I found the same problem. I'm pretty sure the conditional operator doesn't let you declare variables. You also can't put a parenthesis around a do while loop. This change to the HAL code was broke these macros. Looks like the comment says this change was to "Delay after an RCC peripheral clock enabling." I can think of a few better ways to delay than this.

#define __HAL_RCC_GPIOA_CLK_ENABLE()   do { \
                                        __IO uint32_t tmpreg; \
                                        SET_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
                                        /* Delay after an RCC peripheral clock enabling */ \
                                        tmpreg = READ_BIT(RCC->IOPENR, RCC_IOPENR_GPIOAEN);\
                                        UNUSED(tmpreg); \
                                      } while(0)

So you can either change it. Back to the way it was (you'll need to fix the name and this will probably break other things so don't do it

#define __GPIOA_CLK_ENABLE()         (RCC->IOPENR |= (RCC_IOPENR_GPIOAEN))

The right way is the macros:

//#define LEDx_GPIO_CLK_ENABLE(__INDEX__)         (((__INDEX__) == 0) ? LED3_GPIO_CLK_ENABLE() : LED4_GPIO_CLK_ENABLE())
#define LEDx_GPIO_CLK_ENABLE(__INDEX__)\
if (__INDEX__ == 0)\
{\
  LED3_GPIO_CLK_ENABLE();\
}else\
{\
  LED4_GPIO_CLK_ENABLE();\
}\
//#define BUTTONx_GPIO_CLK_ENABLE(__INDEX__)      (KEY_BUTTON_GPIO_CLK_ENABLE())
#define BUTTONx_GPIO_CLK_ENABLE(__INDEX__)      KEY_BUTTON_GPIO_CLK_ENABLE()

File this one under the law of unintended consequences and a reason not to use the ternary operator in macros. You never know who is going to change what is fed into the macro.

I have found this post from 2021. I have created an empty project for STM32L0538-Discovery using STM32CubeMX and copied the BSP folder from the https://www.st.com/en/embedded-software/stsw-stm32152.html (same as the thread owner).

 

After adding a BSP, I am getting the same errors:

 

12:07:19 **** Incremental Build of configuration Debug for project E-ink ****
make -j16 all 
arm-none-eabi-gcc "../Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery.c" -mcpu=cortex-m0plus -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32L053xx -c -I../Core/Inc -I../Drivers/STM32L0xx_HAL_Driver/Inc -I../Drivers/STM32L0xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L0xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery.d" -MT"Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery.o"
arm-none-eabi-gcc "../Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery_epd.c" -mcpu=cortex-m0plus -std=gnu11 -g3 -DDEBUG -DUSE_HAL_DRIVER -DSTM32L053xx -c -I../Core/Inc -I../Drivers/STM32L0xx_HAL_Driver/Inc -I../Drivers/STM32L0xx_HAL_Driver/Inc/Legacy -I../Drivers/CMSIS/Device/ST/STM32L0xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery_epd.d" -MT"Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery_epd.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery_epd.o"
In file included from ../Core/Inc/stm32l0xx_hal_conf.h:188,
                 from ../Drivers/STM32L0xx_HAL_Driver/Inc/stm32l0xx_hal.h:29,
                 from ../Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery.h:48,
                 from ../Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery.c:40:
../Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery.c: In function 'BSP_LED_Init':
../Drivers/STM32L0xx_HAL_Driver/Inc/stm32l0xx_hal_rcc.h:724:40: error: expected expression before 'do'
  724 | #define __HAL_RCC_GPIOB_CLK_ENABLE()   do { \
      |                                        ^~
../Drivers/STM32L0xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h:2829:28: note: in expansion of macro '__HAL_RCC_GPIOB_CLK_ENABLE'
 2829 | #define __GPIOB_CLK_ENABLE __HAL_RCC_GPIOB_CLK_ENABLE
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~
../Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery.h:104:49: note: in expansion of macro '__GPIOB_CLK_ENABLE'
  104 | #define LED3_GPIO_CLK_ENABLE()                  __GPIOB_CLK_ENABLE()
      |                                                 ^~~~~~~~~~~~~~~~~~
../Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery.h:112:71: note: in expansion of macro 'LED3_GPIO_CLK_ENABLE'
  112 | #define LEDx_GPIO_CLK_ENABLE(__INDEX__)         (((__INDEX__) == 0) ? LED3_GPIO_CLK_ENABLE() : LED4_GPIO_CLK_ENABLE())
      |                                                                       ^~~~~~~~~~~~~~~~~~~~
../Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery.c:154:3: note: in expansion of macro 'LEDx_GPIO_CLK_ENABLE'
  154 |   LEDx_GPIO_CLK_ENABLE(Led);
      |   ^~~~~~~~~~~~~~~~~~~~
../Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery.c: In function 'BSP_PB_Init':
../Drivers/STM32L0xx_HAL_Driver/Inc/stm32l0xx_hal_rcc.h:716:40: error: expected expression before 'do'
  716 | #define __HAL_RCC_GPIOA_CLK_ENABLE()   do { \
      |                                        ^~
../Drivers/STM32L0xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h:2823:28: note: in expansion of macro '__HAL_RCC_GPIOA_CLK_ENABLE'
 2823 | #define __GPIOA_CLK_ENABLE __HAL_RCC_GPIOA_CLK_ENABLE
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~
../Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery.h:128:49: note: in expansion of macro '__GPIOA_CLK_ENABLE'
  128 | #define KEY_BUTTON_GPIO_CLK_ENABLE()            __GPIOA_CLK_ENABLE()
      |                                                 ^~~~~~~~~~~~~~~~~~
../Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery.h:136:50: note: in expansion of macro 'KEY_BUTTON_GPIO_CLK_ENABLE'
  136 | #define BUTTONx_GPIO_CLK_ENABLE(__INDEX__)      (KEY_BUTTON_GPIO_CLK_ENABLE())
      |                                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~
../Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery.c:222:3: note: in expansion of macro 'BUTTONx_GPIO_CLK_ENABLE'
  222 |   BUTTONx_GPIO_CLK_ENABLE(Button);
      |   ^~~~~~~~~~~~~~~~~~~~~~~
make: *** [Drivers/BSP/STM32L0538-Discovery/subdir.mk:34: Drivers/BSP/STM32L0538-Discovery/stm32l0538_discovery.o] Error 1
make: *** Waiting for unfinished jobs....
"make -j16 all" terminated with exit code 2. Build might be incomplete.

12:07:19 Build Failed. 4 errors, 0 warnings. (took 564ms)

 

As has been mentioned above, the errors could be related the macros 

#define BUTTONx_GPIO_CLK_ENABLE(__INDEX__)      (KEY_BUTTON_GPIO_CLK_ENABLE())
#define BUTTONx_GPIO_CLK_DISABLE(__INDEX__)     (KEY_BUTTON_GPIO_CLK_DISABLE())

 

But is not fully clear to me from the response above what I should replace them with in order to get the project to compile

Bob S
Principal

Look at the last 2 lines of code in the post just before yours.  Do you see what that person did?  Do the same.