Advertisement
Guest User

STM32F7 DWT Delay initialiser

a guest
Mar 11th, 2016
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. /* Custom timers structure */
  2. static TM_DELAY_Timers_t CustomTimers = {0};
  3.  
  4. uint32_t TM_DELAY_Init(void) {
  5. #if !defined(STM32F0xx)
  6.     uint32_t c;
  7.    
  8.     /* Enable TRC */
  9.     CoreDebug->DEMCR &= ~0x01000000;
  10.     CoreDebug->DEMCR |=  0x01000000;
  11.    
  12.     /* Enable counter */
  13.     DWT->CTRL &= ~0x00000001;
  14.     DWT->CTRL |=  0x00000001;
  15.    
  16.     /* Reset counter */
  17.     DWT->CYCCNT = 0;
  18.    
  19.     /* Check if DWT has started */
  20.     c = DWT->CYCCNT;
  21.    
  22.     /* 2 dummys */
  23.     __ASM volatile ("NOP");
  24.     __ASM volatile ("NOP");
  25.    
  26.     /* Return difference, if result is zero, DWT has not started */
  27.     return (DWT->CYCCNT - c);
  28. #else
  29.     /* Return OK */
  30.     return 1;
  31. #endif
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement