cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F1 can not using __HAL_TIM_SET_CAPTUREPOLARITY()

HoangDuong
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

7 REPLIES 7

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

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

HoangDuong
Associate II

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

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 Accept as Solution on the reply which solved your issue or answered your question.

Thanks, Amel.

Jan