点灯就相当于 python 的print("hello world")

定义引脚

打开工程文件后,找到相应的引脚,单击选择GPIO_Output,再右键选择 Enter User Label,输入定义的名称。

工程

LED_2
LED_3
LED_4

点击生成代码

点击生成代码
等待生成代码

点灯代码如下

1
2
3
//点灯代码    LED1闪烁
HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
HAL_Delay(300);

自动生成代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
int main(void)
{
/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration----------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

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

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */

/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
//点灯代码 LED1闪烁
HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
HAL_Delay(300);
}
/* USER CODE END 3 */
}

连接开发板后点击RUN图标

alt=RUN
alt=RUN
alt=successfully
alt=successfully

, alt=successfully %}