2014-11-14 09:14 AM
Hi, I'm just starting on ARM CORTEX and STM32 via The Spark Core so forgive me if I'm missing something but in file stm32f10x_tim.c
Functionvoid
(http://stm32.kosyak.info/doc/struct_t_i_m___type_def.html
* TIMx, uint16_t TIM_IT)the lines02681
/* Clear the IT pending Bit */
02682 TIMx->http://stm32.kosyak.info/doc/struct_t_i_m___type_def.html#a44962ea5442d203bf4954035d1bfeb9d
= (uint16_t)~TIM_IT;should surely read02681
/* Clear the IT pending Bit */
02682 TIMx->http://stm32.kosyak.info/doc/struct_t_i_m___type_def.html#a44962ea5442d203bf4954035d1bfeb9d
&= (uint16_t)~TIM_IT;With &= instead of just = otherwise the function is clobbering all the flags in the status register. That's all.2014-11-14 09:52 AM
But doing it your way introduces a HUGE HAZARD given the window of the Read-Modify-Write with respect to the peripheral's clock. Suggest you look at the reference manual a bit harder, and think like an IC designer, not a SW engineer.
2014-11-14 12:28 PM
If you're still pondering on this, remember if you AND something with ZERO it will clear it. Peripheral registers are not memory cells, and can change outside program / cpu control. An interrupt can assert between the time you read and when the write occurs. It's also dangerous to use bit-banding writes on this, and other, registers.
TIMx->
http://stm32.kosyak.info/doc/struct_t_i_m___type_def.html#a44962ea5442d203bf4954035d1bfeb9d
= (uint16_t)~TIM_IT; At a hardware level operates as SR_NEXT := (SR_CURRENT & ~TIM_IT) | INTERRUPTS_NEW, on the synchronous edge on a single clock.2014-11-14 01:10 PM
OK, thanks. Perhaps I did deserve the patronising comment. My problem was not knowing that the term rc_w0 lurking in the manual was significant & that the register bits were reset only on write. I do appreciate the danger of read-modify-write cycles.