很高兴收到中科蓝讯AB32VG1 RISC-V开发板,这是我第一次用RISC-V的MCU, RT-Thread 也是第一次用。参考文档“中科蓝讯AB32VG1开发实践指南”对我使用有很大帮助。当然文档还是有一些关键点没有说明清楚或就是说明本身错误的。在本文后面会说明。
1. RT-Thread 下载:https://www.rt-thread.org/page/download.html
2. 下载安装过程略。但安装后还需要安装latest RT-thread source code. 见下图箭头所指。

接着安装AB32VG1 板的开发包。见下图箭头所指

接着安装risc-v工具链,和downloader,这些可以参考文档“中科蓝讯AB32VG1开发实践指南”。
这些安装好了后,就可以用RT-Thread 新建项目了。


这样code就生成了。
但编译居然不通过!报错:没有uint8_t 声明,我也不知道其他人都说顺利编译成功是怎么回事,反正我分别在文件“drv_common.c”中加了:#include "stdint.h", 在“drv_uart.c”中加了#include "stdio.h", 编译才顺利通过。
至此才开始coding工作。
这里文档里有一个问题: Blue_LED 在文档里写的对应PA.2 ,我试了很久都不对,后来看到原理图才发现对应PA.1,改code就正常工作了。
下面的code能以500ms间隔,循环用7中颜色点亮LED:
void init_LED(uint8_t r_led,uint8_t g_led,uint8_t b_led)
{
rt_pin_mode(r_led, PIN_MODE_OUTPUT);
rt_pin_mode(g_led, PIN_MODE_OUTPUT);
rt_pin_mode(b_led, PIN_MODE_OUTPUT);
rt_pin_write(r_led, PIN_HIGH); //r_led off
rt_pin_write(g_led, PIN_HIGH); //g_led off
rt_pin_write(b_led, PIN_HIGH); //b_led off
}
void LED_toggle(uint8_t r_led,uint8_t g_led,uint8_t b_led,uint16_t delaytime)
{
rt_pin_write(r_led, PIN_LOW); //r_led on
rt_thread_mdelay(delaytime);
rt_pin_write(r_led, PIN_HIGH); //r_led off
rt_thread_mdelay(delaytime);
rt_pin_write(g_led, PIN_LOW); //g_led on
rt_thread_mdelay(delaytime);
rt_pin_write(g_led, PIN_HIGH); //g_led off
rt_thread_mdelay(delaytime);
rt_pin_write(b_led, PIN_LOW); //b_led on
rt_thread_mdelay(delaytime);
rt_pin_write(b_led, PIN_HIGH); //b_led off
rt_thread_mdelay(delaytime);
rt_pin_write(r_led, PIN_LOW); //r_led on
rt_pin_write(g_led, PIN_LOW); //g_led on
rt_thread_mdelay(delaytime);
rt_pin_write(r_led, PIN_HIGH); //r_led off
rt_pin_write(g_led, PIN_HIGH); //g_led off
rt_thread_mdelay(delaytime);
rt_pin_write(r_led, PIN_LOW); //r_led on
rt_pin_write(b_led, PIN_LOW); //b_led on
rt_thread_mdelay(delaytime);
rt_pin_write(r_led, PIN_HIGH); //r_led off
rt_pin_write(b_led, PIN_HIGH); //b_led off
rt_thread_mdelay(delaytime);
rt_pin_write(g_led, PIN_LOW); //g_led on
rt_pin_write(b_led, PIN_LOW); //b_led on
rt_thread_mdelay(delaytime);
rt_pin_write(g_led, PIN_HIGH); //g_led off
rt_pin_write(b_led, PIN_HIGH); //b_led off
rt_thread_mdelay(delaytime);
rt_pin_write(r_led, PIN_LOW); //r_led on
rt_pin_write(g_led, PIN_LOW); //g_led on
rt_pin_write(b_led, PIN_LOW); //b_led on
rt_thread_mdelay(delaytime);
rt_pin_write(r_led, PIN_HIGH); //r_led off
rt_pin_write(g_led, PIN_HIGH); //g_led off
rt_pin_write(b_led, PIN_HIGH); //b_led off
rt_thread_mdelay(delaytime);
}
int main(void)
{
uint8_t r_led = rt_pin_get("PE.1"); //red LED control
uint8_t g_led = rt_pin_get("PE.4"); //green LED control
uint8_t b_led = rt_pin_get("PA.1"); //blue LED control
rt_kprintf("Hello, world\n");
init_LED(r_led,g_led,b_led);
while (1)
{
LED_toggle(r_led,g_led,b_led,500);
}
}