So in the meantime I got the answers to my questions.

When CH1 triggers, the TIM3->SR register gets the value of 0x0000001f. I have looked at it in the debugger. The other channels are not even set up, so their interrupts should be disabled, right?

Well as it turns out, the channels, which are "not set up" are rather in their reset states. So the reset register settings apply to them.

It enters the TIM3_IRQHandler function and it executes the ISR of all the channels. Not only that, but it doesn't even reset the CCxIF bits when I tell it to. It just goes over the line and does nothing. According to the debugger, the TIM3->SR value remains unchanged.

Yes, it executes them, because the interrupt flags are set, no matter the settings in the TIMx->DIER register. The TIMx->DIER register serves only to set whether an interrupt is made, not if the interrupt flag sets or not. So what happened is, the CCRx registers of the unused channels were 0, and when the CNT register reached 0, they set the corresponding CCxIF interrupt flags. So in the interrupt handler I have to check not only if the interrupt flag is set for the channel, but if the channel DIER bit is enabled.

The reason all flags appeared to set at once is because in debugging mode the timer clock continued to tick, even when the code execution halted. That explains everything else that was unclear.

Answer from inaseaofsalt on Stack Exchange
🌐
STMicroelectronics Community
community.st.com › stmicroelectronics community › discussions › product forums › stm32 mcus › stm32 mcus products › stm32 timer output compare interrupt all interrupt flags set at once
STM32 Timer Output Compare Interrupt all interrupt flags set at once | Community
October 27, 2021 - Could you provide some example as to how to properly setup output compare interrupts? Any help is much appreciated! ... void TIM3_Init(void) { RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; //Enable timer 3 clock TIM3->PSC = 65536-1; // Set timer 3 prescaler TIM3->ARR = 7200-1; //Set timer 3 auto reload value TIM3->CR1 &= ~(3 << TIM_CR1_CMS_Pos); //selecting edge aligned PWM TIM3->CR1 |= TIM_CR1_ARPE; //Enable auto-reload preload TIM3->CCER &= ~TIM_CCER_CC1E;//Capture compare 1 disable TIM3->CCER &= ~TIM_CCER_CC1P;//Capture compare polarity active high TIM3->CCMR1 &= ~(3 << TIM_CCMR1_CC1S_Pos);//CC1 channel is output TIM3->CCMR1 &= ~(7 << TIM_CCMR1_OC1M_Pos);//OC no output selected TIM3->CCER |= TIM_CCER_CC1E;//Capture compare 1 enable }
🌐
Medium
medium.com › @pqshedy33 › what-is-output-compare-mode-on-stm32-timers-1b231988274b
What is output compare mode on STM32 timers? | by Ampheo | Medium
October 9, 2025 - The Output Compare mode is a fundamental feature of STM32’s timer peripherals. Its core function is to compare the current value of the Timer Counter (CNT) register with a pre-loaded value in the Capture/Compare Register (CCR).
🌐
EmbeddedExpertIO
blog.embeddedexpert.io
Working with STM32 and Timers part 6: Output Compare – EmbeddedExpertIO
Drivers, STM32 · In the pervious ... to the maximum level (set by the ARR), the following will happen: Assigns the corresponding output pin to a programmable value defined by the output compare mode. Sets a flag in the interrupt status ......
🌐
STMicroelectronics Community
community.st.com › t5 › stm32-mcus-products › is-it-possible-to-compare-compare-the-output-using-stm32-s-timer › td-p › 80742
Is it possible to compare compare the output using STM32's timer interrupts
February 17, 2022 - So check the ref manual about the ... output compare mode "frozen", not sure though). Basically you write a timer value in CCR1 -> interrupt on compare, next timer value in CCR2 -> interrupt on compare, etcpp......
🌐
Medium
medium.com › @csrohit › output-compare-mode-on-stm32f4-timers-6d961162bbe2
Output Compare Mode on STM32F4 Timers | by Rohit Nimkar | Medium
May 15, 2025 - It monitors the timer counter. When a match occurs, it performs the programmed action on the output pin (see Figure 2 in AN4776). Any STM32F4 board (I’m using an STM32F401, but this works on most STM32F4 MCUs)
Find elsewhere
🌐
STMicroelectronics Community
community.st.com › t5 › stm32cubemx-mcus › how-to-enable-output-compare-timer-interrupt-in-stm32cubemx › td-p › 225520
Solved: How to enable output compare timer interrupt in ST... - STMicroelectronics Community
May 29, 2021 - The respective CCxIE bits (Capture/Compare interrupt enable) are set inside the code when you are using related HAL functions. In your case you will be interested in these respective functions: HAL_StatusTypeDef HAL_TIM_OC_Start_IT (TIM_HandleTypeDef * htim, uint32_t Channel); HAL_StatusTypeDef HAL_TIM_OC_Stop_IT (TIM_HandleTypeDef * htim, uint32_t Channel); More information you can in the HAL and low-layer drivers user manual related to MCU family you are using. For the STM32F4 mcus family the manual could be found here.
🌐
STMicroelectronics
st.com › resource › en › product_training › STM32L4_WDG_TIMERS_GPTIM.pdf pdf
Hello, and welcome to this presentation on the STM32
This slide presents the output compare features. A compare event is generated when the counter matches · the value of the compare register. This event can trigger · an interrupt or a DMA request and can be reflected on
🌐
DeepBlue
deepbluembedded.com › home › blog › stm32 timer interrupt hal example – timer mode lab
STM32 Timer Interrupt HAL Example - Timer Mode LAB – DeepBlueMbedded
February 17, 2025 - After navigating to the timer interrupt handler routine, you’ll find the following implementation. In this code, we’re searching for the callback function’s name that gets called when an overflow interrupt occurs. You can notice that all sources share the same interrupt signal output compare match, overflow, input capture, etc.
🌐
DeepBlue
deepbluembedded.com › home › blog › stm32 timers tutorial | hardware timers explained
STM32 Timers Explained Tutorial - Timer Modes Examples Interrupts pwm
January 20, 2024 - All standard IR pulse modulation modes can be obtained by programming the two-timer output compare channels. TIM15 is used to generate the high-frequency carrier signal, while TIM16 generates the modulation envelope.
🌐
EmbeddedExpertIO
blog.embeddedexpert.io
Getting Started with STM32F103: Output Compare Mode in Timer – EmbeddedExpertIO
In this mode, the timer shall count to the maximum level (set by the ARR), the following will happen: Assigns the corresponding output pin to a programmable value defined by the output compare mode. Sets a flag in the interrupt status register.
🌐
STMicroelectronics Community
community.st.com › t5 › stm32-mcus-products › stm32-timer-output-compare › td-p › 247471
STM32 Timer Output compare - STMicroelectronics Community
April 6, 2020 - The timer configuration in CubeMX and HAL is quite poorly documented. The generated code has lots of unnecessary diversions. Use the register interface, which is documented in detail in the reference manual. // interrupt handler for TIM1 capture/compare event void TIM1_CC_IRQHandler(void) { uint32_t sr = TIM1->SR; // read interrupt flags TIM1->SR = ~sr; // clear interrupt flags before proceeding if(sr & TIM_SR_CC1IF) { // capture event } } void TIM1_UP_TIM16_IRQHandler(void) { uint32_t sr = TIM1->SR; // read interrupt flags TIM1->SR = ~sr; // clear interrupt flags before proceeding if(sr & TIM
🌐
Aticleworld
aticleworld.com › home › stm32 timer tutorial using interrupt with hal code example
STM32 Timer Tutorial Using Interrupt with HAL Code Example - Aticleworld
October 6, 2025 - Auto-Reload Value (ARR) – Defines the maximum counter value, effectively setting the timer period. Interrupts or Output Compare – Specifies actions to execute when the counter reaches certain values, enabling precise event handling.
🌐
Stack Exchange
electronics.stackexchange.com › questions › 475957 › stm32-timer-synchronization-between-output-compare-and-timer-interrupt
stm32 timer synchronization between output compare and timer interrupt - Electrical Engineering Stack Exchange
January 13, 2020 - If you don't, you should be able to set an interrupt to fire on EVERY output compare event and in that interrupt check whether the "inside interrupt IO" should be triggered. And the rock bottom way is to not use the output compare at all. Just use interrupts for both and trigger both IO off of different compare registers connected to the same timer.
🌐
GitHub
github.com › dekuNukem › STM32_tutorials › blob › master › lesson4_timers_and_pwm › README.md
STM32_tutorials/lesson4_timers_and_pwm/README.md at master · dekuNukem/STM32_tutorials
Just like Arduino, only certain pins on STM32 has PWM output. You can find out by left clicking a pin and see if it as TIMXXCHY function, where XX is timer number, and Y is channel number. Let's see what's on the on-board LED, PA4: Bingo!
Author   dekuNukem