优化调试新增按键驱动

This commit is contained in:
冯佳
2026-01-23 13:03:40 +08:00
parent 0a30f956b4
commit 988cc7ad4a
66 changed files with 878713 additions and 1274 deletions

View File

@ -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;
}

View File

@ -47,3 +47,16 @@ void hal_delay_us(uint32_t us) {
#error "Unsupported HAL architecture"
#endif
}
/**
* @brief Get current system tick count in milliseconds
* @return Current tick count in milliseconds
*/
uint32_t hal_get_tick(void) {
/* Call architecture specific tick implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F4
return hal_stm32f4_get_tick();
#else
#error "Unsupported HAL architecture"
#endif
}