1 RT-Thread配置
board.h在USB相关定义中增加
#define BSP_USING_USBDEVICE
#define BSP_USING_USBD
需要注意的是,如果不打开虚拟COM DMA发送开关,则只能发送一次,具体问题还不清楚,厂家提供的BSP中未做相关说明。
如果有编译错误,把相关文件中的RT_WEAK替换为rt_weak即可
2 测试程序
输入list device
list device
device type ref count
-------- -------------------- ----------
vcom Character Device 1
usbd USB Slave Device 0
uart4 Character Device 0
uart3 Character Device 0
uart1 Character Device 2
pin Pin Device 0
int main(void)
{
int count;
char buf2[128];
rt_device_t dev = RT_NULL;
dev = rt_device_find("vcom");
if (dev)
rt_device_open(dev, RT_DEVICE_FLAG_RDWR);
else
return -RT_ERROR;
while (1)
{
count = rt_device_read(dev, 0, buf2, 128);
if(count>0){
buf2[count] = 0;
rt_kprintf("%s\n",buf2);
rt_device_write(dev, 0, buf2, count);
}
rt_thread_mdelay(1);
}
return RT_EOK;
}
————————————————
版权声明:本文为CSDN博主「lg28870983」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lg28870983/article/details/135352856
|