on 2025-08-18 1:53 AM
The break feature is embedded only in timer peripherals that include complementary outputs. Specifically, it is available in timers that have at least one channel with two complementary outputs. This makes it suitable for:
This feature is supported across various STM32 families. You can check table 2 "Timers and break input availability in STM32 devices" in AN4277.
The break feature acts on the output stage of timer channels configured in output mode. As soon as an active edge is detected on the break input, the outputs of timer channels configured in output mode are either turned off or forced to a predefined safe state. Its key functionalities include:
The primary purpose of the break feature is to implement safe shutdown functionality in electrical power systems during anomalies. It is widely used in:
The break input can be triggered by both internal and external sources:
Advanced timers support two break inputs (BRK and BRK2), each with different priorities.
In motor control applications, BRK2 is typically used for overcurrent protection, while BRK is used for overvoltage protection.
The break feature is enabled using the BRK (BKE) bit in the TIMx_BDTR register following this sequence:
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; /* TIM1 clock enable */
Prescaler = (uint16_t) (SystemCoreClock / 500000) - 1; /* Set the Timer
prescaler to get 500 kHz as counter clock */
TIM1->CR1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS); /* Select the up counter mode*/
TIM1->CR1 |= TIM_COUNTERMODE_UP;
TIM1->CR1 &= ~TIM_CR1_CKD;
TIM1->CR1 |= TIM_CLOCKDIVISION_DIV1; /* Set the clock division to 1*/
TIM1->ARR = PERIOD; /* Set the Autoreload value */
TIM1->CCR1 = PULSE; /* Set the Capture Compare Register value */
TIM1->PSC = Prescaler; /* Set the Prescaler value */
TIM1->EGR = TIM_EGR_UG; /* Generate an update event to reload the Prescaler
and the repetition counter value immediatly */
TIM1->SMCR = RESET; /*Configure the Internal Clock source */
TIM1->BDTR = RESET; /* Clear the BDTR bits */
TIM1->BDTR |= DEAD_TIME; /* Set the Dead Time value to 0 */
TIM1->BDTR |= TIM_LOCKLEVEL_OFF; /* Disable the Lock Level*/
TIM1->BDTR |= TIM_OSSI_ENABLE; /* Enable the Output idle mode */
TIM1->BDTR |= TIM_OSSR_DISABLE; /* Disable the Output run mode */
TIM1->BDTR |= TIM_BREAK_ENABLE; /* Enable the Break input */
TIM1->BDTR |= TIM_BREAKPOLARITY_HIGH; /* Set the polarity to High */
TIM1->BDTR |= TIM_AUTOMATICOUTPUT_ENABLE; /* Enable the automatic output */
TIM1->CCMR1 &= ~TIM_CCMR1_OC1M; /* Select channel 1 output Compare and Mode*/
TIM1->CCMR1 &= ~TIM_CCMR1_CC1S;
TIM1->CCMR1 |= TIM_OCMODE_PWM1;
TIM1->CCER &= ~TIM_CCER_CC1P; /* Set the Output Compare Polarity to High */
TIM1->CCER |= TIM_OCPOLARITY_HIGH;
TIM1->CCER |= TIM_CCER_CC1E; /* Enable the Compare output channel 1 */
TIM1->CR1|=TIM_CR1_CEN; /* Enable the TIM peripheral */
Macros:
Usage:
Callback function:
The HAL library provides a callback mechanism to handle break events. The callback function is defined as:
void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim);
This function is called automatically when a break event occurs. So, you can implement custom fault-handling logic, such as logging the fault, shutting down peripherals, or resetting the system.
Break input flags:
These flags can be polled or cleared in the application code to manage break events. For example:
if (__HAL_TIM_GET_FLAG(&htim, TIM_FLAG_BREAK)) {
// Handle break event
__HAL_TIM_CLEAR_FLAG(&htim, TIM_FLAG_BREAK);
}
For STM32CubeMX configuration, to enable the break input feature, click on "Activate break input" after choosing an advanced timer.
After enabling the break input, you can configure these three modes as shown below:
Application note 4776: General-purpose timer cookbook for STM32 microcontrollers