优化实现串口驱动,SPI驱动 W25QXX还需要初始化验证修复

This commit is contained in:
冯佳
2026-01-23 09:59:43 +08:00
parent 51e8d79f78
commit b166bee1a9
69 changed files with 6253 additions and 1178 deletions

View File

@ -7,14 +7,19 @@
*/
/* USER CODE END Header */
#include "hal.h"
#include "hal_delay.h"
#include "stm32f4xx_hal.h"
/**
* @brief Initialize delay module
*/
void hal_delay_init(void) {
/* Delay initialization is handled by HAL_Init() */
/* Call architecture specific delay initialization */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F4
hal_stm32f4_delay_init();
#else
#error "Unsupported HAL architecture"
#endif
}
/**
@ -22,7 +27,12 @@ void hal_delay_init(void) {
* @param ms: Delay time in milliseconds
*/
void hal_delay_ms(uint32_t ms) {
HAL_Delay(ms);
/* Call architecture specific delay implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F4
hal_stm32f4_delay_ms(ms);
#else
#error "Unsupported HAL architecture"
#endif
}
/**
@ -30,14 +40,10 @@ void hal_delay_ms(uint32_t ms) {
* @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 */
}
/* Call architecture specific delay implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F4
hal_stm32f4_delay_us(us);
#else
#error "Unsupported HAL architecture"
#endif
}