stm32l475 LPUART1使用DMA接收打开错误-RT_EIO

发布于 2020-11-24 10:07:57

硬件:stm32l475
软件:rtt4.0.2
使用ENV开启LPUART1的接收和DMA,rt_device_open中device_init正常,之后进入device_open即rt_serial_open时判断dev->flag出错。调试环境查看dev->flag,find后即为0x503,init后变为0x513,然后判断就出错返回了。

int init_uart_pre(const char *name, rt_uint32_t bound)
{
    //1查找设备
    rt_device_t pre_uart_device = rt_device_find(name);
    if (pre_uart_device == RT_NULL)
    {
        rt_kprintf("find device %d failed!\r\n", name);
        return RT_ERROR;
    }
    //2配置设备  
    struct serial_configure cfg = RT_SERIAL_CONFIG_DEFAULT;
    cfg.baud_rate = bound;
    cfg.bufsz = MAX_RECEIVE_LEN_PRE;
    if (RT_EOK != rt_device_control(pre_uart_device, RT_DEVICE_CTRL_CONFIG,(void *)&cfg)) 
    {
        rt_kprintf("control device %d failed!\r\n", name);
        return RT_ERROR;
    }
    //3打开设备中断接收轮询发送
//    if (RT_EOK != rt_device_open(pre_uart_device, RT_DEVICE_FLAG_INT_RX))
    if (RT_EOK != rt_device_open(pre_uart_device, RT_DEVICE_FLAG_DMA_RX))
    {
        rt_kprintf("open device %d failed!\r\n", name);
        return RT_ERROR;
    }
    //4设置回调函数
    if (RT_EOK != rt_device_set_rx_indicate(pre_uart_device, pressure_uart_receive_callback))
    {
        rt_kprintf("indicate device %d failed!\r\n", name);
        return RT_ERROR;
    }
    //5初始化消息队列
//    g_pressure_mq = rt_mq_create("pressure_mq", sizeof(struct msg), 2, RT_IPC_FLAG_FIFO);    
    g_pressure_rx_mq = rt_mq_create("pressure_rx_mq", 200, 2, RT_IPC_FLAG_FIFO);
    rt_kprintf("$pressure uart initialized ok\r\n");
    
    return RT_EOK;   
}

这是出错位置。
image.png
若不使用DMA,使用接收中断,是可以正常工作的。

查看更多

关注者
0
被浏览
283
1 个回答
james_s
james_s 2021-04-13

驱动层面不支持, 所以返回了EIO, 更新下rtt或者看下LPUART1的驱动是否支持dma
特别是单步到
rt_device_control(pre_uart_device, RT_DEVICE_CTRL_CONFIG,(void *)&cfg))
这个里面看看如何配置的.

撰写答案

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

发布
问题

分享
好友

手机
浏览

扫码手机浏览