优化调试新增按键驱动
This commit is contained in:
@ -15,7 +15,12 @@
|
||||
* @brief STM32F4 specific delay initialization
|
||||
*/
|
||||
void hal_stm32f4_delay_init(void) {
|
||||
/* Delay initialization is handled by HAL_Init() */
|
||||
/* Enable DWT (Data Watchpoint and Trace) */
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
/* Reset DWT cycle counter */
|
||||
DWT->CYCCNT = 0;
|
||||
/* Enable DWT cycle counter */
|
||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,9 +41,26 @@ void hal_stm32f4_delay_us(uint32_t us) {
|
||||
uint32_t tick_freq = HAL_RCC_GetHCLKFreq() / 1000000;
|
||||
|
||||
ticks = us * tick_freq;
|
||||
start_tick = HAL_GetTick() * tick_freq;
|
||||
start_tick = DWT->CYCCNT;
|
||||
|
||||
while ((HAL_GetTick() * tick_freq - start_tick) < ticks) {
|
||||
/* Wait for the specified number of ticks */
|
||||
while ((DWT->CYCCNT - start_tick) < ticks) {
|
||||
/* Busy wait */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief STM32F4 specific get tick implementation
|
||||
* @return Current tick count in milliseconds
|
||||
*/
|
||||
uint32_t hal_stm32f4_get_tick(void) {
|
||||
return HAL_GetTick();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get current DWT cycle count
|
||||
* @return Current DWT cycle count
|
||||
*/
|
||||
uint32_t hal_stm32f4_get_dwt_tick(void) {
|
||||
return DWT->CYCCNT;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user