各位大神,新购买TI ompal138开发板,LINUX内核使用linux-3.3-psp03-22.00.06.sdk.学习使用UART1输入输出,是否能提供UART1的测试例程。谢谢!
Tony Tang:
SDK_UART1.zip
参考一下附件里的内容。很久以前做的,自己都忘了。
user4804899:
回复 Tony Tang:
Hi tony tang,首先感谢你提供的例子。
我使用的是LCDK的开发板,linux内核使用开发板配套提供的linux-3.3-psp03-22.00.06.sdk。
我修改了部分初始化配置:
omapl138_lcdk_init
//1. 添加UART1 pinmux设置
ret = davinci_cfg_reg_list(da850_uart1_pins); if (ret) pr_warning("omapl138_lcdk_init: UART 1 mux setup failed:" " %d\n", ret);
//2.去掉 shut down UART1
//__raw_writel(0, IO_ADDRESS(DA8XX_UART1_BASE) + 0x30);
启动内核后,调用UART1发送程序。
./uart_rw /dev/ttyS1 write test_w.txt
其中uart_rw是按以下程序编译的.o文件,test_w.txt内写的“hello!”.
但实际测量UART1_TXD电平没有任何改变。
请教下,使用设备节点/dev/ttyS1控制UART1输出,是否还需在原先内核基础在做其他程序修改。
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <termios.h>#include <strings.h>#include <errno.h>#include <string.h>
#define BUFFER_SIZE 2048
/* write data into uart */int writedata(int fd, char file[]) { char buf_r[BUFFER_SIZE]; int fd_r, localfile_num, fd_dev = fd;
bzero(buf_r, sizeof(buf_r));
// open local file if ((fd_r = open(file, O_RDONLY)) < 0) { perror("open"); return -1; } // read local file if ((localfile_num = read(fd_r, buf_r, sizeof(buf_r))) < 0) { perror("read"); return -1; } // send data if ((write(fd_dev, buf_r, localfile_num)) < 0) { perror("write"); return -1; }
close (fd_r);
return 0;}
/* read data from uart */int readdata(int fd, char file[]) { char buf_w[BUFFER_SIZE]; int fd_w, recv_num, fd_dev = fd; bzero(buf_w, sizeof(buf_w));
// receive data if ((recv_num = read(fd_dev, buf_w, sizeof(buf_w))) < 0) { perror("read"); return -1; }
printf("data from uart is: %s\n", buf_w); printf("\n");
// open another local file if ((fd_w = open(file, O_WRONLY | O_CREAT)) < 0) { perror("open"); return -1; }
// write data into local file if ((write(fd_w, buf_w, recv_num)) < 0) { perror("write"); return -1; }
close (fd_w);
return 0;}
int main(int argc, char *argv[]) { int fd_dev; struct termios Opt; struct termios Option; // check input arguments if (argc != 4) { printf("please check your input.such as:\n"); printf("./uart_rw [/dev/ttyS1] read/write [/media/text_w.txt]\n"); return -1; } // open serial uart1 if ((fd_dev = open(argv[1], O_RDWR)) < 0) { perror("open"); return -1; } // define termois Option.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); Option.c_oflag &= ~OPOST; tcgetattr(fd_dev, &Opt); cfsetispeed(&Opt, B115200); cfsetospeed(&Opt, B115200); tcsetattr(fd_dev, TCSANOW, &Opt); // if choose read data if (!strcmp(argv[2], "read")) readdata(fd_dev, argv[3]);
// if choose write data else if (!strcmp(argv[2], "write")) writedata(fd_dev, argv[3]);
else printf("please check the third argument\n"); close (fd_dev);
return 0;}
Shine:
回复 user4804899:
把R205和R208去掉, R206,R209短路。或者直接量R206处看有没有数据输出。
user4804899:
回复 Shine:
搞定了,代码除了上述修改的初始化,还有一处需要修改:
davinci_serial_init
//此处需要添加为d850也执行davinci_serial_reset
if ((p->membase && p->type != PORT_AR7) || cpu_is_davinci_da830()) davinci_serial_reset(p);