From 581ed93e1df5a1e445daa8acebe944a279c8b795 Mon Sep 17 00:00:00 2001 From: "NOTE-MARKUS\\Markus" <pichlerbi76568@th-nuernberg.de> Date: Thu, 20 May 2021 17:45:51 +0200 Subject: [PATCH] SCR --- Core/Inc/DWT_Delay.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Core/Inc/DWT_Delay.h diff --git a/Core/Inc/DWT_Delay.h b/Core/Inc/DWT_Delay.h new file mode 100644 index 0000000..ee7442b --- /dev/null +++ b/Core/Inc/DWT_Delay.h @@ -0,0 +1,40 @@ +/* + * File: DWT_Delay.h + * Driver Name: [[ DWT Delay ]] + * SW Layer: ECUAL + * Created on: Jun 28, 2020 + * Author: Khaled Magdy + * ------------------------------------------- + * For More Information, Tutorials, etc. + * Visit Website: www.DeepBlueMbedded.com + * + */ + +#ifndef DWT_DELAY_H_ +#define DWT_DELAY_H_ + +#include "stm32f4xx_hal.h" + + +uint32_t DWT_Delay_Init(void); + + +// This Function Provides Delay In Microseconds Using DWT +__STATIC_INLINE void DWT_Delay_us(volatile uint32_t au32_microseconds) +{ + uint32_t au32_initial_ticks = DWT->CYCCNT; + uint32_t au32_ticks = (HAL_RCC_GetHCLKFreq() / 1000000); + au32_microseconds *= au32_ticks; + while ((DWT->CYCCNT - au32_initial_ticks) < au32_microseconds-au32_ticks); +} + +// This Function Provides Delay In Milliseconds Using DWT +__STATIC_INLINE void DWT_Delay_ms(volatile uint32_t au32_milliseconds) +{ + uint32_t au32_initial_ticks = DWT->CYCCNT; + uint32_t au32_ticks = (HAL_RCC_GetHCLKFreq() / 1000); + au32_milliseconds *= au32_ticks; + while ((DWT->CYCCNT - au32_initial_ticks) < au32_milliseconds); +} + +#endif /* DWT_DELAY_H_ */ -- GitLab