4c1l 发表于 2024-11-21 01:22

STM32CubeMX 主程序

主程序
在主程序中,我们只需要初始化 HAL 库、启动定时器和 GPIO,并进入主循环即可。定时器中断将周期性地触发,改变 LED 状态。

main.c 示例代码:
c
复制代码
#include "stm32f0xx_hal.h"

int main(void)
{
    /* Initialize HAL Library */
    HAL_Init();

    /* Configure the system clock */
    SystemClock_Config();

    /* Initialize GPIO for LED */
    MX_GPIO_Init();

    /* Initialize TIM3 for interrupt */
    MX_TIM3_Init();

    /* Start the timer interrupt */
    HAL_TIM_Base_Start_IT(&htim3);

    /* Main loop */
    while (1)
    {
      /* The LED blinking is handled in the interrupt service routine */
    }
}

页: [1]
查看完整版本: STM32CubeMX 主程序