cancel
Showing results for 
Search instead for 
Did you mean: 

Possible BUG: Always writing 0xFF to TIM2->SR in stm8s_tim2.c

pacman
Associate III

I just downloaded the latest StdPeriph_Driver library a few days ago.

The line ...

TIM2->SR2 = (uint8_t)(~((uint8_t)((uint8_t)TIM2_FLAG >> 8)));

... produces a warning. The value written to TIM2->SR2 will always be 0xFF.

It's unclear to me what the desired functionality of the above line is.

-If this is supposed to use any bits from 'TIM2_FLAG'), the following would be better...

TIM2->SR2 = (uint8_t)(~((uint8_t)((uint8_t)(TIM2_FLAG >> 8))));

... which then again is the exact same thing as ...

TIM2->SR2 = ~0;

... but when looking at the code for TIM3, I see the following code ...

TIM3->SR2 = (uint8_t)(~((uint8_t)((uint16_t)TIM3_FLAG >> 8)));

... which suggests that it might be better to do this ...

TIM2->SR2 = (uint8_t)(~((uint8_t)((uint16_t)TIM3_FLAG >> 8)));

... So if the line from TIM3 is correct, then I'd suggest cleaning it up a little:

TIM3->SR2 = ~(uint8_t)(TIM3_FLAG >> 8);

0 REPLIES 0