Skip to main content
HoangDuong
Associate II
December 18, 2019
Solved

STM32F1 can not using __HAL_TIM_SET_CAPTUREPOLARITY()

  • December 18, 2019
  • 7 replies
  • 2668 views

I using STM32F103C8, SW4STM32 and CubeMx

When using input capture mode and call

__HAL_TIM_SET_CAPTUREPOLARITY(htim, TIM_CHANNEL_1, TIM_INPUTCHANNELPOLARITY_FALLING);

The complier always show error:

/Users/duonghuuhoang/iWorks/ARM/TIM_InputCapture/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h:1745:106: error: expected ':' before ')' token

I do not modify and any single line in stm32f1xx_hal_tim.h

This topic has been closed for replies.
Best answer by waclawek.jan

So the problem is clear: the brackets are not balanced, line 2 should be

(((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCER &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP)) :\

(i.e. one of the closing brackes at the end removed)

Appears to be a CubeF1 bug then.

https://github.com/STMicroelectronics/STM32CubeF1/blob/master/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h#L1745

@Amel NASRI​ , can you please have a look at it?

Thanks,

JW

7 replies

waclawek.jan
Super User
December 18, 2019

And what is on and around line 1745 in stm32f1xx_hal_tim.h?

If you'll see nothing suspicious there, you should trace all macros defied there up to their origin. One way to approach this is to generate the preprocessed source, using -E instead of -c in the gcc command line - I don't use SW4STM32 so I don't know how to do that there.

I don't use Cube/CubeMX.

JW

HoangDuong
Associate II
December 20, 2019
#define TIM_RESET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__) \
 (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCER &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP))) :\
 ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCER &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP)) :\
 ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCER &= ~(TIM_CCER_CC3P)) :\
 ((__HANDLE__)->Instance->CCER &= ~(TIM_CCER_CC4P)))

that is the code of ST Lib from stm32f1xx_hal_tim.h

i try using ​__HAL_TIM_SET_CAPTUREPOLARITY() function but using stm32f4 family , it working fine without error

and my output when using preprocessed (-E) ​:

Building target: TIM_InputCapture.elf
Invoking: MCU GCC Linker
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -mfloat-abi=soft -specs=nosys.specs -specs=nano.specs -T"../STM32F103C8Tx_FLASH.ld" -Wl,-Map=output.map -Wl,--gc-sections -o "TIM_InputCapture.elf" @"objects.list" -lm
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.o: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
make: *** [TIM_InputCapture.elf] Error 1

​@Community member​  thanks for answer

waclawek.jan
waclawek.janBest answer
Super User
December 20, 2019

So the problem is clear: the brackets are not balanced, line 2 should be

(((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCER &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP)) :\

(i.e. one of the closing brackes at the end removed)

Appears to be a CubeF1 bug then.

https://github.com/STMicroelectronics/STM32CubeF1/blob/master/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h#L1745

@Amel NASRI​ , can you please have a look at it?

Thanks,

JW

Amel NASRI
ST Technical Moderator
December 31, 2019

Thanks @Community member​  for bringing this error to our attention.

It is tracked internally (ref78456).

-Amel

To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
waclawek.jan
Super User
December 31, 2019

Thanks, Amel.

Jan

HoangDuong
Associate II
December 21, 2019

@Community member​  Thanks so much ​, i remove brackes at the end of line 2 and now it work normal.