Skip to main content
zaalzaalak222
Associate II
July 7, 2012
Question

TIM_ClearFlag() function in stm32f10x library

  • July 7, 2012
  • 3 replies
  • 871 views
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?
    This topic has been closed for replies.

    3 replies

    Tesla DeLorean
    Guru
    July 7, 2012
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    zaalzaalak222
    Associate II
    July 13, 2012
    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?

    Tesla DeLorean
    Guru
    July 13, 2012
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..