主题 : micro2440开发板的串口2无法通信,求前辈们指教 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 125216
精华: 0
发帖: 4
金钱: 20 两
威望: 4 点
贡献值: 0 点
综合积分: 8 分
注册时间: 2016-05-13
最后登录: 2016-05-25
楼主  发表于: 2016-05-15 14:28

 micro2440开发板的串口2无法通信,求前辈们指教

在做串口驱动开发的时候,串口0和1都可以正常通信,但是换成串口2就无法从串口助手上接收到数据了。求前辈们指教可能是什么问题或者该怎么去查找问题的所在
驱动程序如下:
#include <linux/module.h>
#include <linux/kernel.h>
#include <asm/uaccess.h>
#include <linux/serial_core.h>
#include <asm/io.h>
#include <plat/regs-serial.h>

#define BUFSIZE 100
#define ttyS0_MAJOR 240
#define iobase S3C24XX_VA_UART2                             //当宏定义为S3C24XX_VA_UART1和S3C24XX_VA_UART0的时候,串口1和串口0都可以正常工作
#define UART_ULCON0 iobase
#define UART_UCON0 (iobase+0x4)
#define UART_UFCON0 (iobase+0x8)
#define UART_UTRSTAT0 (iobase+0x10)
#define UART_UTXH0 (iobase+0x20)
#define UART_URXH0 (iobase+0x24)
#define UART_UBRDIV0 (iobase+0x28)

int s3c2440_open(struct inode * inode, struct file * filp)
{
    writel(3, UART_ULCON0);
    writel(5, UART_UCON0);
    writel(26, UART_UBRDIV0);
    printk("open OK\n");

    return 0;
}

ssize_t s3c2440_write(struct file * filp, const char __user * buf, size_t count, loff_t * f_pos)
{
    char wbuf[BUFSIZE] = {0};
    int state;
    int i = 0;
    copy_from_user(wbuf, buf, count);
    while(wbuf != '\0')
    {
        state = readl(UART_UTRSTAT0);
        if(2 == (0x02 & state))
        {
            printk("%c", wbuf);
            writeb(wbuf, UART_UTXH0);
            i++;
        }
    }
    printk("write OK\n");

    return 0;
}

ssize_t s3c2440_read(struct file * filp, char __user * buf, size_t count, loff_t * f_ops)
{
    char rbuf[1] = {0};
    int state;
    state = readl(UART_UTRSTAT0);
    if(1 == (0x01 & state))
    {
        rbuf[0] = readb(UART_URXH0);
        copy_to_user(buf, rbuf, 1);
    }
    else
    {
        set_current_state(TASK_INTERRUPTIBLE);
        schedule_timeout(10);
    }
    return 0;
}

int s3c2440_release(struct inode * inode, struct file * filp)
{
    return 0;
}

struct file_operations ttyS0_fops =
{
    .owner = THIS_MODULE,
    .open = s3c2440_open,
    .write = s3c2440_write,
    .read = s3c2440_read,
    .release = s3c2440_release,
};

int __init s3c2440_init(void)
{
    int rc;
    printk("s3c2440 serial module loaded!\n");

    rc = register_chrdev(ttyS0_MAJOR, "ttyS0", &ttyS0_fops);
    if(rc < 0)
    {
        printk("Error: register ttyS0 device error!\n");
        return -1;
    }

    return 0;
}

void __exit s3c2440_exit(void)
{
    unregister_chrdev(ttyS0_MAJOR, "ttyS0");
}

module_init(s3c2440_init);
module_exit(s3c2440_exit);

MODULE_AUTHOR("s3c2440");
MODULE_DESCRIPTION("s3c2440 serial driver");
MODULE_LICENSE("GPL");

运行该程序时,控制台可以看到输出:
open OK
send test                      注:客户端待写入数据
write OK

但是连接串口2的串口助手并不能收到写入的数据,在连接串口2的串口助手界面输入开发板也接收不到数据。



检查过串口助手波特率是115200,根据串口2和串口1的波特率设置情况分析可以得出波特率正确

也分别用平行线和交叉线试过连接串口助手,都接收不到数据

文件arch/arm/mach-s3c2440/mach-mini2440.c中已经改成
static struct s3c2410_uartcfg mini2440_uartcfgs[] __initdata = {
      [0] = {
          .hwport      = 0,
          .flags       = 0,
          .ucon        = 0x3c5,
          .ulcon       = 0x03,
          .ufcon       = 0x51,
      },
      [1] = {
          .hwport      = 1,
          .flags       = 0,
          .ucon        = 0x3c5,
          .ulcon       = 0x03,
          .ufcon       = 0x51,
      },
      [2] = {
          .hwport      = 2,
          .flags       = 0,
          .ucon        = 0x3c5,
          .ulcon       = 0x03,
         .ufcon       = 0x51,
     }
};
并重新编译烧录,还是收不到数据。
有没有前辈遇到过这种问题?
级别: 新手上路
UID: 125216
精华: 0
发帖: 4
金钱: 20 两
威望: 4 点
贡献值: 0 点
综合积分: 8 分
注册时间: 2016-05-13
最后登录: 2016-05-25
1楼  发表于: 2016-05-17 09:38
没有前辈遇到过嘛
级别: 新手上路
UID: 125216
精华: 0
发帖: 4
金钱: 20 两
威望: 4 点
贡献值: 0 点
综合积分: 8 分
注册时间: 2016-05-13
最后登录: 2016-05-25
2楼  发表于: 2016-05-17 09:39
现在不知道该怎么调试找不到问题在哪儿 求指教。。。
级别: 新手上路
UID: 136362
精华: 0
发帖: 11
金钱: 55 两
威望: 11 点
贡献值: 0 点
综合积分: 22 分
注册时间: 2018-01-06
最后登录: 2020-06-28
3楼  发表于: 2020-06-18 14:11
我也遇到类似问题,调整波特率后虽然可以收到数据,但是全部为乱码。
不明白其中原因。韦神没有回答过类似问题?