feat: 添加TIM4心跳闪烁并更新文档

This commit is contained in:
2026-03-30 21:06:23 +08:00
parent 9efa2cdc59
commit 0abda47013
9 changed files with 256 additions and 24 deletions
+23
View File
@@ -21,6 +21,7 @@
#include "dma.h"
#include "iwdg.h"
#include "spi.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"
@@ -67,6 +68,7 @@
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
static volatile uint16_t g_led_blink_ticks = 0;
/* USER CODE END PV */
@@ -75,6 +77,7 @@ void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
static void CH390_HardwareReset(void);
static void LED_Init(void);
static void LED_StartBlink(void);
static void App_Init(void);
static void App_Poll(void);
/* USER CODE END PFP */
@@ -109,6 +112,13 @@ static void LED_Init(void)
HAL_GPIO_WritePin(LED_PORT, LED_PIN, GPIO_PIN_SET);
}
static void LED_StartBlink(void)
{
if (HAL_TIM_Base_Start_IT(&htim4) != HAL_OK) {
Error_Handler();
}
}
/**
* @brief LED 闪烁(用于指示系统运行状态)
*/
@@ -117,6 +127,17 @@ void LED_Toggle(void)
HAL_GPIO_TogglePin(LED_PORT, LED_PIN);
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
if (htim->Instance == TIM4) {
g_led_blink_ticks++;
if (g_led_blink_ticks >= 1000u) {
g_led_blink_ticks = 0u;
LED_Toggle();
}
}
}
static void App_Init(void)
{
const device_config_t *cfg;
@@ -247,10 +268,12 @@ int main(void)
MX_USART2_UART_Init();
MX_USART3_UART_Init();
MX_SPI1_Init();
MX_TIM4_Init();
/* USER CODE BEGIN 2 */
/* LED 初始化 */
LED_Init();
LED_StartBlink();
/* CH390 硬件复位 */
CH390_HardwareReset();