Skip to content

Instantly share code, notes, and snippets.

@MayaPosch
Created October 30, 2020 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MayaPosch/32710d2aac8c46cb6327479b203f0b27 to your computer and use it in GitHub Desktop.
Save MayaPosch/32710d2aac8c46cb6327479b203f0b27 to your computer and use it in GitHub Desktop.
AN4776 TIM6 delay loop
#define ANY_DELAY_RQUIRED 0x0FFF
/* Hardware-precision delay loop implementation using TIM6 timer
peripheral. Any other STM32 timer can be used to fulfill this function, but
TIM6 timer was chosen as it has the less integration level. Other timer
peripherals may be reserved for more complicated tasks */
/* Clear the update event flag */
TIM6->SR = 0
/* Set the required delay */
/* The timer presclaer reset value is 0. If a longer delay is required the
presacler register may be configured to */
/*TIM6->PSC = 0 */
TIM6->ARR = ANY_DELAY_RQUIRED
/* Start the timer counter */
TIM6->CR1 |= TIM_CR1_CEN
/* Loop until the update event flag is set */
while (!(TIM6->SR & TIM_SR_UIF));
/* The required time delay has been elapsed */
/* User code can be executed */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment