【GD32-colibri-F350RX】+LED or 按键 or UART打印测试
[复制链接]
本帖最后由 damiaa 于 2018-9-15 09:39 编辑
【GD32-colibri-F350RX】+LED or 按键 or UART打印测试
1,从GD官网下载GD32F3x0_Firmware_Library_V1.0.0并解压
2,(目前解压到E盘)E:\gd350\GD32F3x0_Firmware_Library_V1.0.0_Colibri-F350_\Projects
中建一个目录ledflash
拷贝Template目录以下文件到这个目录如下
配置好文件路径,工程中有的文件要删除后加入(都是路径问题),试下编译通过就OK。
3,记得调试用CMSID-DAP这个调试器选项 。
4,修改LED1,LED2,LED3 IO口(库和板子对应不上)
#define LEDn 3U
#define LED1_PIN GPIO_PIN_8
#define LED1_GPIO_PORT GPIOB
#define LED1_GPIO_CLK RCU_GPIOB
#define LED2_PIN GPIO_PIN_9
#define LED2_GPIO_PORT GPIOB
#define LED2_GPIO_CLK RCU_GPIOB
#define LED3_PIN GPIO_PIN_10
#define LED3_GPIO_PORT GPIOB
#define LED3_GPIO_CLK RCU_GPIOB
这里LED4可以保留,这样就不会编译出问题,否则还要删除与LED4有关东西。
typedef enum
{
LED1 = 0,
LED2 = 1,
LED3 = 2,
LED4 = 3
}led_typedef_enum;
5,修改按键IO口(库和板子对应不上)
#define KEYn 2U
/* wakeup push-button B2 */
#define WAKEUP_KEY_PIN GPIO_PIN_0
#define WAKEUP_KEY_GPIO_PORT GPIOA
#define WAKEUP_KEY_GPIO_CLK RCU_GPIOA
#define WAKEUP_KEY_EXTI_LINE EXTI_0
#define WAKEUP_KEY_EXTI_PORT_SOURCE EXTI_SOURCE_GPIOA
#define WAKEUP_KEY_EXTI_PIN_SOURCE EXTI_SOURCE_PIN0
#define WAKEUP_KEY_EXTI_IRQn EXTI0_1_IRQn
/* tamper push-button B3 */
#define TAMPER_KEY_PIN GPIO_PIN_7
#define TAMPER_KEY_GPIO_PORT GPIOB
#define TAMPER_KEY_GPIO_CLK RCU_GPIOB
#define TAMPER_KEY_EXTI_LINE EXTI_7
#define TAMPER_KEY_EXTI_PORT_SOURCE EXTI_SOURCE_GPIOB
#define TAMPER_KEY_EXTI_PIN_SOURCE EXTI_SOURCE_PIN7
#define TAMPER_KEY_EXTI_IRQn EXTI4_15_IRQn
KEY_USER可以保留,这样就不会编译出问题,否则还要删除与KEY_USER有关东西。
typedef enum
{
KEY_WAKEUP = 0,
KEY_TAMPER = 1,
KEY_USER = 2
}key_typedef_enum;
6,修改串口IO口(库和板子对应不上)并把串口设置成UART1
#define COMn 1U
/* definition for COM1, connected to USART1 */
#define EVAL_COM1 USART1
#define EVAL_COM1_CLK RCU_USART1
#define EVAL_COM1_TX_PIN GPIO_PIN_2
#define EVAL_COM1_RX_PIN GPIO_PIN_3
#define EVAL_COM_GPIO_PORT GPIOA
#define EVAL_COM_GPIO_CLK RCU_GPIOA
#define EVAL_COM_AF GPIO_AF_1
7,修改中断gd32f3x0_it.c
void SysTick_Handler(void)
{
// led_spark(); 为了它不干扰主程序的LED,便于观看,如果你要是TICK中断点LED可以用这里。
delay_decrement();
}
8,修改主程序中为:
int main(void)
{
/* configure systick */
systick_config();
/* initilize the LEDs, USART and key */
gd_eval_led_init(LED1);
gd_eval_led_init(LED2);
gd_eval_led_init(LED3);
gd_eval_com_init(EVAL_COM1);
gd_eval_key_init(KEY_WAKEUP, KEY_MODE_GPIO);
/* print out the clock frequency of system, AHB, APB1 and APB2 */
printf("\r\nCK_SYS is %d", rcu_clock_freq_get(CK_SYS));
printf("\r\nCK_AHB is %d", rcu_clock_freq_get(CK_AHB));
printf("\r\nCK_APB1 is %d", rcu_clock_freq_get(CK_APB1));
printf("\r\nCK_APB2 is %d", rcu_clock_freq_get(CK_APB2));
rcu_ckout_config(RCU_CKOUTSRC_CKSYS, RCU_CKOUT_DIV1);
while (1)
{
gd_eval_led_toggle(LED1); //led1 flash
if(RESET == gd_eval_key_state_get(KEY_WAKEUP)) //B2
{
printf("\r\nled2 on!!!");
gd_eval_led_on(LED2);
delay_1ms(100);
gd_eval_led_off(LED2);
printf("\r\nled2 off!!!");
}
if(RESET == gd_eval_key_state_get(KEY_TAMPER))//B3
{
printf("\r\nled3 on!!!");
gd_eval_led_on(LED2);
delay_1ms(100);
gd_eval_led_off(LED3);
printf("\r\nled3 off!!!");
}
}
}
7,打开调试助手,设置对应串口和设置115200,N,8,1,打开串口。
8,编译运行
9,按下中间B2按键,按下B3按键,查看结果。
GD32F3x0_Firmware_Library_V1.0.0_Colibri-F350_.zip
(4.23 MB, 下载次数: 19)