关于uart driver error报错的可能信息

问题出现前提:本人在尝试根据Espressif给的官方API自己写一个简单的UART测试项目,没有参照Example

写完测试程序,看到这个报错,根据错误提示信息找了有联系的函数排查,但是无论是uart_read_bytes(),uart_driver_install(),还是uart_write_bytes()都没有什么问题。

辗转无数个github issues和Espressif社区 都没有得到完全解决的方案,虽然碰到有人和我的报错一样,但是解决办法却是毫无关系。

在我对照Example的代码无数遍,一点一点修改至几乎与示例代码一样的时候,问题解决了,但是不太明确具体原因。

解决方法是将我的初始化函数名 由Uart_Init()  改成init()...

看了一下,IDF框架中并没有Uart_Init这个函数,不存在重写的情况。

之前有学过rt-thread,所以想是否freertos与rt-thread哪里不同的缘故?

如果有大佬知道具体原因可以留个评论  万分感谢

---------------------------------------------------------------------------------------------------------------------

补充:应该就是在某个依赖文件中有这个函数被用过了,刚刚试了一下其他的函数名,只有Uart_Init()是不可以的,Uart_init()也是可以的...

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个简单的Linux UART驱动程序的框架: ```c #include <linux/init.h> #include <linux/module.h> #include <linux/device.h> #include <linux/fs.h> #include <linux/errno.h> #include <linux/types.h> #include <linux/uaccess.h> #include <linux/serial.h> #define DRIVER_NAME "my_uart" // 定义字符设备结构体 struct my_uart_dev { struct cdev cdev; struct class *class; struct device *device; dev_t devno; struct uart_port uart; }; static int my_uart_open(struct inode *inode, struct file *filp) { struct my_uart_dev *dev = container_of(inode->i_cdev, struct my_uart_dev, cdev); filp->private_data = dev; // 初始化串口 uart_config(&dev->uart); return 0; } static ssize_t my_uart_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos) { struct my_uart_dev *dev = filp->private_data; ssize_t ret; // 从串口读取数据到buf中 ret = uart_read(&dev->uart, buf, count); return ret; } static ssize_t my_uart_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos) { struct my_uart_dev *dev = filp->private_data; ssize_t ret; // 将buf中的数据写入到串口中 ret = uart_write(&dev->uart, buf, count); return ret; } static const struct file_operations my_uart_fops = { .owner = THIS_MODULE, .open = my_uart_open, .read = my_uart_read, .write = my_uart_write, }; static int __init my_uart_init(void) { int ret; struct my_uart_dev *dev; // 分配设备结构体的内存 dev = kzalloc(sizeof(*dev), GFP_KERNEL); if (!dev) { ret = -ENOMEM; goto err_alloc_dev; } // 初始化串口 uart_init_port(&dev->uart); // 注册字符设备 dev->devno = MKDEV(0, 0); ret = alloc_chrdev_region(&dev->devno, 0, 1, DRIVER_NAME); if (ret < 0) { goto err_alloc_chrdev_region; } cdev_init(&dev->cdev, &my_uart_fops); dev->cdev.owner = THIS_MODULE; ret = cdev_add(&dev->cdev, dev->devno, 1); if (ret < 0) { goto err_cdev_add; } // 创建设备节点 dev->class = class_create(THIS_MODULE, DRIVER_NAME); if (IS_ERR(dev->class)) { ret = PTR_ERR(dev->class); goto err_class_create; } dev->device = device_create(dev->class, NULL, dev->devno, NULL, DRIVER_NAME); if (IS_ERR(dev->device)) { ret = PTR_ERR(dev->device); goto err_device_create; } return 0; err_device_create: class_destroy(dev->class); err_class_create: cdev_del(&dev->cdev); err_cdev_add: unregister_chrdev_region(dev->devno, 1); err_alloc_chrdev_region: kfree(dev); err_alloc_dev: return ret; } static void __exit my_uart_exit(void) { struct my_uart_dev *dev = container_of(&my_uart_fops, struct my_uart_dev, cdev); // 删除设备节点 device_destroy(dev->class, dev->devno); class_destroy(dev->class); // 注销字符设备 cdev_del(&dev->cdev); unregister_chrdev_region(dev->devno, 1); // 释放设备结构体的内存 kfree(dev); } module_init(my_uart_init); module_exit(my_uart_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Your name"); MODULE_DESCRIPTION("My UART driver"); ``` 需要注意的地方: 1. 在字符设备结构体`my_uart_dev`中,有一个`struct uart_port uart`成员,用来保存串口的状态。 2. 在驱动初始化函数`my_uart_init`中,需要分配`my_uart_dev`结构体的内存,并初始化`struct uart_port uart`成员。 3. 在驱动初始化函数`my_uart_init`中,需要注册字符设备,并创建设备节点。 4. 在驱动退出函数`my_uart_exit`中,需要删除设备节点,并注销字符设备。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值