To start TIM16 and TIM17 PWM outputs simultaneously on the STM32F030C8T6, you can use the Master-Slave Timer synchronization mechanism. However, TIM16 and TIM17 are independent advanced-control timers, and on STM32F030, they do not support direct hardware master/slave synchronization between each other like TIM1 and TIM3 do on higher-end chips.
But you can still synchronize their start using either of these methods:
Option 1: Start Both Timers in Software (Software Sync)
This is the simplest approach for STM32F0 series without inter-timer triggers.
Steps:
- Configure both TIM16 and TIM17 for PWM mode.
- Set CR1.CEN = 0 initially (timers disabled).
- After full configuration, start both timers in quick succession in code.
Code Example (HAL):
c
HAL_TIM_PWM_Start(&htim16, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim17, TIM_CHANNEL_1);
Or more precise (with register-level control):
c
// Configure everything first, then:
TIM16->CR1 |= TIM_CR1_CEN;
TIM17->CR1 |= TIM_CR1_CEN;
This works well if a few CPU cycles of delay between start is acceptable.
Option 2: Use a Shared Trigger (Advanced Sync – Optional for STM32F0)
On STM32F030, TIM16 and TIM17 do not support slave mode (SMS) or external triggers directly. However:
- You can use an external event (like EXTI or a GPIO edge) to start both timers if you're okay with using external hardware or code-generated triggers.
- Or, in some use cases, you could generate a shared software event (like writing to UG - Update Generation) to preload and sync both counters.
Preloading + UG Example:
c
TIM16->EGR |= TIM_EGR_UG; // Generate update event (preload registers)
TIM17->EGR |= TIM_EGR_UG;
TIM16->CR1 |= TIM_CR1_CEN;
TIM17->CR1 |= TIM_CR1_CEN;
This ensures both timers start counting from their initial preload values.
Option 3: Use DMA or SysTick Trigger (More Complex)
For very tight sync, you could:
- Use a DMA request or SysTick interrupt to enable both timers at the same time.
- But this is overkill unless you're doing precision waveform generation.
Notes and Tips
Recommendation
For STM32F030C8T6, the best practical method is:
c
// Set both timers' configurations, preload values, PWM modes
TIM16->EGR |= TIM_EGR_UG;
TIM17->EGR |= TIM_EGR_UG;
// Then start both timers
TIM16->CR1 |= TIM_CR1_CEN;
TIM17->CR1 |= TIM_CR1_CEN;
This achieves near-simultaneous PWM start, good enough for most embedded applications.