USB

usb虚拟串口接收数据死机,打印信息为指针为0 异常

发布于 2019-12-04 15:50:16
\ | /
- RT - Thread Operating System
/ | \ 4.0.1 build Dec 4 2019
2006 - 2019 Copyright by rt-thread team
msh >
msh >
msh >
msh >
msh >
msh >(rx_fifo != RT_NULL) assertion failed at function:rt_hw_serial_isr, line number:1154

查看更多

关注者
0
被浏览
538
5 个回答
JQRR_7669
JQRR_7669 2019-12-04
打开设备时打开标志加上收发使用终端就好了
李金召
李金召 2019-12-05
找到问题了,把这个rt_device_open(serial, RT_DEVICE_OFLAG_RDWR);
改成这个rt_device_open(serial, RT_DEVICE_FLAG_RDWR);
就好了,没弄清区别
Reilly
Reilly 2019-12-08
楼上用的什么芯片,可以发一下demo代码么
李金召
李金召 2019-12-10
Reilly 发表于 2019-12-8 11:39
楼上用的什么芯片,可以发一下demo代码么

stm32f103zet6


/* 用于接收消息的信号量 */
static struct rt_semaphore rx_sem;
static rt_device_t serial;

/* 接收数据回调函数 */
static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
{
/* 串口接收到数据后产生中断,调用此回调函数,然后发送接收信号量 */
rt_sem_release(&rx_sem);

return RT_EOK;
}

static void serial_thread_entry(void *parameter)
{
char ch;

while (1)
{
/* 从串口读取一个字节的数据,没有读取到则等待接收信号量 */
while (rt_device_read(serial, -1, &ch, 1) != 1)
{
/* 阻塞等待接收信号量,等到信号量后再次读取数据 */
rt_sem_take(&rx_sem, RT_WAITING_FOREVER);
}
/* 读取到的数据通过串口错位输出 */
rt_device_write(serial, 0, &ch, 1);
}
}

int main(void)
{
int err = 0;
rt_thread_t tid;
//创建并启动交互任务
tid = rt_thread_create("led", led_task, RT_NULL, RT_MAIN_THREAD_STACK_SIZE, 25, 20);
RT_ASSERT(tid != RT_NULL);
rt_thread_startup(tid);

tid = rt_thread_create("iic", iic_task, RT_NULL, RT_MAIN_THREAD_STACK_SIZE, 24, 20);
RT_ASSERT(tid != RT_NULL);
rt_thread_startup(tid);

serial = rt_device_find("vcom");
if (!serial)
{
rt_kprintf("find failed!\n");
return RT_ERROR;
}
err = rt_device_init(serial);
if (!serial)
{
rt_kprintf("find failed!\n");
return RT_ERROR;
}
err = rt_device_open(serial, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX);

//初始化信号量
rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO);

// 设置接收回调函数
rt_device_set_rx_indicate(serial, uart_input);

rt_thread_t thread = rt_thread_create("serial", serial_thread_entry, RT_NULL, 1024, 25, 10);
if (thread != RT_NULL)
{
rt_thread_startup(thread);
}

while (1)
{
rt_thread_mdelay(100);
}

return RT_EOK;
}


撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友