ADC1->ISR = ADC_ISR_ADRDY; // Day 7: a 1 at the flag, 0s everywhere else
TIM14->SR = ~TIM_SR_UIF; // today: a 0 at the flag, 1s everywhere else
Both lines are correct. Commit to an explanation before reading on: what must be different about these two registers for opposite masks to both be right?
Now open RM0490 §1.2, List of abbreviations for registers, and find that label’s definition. Compare it with the definition of rc_w1, the ADC flags’ type from Day 7.
Figure8.2.13.The TIM14 status register (RM0490 §17.4.3), with the answer boxed. UIF is bit 0, and the access type printed under it is rc_w0: read, and clear by writing 0. Writing 1 has no effect. Its neighbors CC1IF and CC1OF are rc_w0 too. The ADC’s flags were the mirror image, rc_w1.
UIF is rc_w0: cleared by writing 0; writing 1 has no effect. The ADC’s flags were rc_w1: cleared by writing 1; writing 0 has no effect. Same mechanism, opposite polarity, and now both masks make sense. A clearing mask carries the clearing value at your flag and the no-effect value at every other bit. TIM14->SR = ~TIM_SR_UIF; writes a 0 exactly at UIF and harmless 1s everywhere else; ADC1->ISR = ADC_ISR_ADRDY; writes a 1 exactly at ADRDY and harmless 0s everywhere else. The status registers of the STM32C031C6’s peripherals split between the two conventions (the peripheral designs come from different origins, and the clearing method came with them) so the access type in the reference manual, not habit, is the authority.
One postscript. Could you have cleared UIF with the read-modify-write Day 7 forbade, TIM14->SR &= ~TIM_SR_UIF;? Here, mostly yes: the write-back sends a 1 to every flag that read as 1, no effect on rc_w0 bits, and a 0 to every flag that read as 0, which was already clear. The damage Day 7 warned about does not occur. It is still the weaker habit, twice over. On an rc_w1 register it is destructive. That was the ADC’s case. And even here, if the hardware raises another flag in this register between the read and the write-back, the 0 written over it clears it and the event is silently lost. Once your own interrupts start landing in the middle of your own main loop, that stops being hypothetical. Clear status flags by assigning a mask. The interrupt version of today’s program, coming next, does exactly that.
ADC1->ISR = ADC_ISR_ADRDY; // Day 7: a 1 at the flag, 0s everywhere else
TIM14->SR = ~TIM_SR_UIF; // today: a 0 at the flag, 1s everywhere else
The ADC_ISR_ADRDY flag is cleared by writing a 1 to the flag bit. Today’s clear puts a 0 at the TIM_SR_UIF bit to clear it, and 1s over every other bit.