/* * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2022-06-14 fize the first version */ #include "user_uart.h" //dev 设备句柄(回调函数参数) //size 缓冲区数据大小(回调函数参数) //still in ISR func,so can only use ulog at asynchronous mode. static rt_err_t uart3_rx_complete(rt_device_t dev, rt_size_t size) { uart3_simpack.rx_num = size; rt_sem_release(&uart3_simpack.rx_sem); return RT_EOK; } static rt_err_t uart6_rx_complete(rt_device_t dev, rt_size_t size) { uart6_simpack.rx_num = size; rt_sem_release(&uart6_simpack.rx_sem); return RT_EOK; } rt_device_t uart3_init(void) { struct serial_configure config; serial3 = rt_device_find(USER_UART3_NAME); if (serial3 == RT_NULL) { LOG_E("could not find device: %s", USER_UART3_NAME); return RT_NULL; } config.baud_rate = BAUD_RATE_460800; //修改波特率为 460800 config.data_bits = DATA_BITS_8; //数据位 8 config.stop_bits = STOP_BITS_1; //停止位 1 config.bufsz = 8000; //修改缓冲区 buff size 为 2048 config.parity = PARITY_NONE; //无奇偶校验位 rt_device_control(serial3, RT_DEVICE_CTRL_CONFIG, &config); if (rt_device_set_rx_indicate(serial3, uart3_rx_complete) != RT_EOK) { LOG_E("could not set %s 's rx callback func", USER_UART3_NAME); return RT_NULL; } //do not ust dma for rx and tx at same time if (rt_device_open(serial3, RT_DEVICE_FLAG_INT_TX | RT_DEVICE_FLAG_DMA_RX | RT_DEVICE_OFLAG_RDWR)) { LOG_E("could not open device: %s", USER_UART3_NAME); return RT_NULL; } rt_sem_init(&uart3_simpack.rx_sem, "rx3_sem", 0, RT_IPC_FLAG_PRIO); return serial3; } rt_device_t uart6_init(void) { struct serial_configure config; serial6 = rt_device_find(USER_UART6_NAME); if (serial6 == RT_NULL) { LOG_E("could not find device: %s", USER_UART6_NAME); return RT_NULL; } config.baud_rate = BAUD_RATE_115200; //修改波特率为 460800 config.data_bits = DATA_BITS_8; //数据位 8 config.stop_bits = STOP_BITS_1; //停止位 1 config.bufsz = 8000; //修改缓冲区 buff size 为 2048 config.parity = PARITY_NONE; //无奇偶校验位 rt_device_control(serial6, RT_DEVICE_CTRL_CONFIG, &config); if (rt_device_set_rx_indicate(serial6, uart6_rx_complete) != RT_EOK) { LOG_E("could not set %s 's rx callback func", USER_UART6_NAME); return RT_NULL; } //do not ust dma for rx and tx at same time if (rt_device_open(serial6, RT_DEVICE_FLAG_INT_TX | RT_DEVICE_FLAG_DMA_RX | RT_DEVICE_OFLAG_RDWR)) { LOG_E("could not open device: %s", USER_UART6_NAME); return RT_NULL; } rt_sem_init(&uart6_simpack.rx_sem, "rx6_sem", 0, RT_IPC_FLAG_PRIO); return serial6; }