44 lines
1.0 KiB
C
44 lines
1.0 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file : hal_delay.c
|
|
* @brief : Delay hardware abstraction layer source file
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
|
|
#include "hal_delay.h"
|
|
#include "stm32f4xx_hal.h"
|
|
|
|
/**
|
|
* @brief Initialize delay module
|
|
*/
|
|
void hal_delay_init(void) {
|
|
/* Delay initialization is handled by HAL_Init() */
|
|
}
|
|
|
|
/**
|
|
* @brief Delay in milliseconds
|
|
* @param ms: Delay time in milliseconds
|
|
*/
|
|
void hal_delay_ms(uint32_t ms) {
|
|
HAL_Delay(ms);
|
|
}
|
|
|
|
/**
|
|
* @brief Delay in microseconds
|
|
* @param us: Delay time in microseconds
|
|
*/
|
|
void hal_delay_us(uint32_t us) {
|
|
uint32_t ticks = 0;
|
|
uint32_t start_tick = 0;
|
|
uint32_t tick_freq = HAL_RCC_GetHCLKFreq() / 1000000;
|
|
|
|
ticks = us * tick_freq;
|
|
start_tick = HAL_GetTick() * tick_freq;
|
|
|
|
while ((HAL_GetTick() * tick_freq - start_tick) < ticks) {
|
|
/* Busy wait */
|
|
}
|
|
}
|