实现串口驱动,移植方便
This commit is contained in:
43
HAL/Src/hal_delay.c
Normal file
43
HAL/Src/hal_delay.c
Normal file
@ -0,0 +1,43 @@
|
||||
/* 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 */
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user