I am testing an STM32F103C6 developing board, and I want to use the TIMx_CNT
value in the main function like this:
int main(void)
{
while(1)
{
if(TIM2_CNT < 500)
{
GPIO_SetBits(GPIOA, GPIO_Pin_4);
} else {
GPIO_ResetBits(GPIOA, GPIO_Pin_4);
}
}
}
Is this possible?
Yes, it's possible. Assuming that you have CMSIS compatible headers included, you need to write TIM2->CNT
(instead of TIM2_CNT). Other peripherals follow the same notation.
But for coding style consistency, if you're using ST's HAL (or Cube) libraries, you may want to prefer to use the functions provided by these libraries instead of direct register access, unless there are significant performance benefits.