嵌入式系统与应用实验指导报告书

  • 格式:doc
  • 大小:2.08 MB
  • 文档页数:31

安徽工业大学 嵌入式系统与应用 实验报告册

学院: 电气与信息工程学院 专业: 测控技术与仪器 姓名: 学号: - 1 -

实验一 Linux认知实验 一、实验目的: 1、通过实验,掌握Linux操作系统下常用的命令,能灵活运用这些命令完成特定的工作; 2、学习Linux下文本编辑器vi的使用方法。

二、实验内容: 1、新建文件hello.c,文件位于/home/test/ 目录下; 2、使用vi编辑

三、实验步骤: 1、打开电脑上的虚拟机,加载Linux系统。 2、输入密码进入系统后,按ctrl + Alt + t打开终端; 3、使用mkdir建立/home/test文件夹; 4、使用chmod命令修改文件夹权限; 5、使用vi打开hello.c文件,从而新建文件; 6、在hello.c文件中输入程序,使得程序能够显示打印字符: “Hello,Linux!”

四、实验结果:(包括代码源码和运行结果) 1、源代码 (1)hello.c程序代码:

#include "stdio.h" int main() { printf("hello linux!\n"); }

(2)修改文件夹权限: 用chmod修改文件夹权限 lv@lv-pc:~$ cd test1 lv@lv-pc:~/test1$ ls -l 总用量 28 -rwxr-xr-x 1 lv lv 8136 5月 7 11:36 a.out -rwxr-xr-x 1 lv lv 7869 5月 11 09:10 main -rw-r--r-- 1 lv lv 250 5月 7 11:35 main.c -rwxr-xr-x 1 lv lv 8136 3月 30 20:28 mian lv@lv-pc:~/test1$ chmod 733 a.out - 2 -

lv@lv-pc:~/test1$ ls -l 总用量 28 -rwx-wx-wx 1 lv lv 8136 5月 7 11:36 a.out -rwxr-xr-x 1 lv lv 7869 5月 11 09:10 main -rw-r--r-- 1 lv lv 250 5月 7 11:35 main.c -rwxr-xr-x 1 lv lv 8136 3月 30 20:28 mian

2、实验结果

五、思考: 在建立文件夹的过程中,如果不进入管理员权限,会出现什么问题?同样,不进入管理员权限,vi编辑完代码,能不能保存退出?chmod后面的数字参数是什么含义?

答:会出现:键入mkdir test后显示: 无法创建目录"test": 权限不够的问题。不进入管理员权限,vi编辑完代码,不能保存退出。 想对文件夹所修改成的权限。 - 3 -

实验二 交叉编译实验 一、实验目的: 1、通过实验,掌握交叉编译的原理,理解文件系统挂载的原理; 2、掌握交叉编译工具的使用,学会使用两种不同的方式访问目标板系统,学会使用gdb对程序进行调试。

二、实验内容: 编辑hello.c程序,使用交叉编译工具进行编译,生成可执行文件,分别使用minicom和telnet 登录到目标板上,对程序进行运行调试。

三、实验步骤: 1、打开电脑上的虚拟机,加载Linux系统。 2、Linux系统登录完毕,设置PC机网络地址为192.168.0.10,其中子网掩码为255.255.255.0,连接好实验箱上的电源、网线和USB转串口工具以及串口延长线。 3、按ctrl + Alt + t打开终端,输入sudo minicom打开minicom,查看串口设置是否正确,进行串口设置; 4、打开试验箱电源,查看启动代码,启动完成后,实验箱屏幕显示界面,按“Ctrl+c”,然后按“Enter”,进入板子系统。 5、在文件系统(/home/nfs)下的test文件夹下,建立hello.c的程序,程序中输入相应程序,实现打印信息“hello,linux”并换行输出1~10; 6、再打开一个终端,在该终端中转到文件系统test文件夹,使用交叉编译工具对hello.c进行编译。 7、在minicom中,目录转到“/test”文件夹下使用./(你的程序名) 运行程序; 8、使用“gdb 你的程序名”运行程序,设置断点进行程序调试。 9、关闭minicom,终端中输入telnet,然后输入open 192.168.0.11,等待出现“login:”输入“root”,进入目标板系统; 10、目录转到“/test”文件夹下使用./(你的程序名) 运行程序; 11、使用“gdb 你的程序名”运行程序,设置断点进行程序调试。

四、实验结果:(包括代码源码和运行结果) 1、源程序 #include main( ) { int i ; printf(“hello linux!! \n”); for(i=1;i<=10;i++) printf(“this is %d \n”,i); } - 4 -

2、运行结果 wyxj@wyxj-cpu:~$ cd /home/nfs/test wyxj@wyxj-cpu:/home/nfs/test$ ls 129064068 6-3-3-2 demo hello led.c rtc.c watchdog 129064068~ adc gpio hello1 mizi-pda.tar.gz rtcread watchdog.c 6-3-1-1 adc.c gpio.c hello.c readme.txt rtcread.c 6-3-3-1 a.out heee led rtc uart wyxj@wyxj-cpu:/home/nfs/test$ gcc hello.c -o hello wyxj@wyxj-cpu:/home/nfs/test$ ./hello Hello linux!! this is 1 this is 2 this is 3 this is 4 this is 5 this is 6 this is 7 this is 8 this is 9 this is 10 wyxj@wyxj-cpu:/home/nfs/test$ armv4l-unknown-linux-gcc hello.c -o helloarm wyxj@wyxj-cpu:/home/nfs/test$ ./helloarm bash: ./helloarm: 无法执行二进制文件

(1)在Telnet下运行: wyxj@wyxj-cpu:~$ telnet telnet> open 192.168.0.11 Trying 192.168.0.11... Connected to 192.168.0.11. Escape character is '^]'.

Linux 2.4.18-rmk7-pxa1 (192.168.0.11) (0) 192.168.0.11 login: root

BusyBox v0.60.3 (2002.05.13-08:36+0000) Built-in shell (ash) Enter 'help' for a list of built-in commands.

# ./helloarm ./helloarm: No such file or directory # cd test # ./helloarm Hello linux!! - 5 -

this is 1 this is 2 this is 3 this is 4 this is 5 this is 6 this is 7 this is 8 this is 9 this is 10 (2)在minicom下运行:

wyxj@wyxj-cpu:~$ sudo minicom [sudo] password for wyxj: Welcome to minicom 2.6.2 OPTIONS: I18n Compiled on Feb 8 2013, 06:27:51. Port /dev/ttyUSB0, 21:22:32 Press CTRL-A Z for help on special keys Waiting for enter to start '/bin/sh' (pid 46, terminal /dev/console)

Please press Enter to activate this console. Starting pid 46, console /dev/console: '/bin/sh'

BusyBox v0.60.3 (2002.05.13-08:36+0000) Built-in shell (ash) Enter 'help' for a list of built-in commands.

# ls 333.bmp microwindows-0.90 sbin bin mmcsd sheryl.mp3 bomb mnt test dev notebook tmp etc pig.mp3 usr hello.c proc var iceage.mpeg qcop-msg-qpe vcongui lib qcop-msg-quicklauncher linuxrc qtembedded-root # cd test # ./helloarm Hello linux!! this is 1 this is 2 this is 3 this is 4