测试新唐nuc980串口功能的过程,如下:
git clone https://github.com/OpenNuvoton/NUC970_Buildroot
或者
git clone https://gitee.com/OpenNuvoton/NUC970_Buildroot.git
4.输入 **make ** ,开始进行 Compile ,成功后 NUC980 BSP 相关的文件就会出现在NUC970_Buildroot目录下面的output 这个子目录。如下:
/****************************************************************************
* *
* Copyright (c) 2014 Nuvoton Technology Corp. All rights reserved. *
* *
****************************************************************************/
/****************************************************************************
*
* FILENAME
* uart_test.c
*
* VERSION
* 1.0
*
* DESCRIPTION
* This is the test program used to test the UARTs on NUC980 EV board
*
* DATA STRUCTURES
* None
*
* FUNCTIONS
* None
*
* HISTORY
*
*
* REMARK
* None
****************************************************************************/
#include < stdio.h >
#include < stdlib.h >
#include < unistd.h >
#include < sys/types.h >
#include < sys/stat.h >
#include < fcntl.h >
#include < termios.h >
#include < errno.h >
#include < string.h >
#include < signal.h >
#include < pthread.h >
#define FALSE 0
#define TRUE 1
int fd[2];
pthread_t threads[10];
char buff[101];
static struct termios newtios,oldtios; /*termianal settings */
static int saved_portfd=-1; /*serial port fd */
static void reset_tty_atexit(void)
{
if(saved_portfd != -1)
{
tcsetattr(saved_portfd,TCSANOW,&oldtios);
}
}
/*cheanup signal handler */
static void reset_tty_handler(int signal)
{
if(saved_portfd != -1)
{
tcsetattr(saved_portfd,TCSANOW,&oldtios);
}
_exit(EXIT_FAILURE);
}
static int open_port(const char *portname)
{
struct sigaction sa;
int portfd;
printf("opening serial port:%sn",portname);
/*open serial port */
if((portfd=open(portname,O_RDWR | O_NOCTTY)) < 0 )
{
printf("open serial port %s fail n ",portname);
return portfd;
}
/*get serial port parnms,save away */
tcgetattr(portfd,&newtios);
memcpy(&oldtios,&newtios,sizeof newtios);
/* configure new values */
cfmakeraw(&newtios); /*see man page */
newtios.c_iflag |=IGNPAR; /*ignore parity on input */
newtios.c_oflag &= ~(OPOST | ONLCR | OLCUC | OCRNL | ONOCR | ONLRET | OFILL);
newtios.c_cflag = CS8 | CLOCAL | CREAD;
newtios.c_cc[VMIN]=1; /* block until 1 char received */
newtios.c_cc[VTIME]=0; /*no inter-character timer */
/* 115200 bps */
cfsetospeed(&newtios,B115200);
cfsetispeed(&newtios,B115200);
/* register cleanup stuff */
atexit(reset_tty_atexit);
memset(&sa,0,sizeof sa);
sa.sa_handler = reset_tty_handler;
sigaction(SIGHUP,&sa,NULL);
sigaction(SIGINT,&sa,NULL);
sigaction(SIGPIPE,&sa,NULL);
sigaction(SIGTERM,&sa,NULL);
/*apply modified termios */
saved_portfd=portfd;
tcflush(portfd,TCIFLUSH);
tcsetattr(portfd,TCSADRAIN,&newtios);
return portfd;
}
void * process1(void* arg)
{
int portfd = (int) arg;
unsigned char i, j;
int rev1, rev2;
char RxBuffer[101];
rev1 =0;
rev2 =0;
while(rev2 < 100)
{
rev1 = write(portfd,(buff+rev2),100);
rev2 += rev1;
}
printf("n uart1 send %d bytsn", rev2);
rev1 = 0;
rev2 = 0;
while(rev2 < 100)
{
rev1 = read(portfd,(RxBuffer+rev2),100);
rev2 += rev1;
}
printf("n uart1 receive %d bytesn", rev2);
for(i = 0; i < 100; i++)
{
if(i != RxBuffer[i])
{
printf("n uart1 compare Error!!");
while(1);
}
}
printf("n uart1 compare correct!!n");
printf("n uart1 test done!!n");
}
void * process2(void* arg)
{
int portfd = (int) arg;
unsigned char i, j;
int rev1, rev2;
char RxBuffer[101];
rev1 =0;
rev2 =0;
while(rev2 < 100)
{
rev1 = write(portfd,(buff+rev2),100);
rev2 += rev1;
}
printf("n uart2 send %d bytes n", rev2);
rev1 = 0;
rev2 = 0;
while(rev2 < 100)
{
rev1 = read(portfd,(RxBuffer+rev2),100);
rev2 += rev1;
}
printf("n uart2 receive %d bytes n", rev2);
for(i = 0; i < 100; i++)
{
if(i != RxBuffer[i])
{
printf("n uart2 compare Error!!");
while(1);
}
}
printf("n uart2 compare correct!!n");
printf("n uart2 test done!!n");
}
/**
*@breif main()
*/
int main(int argc, char **argv)
{
char *dev[10]={"/dev/ttyS1", "/dev/ttyS2"};
unsigned int i;
printf("n demo uart1/uart2 external loop back function n");
for(i = 0; i < 100; i++)
{
buff[i] = (i & 0xff);
}
for(i = 0; i < 2; i++)
{
if((fd[i] = open_port(dev[i]))< 0)
return -1;
}
pthread_create(&threads[0], NULL, process1, (void*)(fd[0]));
pthread_create(&threads[1], NULL, process2, (void*)(fd[1]));
pthread_join(threads[0], NULL);
pthread_join(threads[1], NULL);
return 0;
}
8.输入 **make **编译。
9.编译完之后,拷贝相关文件,共四个文件
拷贝 NUC970_Buildroot/output/images 文件夹下的 **uImage **文件;
拷贝 NUC970_Buildroot/output/build/uboot-master 文件夹下的u-boot.bin 文件 ;
拷贝 NUC970_Buildroot/output/build/uboot-master/spl 文件夹下的u-boot-spl.bin 文件;
拷贝 NUC970_Buildroot 文件夹下的 env.txt 文件。这里在 NUC970_Buildroot 文件夹下 未发现env.txt,从别的地方拷贝一份即可。env.txt的内容如下:
baudrate=115200
bootdelay=1
stderr=serial
stdin=serial
stdout=serial
setspi=sf probe 0 30000000
loadkernel=sf read 0x7fc0 0x200000 0x800000
bootcmd=run setspi;run loadkernel;bootm 0x7fc0
10.选择boot启动方式,上电进行镜像下载,(参考: 新唐Nuc980学习笔记1 - 工程创建和下载 )
u-boot-spl.bin 选择Loader默认Image execute address:0x 200 ;下载即可
u-boot.bin 选择 Data下载到 Image start offset: 0x 100000 ; 下载即可
uImage选择Data下载到 Image start offset: 0x 200000 ; 下载即可
**env.txt **选择 Environment下载到 Image start offset: 0x 80000 ; 下载即可
11.选择boot启动方式,复位运行(参考: 新唐Nuc980学习笔记1 - 工程创建和下载 )
12.开机之后的画面如下:
13.输入测试指令 ./usr/bin/uart_demo,可看到串口功能测试符合预期,测试结果如下:
注意:
【 以下动作只需要在更新 Buildroot 工具时使用 】
进入Buildroot 资料夹后请输入以下指令:
git reset --hard
git pull
更新完成后进入 dl 资料夹,先将既有的 linux kernel 与 u-boot 删除,并输入以下指令:
sudo rm -rf linux-master.tar.gz
输入密码 user,并输入以下指令:
sudo rm -rf uboot-master.tar.gz
离开 dl 资料夹,进入 Builroot 资料夹下 make clean。
全部0条评论
快来发表一下你的评论吧 !