cancel
Showing results for 
Search instead for 
Did you mean: 

TIM_ClearFlag() function in stm32f10x library

zaalzaalak222
Associate II
Posted on July 07, 2012 at 09:02

The content of this function is

/* Clear the flags */

  TIMx->SR = (uint16_t)~TIM_FLAG;

But I think it must be in this format:

/* Clear the flags */

  TIMx->SR &= (uint16_t)~TIM_FLAG;

a & is needed for correct clear operation on flags, is this correct?
3 REPLIES 3
Posted on July 07, 2012 at 12:30

a & is needed for correct clear operation on flags, is this correct?

Wouldn't that introduce hazards by being non-atomic?

''This flag is set by hardware only when the corresponding channel is configured in input

 

capture mode. It is cleared by software by writing it to ‘0.''

I can't find a better cite quickly, but the inferred operation is that only a write of a zero bit will stick, and thus the operation is self masking and atomic.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
zaalzaalak222
Associate II
Posted on July 13, 2012 at 15:23

In page 394 of RM0008 we  see:

Bit 15:13     Reserved, must be kept at reset value.

(for TIMx status register (TIMx_SR) )

but we write 1 to reserved bits!

what is the problems of non atomic clear operation?

Posted on July 13, 2012 at 17:08

what is the problems of non atomic clear operation?

That you'd clear an interrupt that asserts in the middle of your non-atomic RMW operation, and you'd never know. Consider for a second what the AND operator does, and now spread that over at least 4-8 cycles.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..