1 /*
2 * Copyright (c) 2006-2022, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2020-04-03 WCH first version
9 * 2022-04-05 Blta modify some formats
10 */
11 #include <rtthread.h>
12 #include <board.h>
13
14
15 /* Global typedef */
16
17 /* Global define */
18
19 /* LED0(PA1) usd pin device */
20 #define LED0_PIN 15
21
22 /* Global Variable */
23
24 /* LED1 initialization */
LED1_BLINK_INIT(void)25 void LED1_BLINK_INIT(void)
26 {
27 GPIO_InitTypeDef GPIO_InitStructure = {0};
28 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
29 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
30 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
31 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
32 GPIO_Init(GPIOA, &GPIO_InitStructure);
33 }
34
35 /* main thread */
main(void)36 int main(void)
37 {
38 rt_kprintf("\r\n MCU: CH32V103C8T6\r\n");
39 rt_kprintf(" SysClk: %dHz\r\n", SystemCoreClock);
40 rt_kprintf(" www.wch.cn\r\n");
41 LED1_BLINK_INIT();
42
43 GPIO_ResetBits(GPIOA, GPIO_Pin_0);
44 while(1)
45 {
46 GPIO_SetBits(GPIOA, GPIO_Pin_0);
47 rt_thread_mdelay(500);
48
49 GPIO_ResetBits(GPIOA, GPIO_Pin_0);
50 rt_thread_mdelay(500);
51 }
52 }
53
54 /* led cmd */
led(void)55 int led(void)
56 {
57 rt_uint8_t count;
58
59 rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);
60
61 for(count = 0; count < 10; count++)
62 {
63 rt_pin_write(LED0_PIN, PIN_LOW);
64 rt_kprintf("led on, count : %d\r\n", count);
65 rt_thread_mdelay(500);
66
67 rt_pin_write(LED0_PIN, PIN_HIGH);
68 rt_kprintf("led off\r\n");
69 rt_thread_mdelay(500);
70 }
71 return 0;
72 }
73 MSH_CMD_EXPORT(led, RT - Thread first led sample by using I / O driver);
74