优化调试新增按键驱动

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

@ -23,4 +23,103 @@
*/
void hal_stm32f4_init(void);
/**
* @brief STM32F4 specific delay initialization
*/
void hal_stm32f4_delay_init(void);
/**
* @brief STM32F4 specific delay in milliseconds
* @param ms: Delay time in milliseconds
*/
void hal_stm32f4_delay_ms(uint32_t ms);
/**
* @brief STM32F4 specific delay in microseconds
* @param us: Delay time in microseconds
*/
void hal_stm32f4_delay_us(uint32_t us);
/**
* @brief STM32F4 specific get tick implementation
* @return Current tick count in milliseconds
*/
uint32_t hal_stm32f4_get_tick(void);
/**
* @brief STM32F4 specific GPIO initialization
*/
void hal_stm32f4_gpio_init(void);
/**
* @brief STM32F4 specific GPIO configure pin implementation
* @param config: Pointer to GPIO configuration structure
*/
void hal_stm32f4_gpio_configure_pin(const hal_gpio_config_t *config);
/**
* @brief STM32F4 specific GPIO write pin implementation
* @param port: GPIO port
* @param pin: GPIO pin
* @param state: GPIO pin state
*/
void hal_stm32f4_gpio_write_pin(hal_gpio_port_t port, hal_gpio_pin_t pin, hal_gpio_pin_state_t state);
/**
* @brief STM32F4 specific GPIO toggle pin implementation
* @param port: GPIO port
* @param pin: GPIO pin
*/
void hal_stm32f4_gpio_toggle_pin(hal_gpio_port_t port, hal_gpio_pin_t pin);
/**
* @brief STM32F4 specific GPIO read pin implementation
* @param port: GPIO port
* @param pin: GPIO pin
* @retval GPIO pin state
*/
hal_gpio_pin_state_t hal_stm32f4_gpio_read_pin(hal_gpio_port_t port, hal_gpio_pin_t pin);
/**
* @brief STM32F4 specific UART initialization
*/
void hal_stm32f4_uart_init(void);
/**
* @brief STM32F4 specific UART configuration
* @param config: Pointer to UART configuration structure
*/
void hal_stm32f4_uart_config(const hal_uart_config_t *config);
/**
* @brief STM32F4 specific UART send implementation
* @param instance: UART instance
* @param data: Pointer to data buffer
* @param length: Data length
*/
void hal_stm32f4_uart_send(hal_uart_instance_t instance, const uint8_t *data, size_t length);
/**
* @brief STM32F4 specific UART receive implementation
* @param instance: UART instance
* @param data: Pointer to data buffer
* @param length: Data length
* @retval Number of bytes received
*/
size_t hal_stm32f4_uart_receive(hal_uart_instance_t instance, uint8_t *data, size_t length);
/**
* @brief STM32F4 specific UART TX ready check
* @param instance: UART instance
* @retval 1 if TX is ready, 0 otherwise
*/
uint8_t hal_stm32f4_uart_is_tx_ready(hal_uart_instance_t instance);
/**
* @brief STM32F4 specific UART RX ready check
* @param instance: UART instance
* @retval 1 if RX is ready, 0 otherwise
*/
uint8_t hal_stm32f4_uart_is_rx_ready(hal_uart_instance_t instance);
#endif /* HAL_STM32F4_H */

View File

@ -29,4 +29,10 @@ void hal_delay_ms(uint32_t ms);
*/
void hal_delay_us(uint32_t us);
/**
* @brief Get current system tick count in milliseconds
* @return Current tick count in milliseconds
*/
uint32_t hal_get_tick(void);
#endif /* HAL_DELAY_H */

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
}