您的位置:首页 > 编程语言 > ASP

Raspberry Raspbian turning off the UART functioning as a serial console

2016-07-03 22:42 686 查看
(写在前面的话:以下内容参考网上资料,这是我第一篇博客不知道应该是属于转载还是翻译还是原创,厚颜就用原创了,如果不应该是原创请提醒一下,CSDN博客排版不太会,好一点的排版点下面链接: http://note.youdao.com/yws/public/redirect/share?id=54d34d47ed9f904ebcc60425f7e4dda2&type=false)
By default Linux will grab the serial port and use it as a terminal. If you want to use it for other purposes you must prevent this.

Raspbian 系统默认将Raspberry串口即 /dev/ttyAMA0 作为调试中断,如果不关闭直接使用串口,将导致冲突。

默认设置下,连接串口并重启系统,串口将接收下列信息(这里仅仅只是以我的系统为例给大家看一下,信息太多这里只给出一段):

Uncompressing Linux... done, booting the kernel.

Welcome to the rescue system

recovery login: Uncompressing Linux... done, booting the kernel.

[ 0.000000] Booting Linux on physical CPU 0xf00

[ 0.000000] Initializing cgroup subsys cpuset

[ 0.000000] Initializing cgroup subsys cpu

[ 0.000000] Initializing cgroup subsys cpuacct

[ 0.000000] Linux version 4.4.11-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611) ) #888 SMP Mon May 23 20:10:33 BST 2016

[ 0.000000] CPU: ARMv7 Processor [410fc075] revision 5 (ARMv7), cr=10c5387d

[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache

[ 0.000000] Machine model: Raspberry Pi 2 Model B Rev 1.1

[ 0.000000] cma: Reserved 8 MiB at 0x3a800000

[ 0.000000] Memory policy: Data cache writealloc

[ 0.000000] [bcm2709_smp_init_cpus] enter (9520->f3003010)

[ 0.000000] [bcm2709_smp_init_cpus] ncores=4

[ 0.000000] PERCPU: Embedded 13 pages/cpu @b9f63000 s22592 r8192 d22464 u53248

[ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 239540

[ 0.000000] Kernel command line: dma.dmachans=0x7f35 bcm2708_fb.fbwidth=640 bcm2708_fb.fbheight=480 bcm2709.boardrev=0xa21041 bcm2709.serial=0x63ad1526 smsc95xx.macaddr=B8:27:EB:AD:15:26 bcm2708_fb.fbswap=1 bcm2709.uart_clock=3000000 bcm2709.disk_led_gpio=47
bcm2709.disk_led_active_low=0 vc_mem.mem_base=0x3dc00000 vc_mem.mem_size=0x3f000000 dwc_otg.lpm_enable=0 console=tty1 console=ttyAMA0,115200 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

[ 0.000000] PID hash table entries: 4096 (order: 2, 16384 bytes)

[ 0.000000] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes)

[ 0.000000] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes)

[ 0.000000] Memory: 939088K/966656K available (6344K kernel code, 432K rwdata,

......

Raspbian GNU/Linux 8 raspberrypi ttyAMA0

raspberrypi login:

这样就可以直接在使用串口登陆控制Raspbian系统。

关闭串口控制台具体参考:
http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/io-pins-raspbian/uart-pins

Backup the /boot/cmdline.txt file before you edit it just in case of screw-ups(备份/boot/cmdline.txt 以防万一,我有一次编辑错了之后导致系统不能启动):

>>>
sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt

Edit the file (编辑 /boot/cmdline.txt ):

>>>
sudo nano /boot/cmdline.txt

Delete parameters (删除文件下列字段,其余不作修改):

console=ttyAMA0,115200

注意:在2014-09-09-wheezy-raspbian.img系统中,cmdline.txt内容为:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

但在 2015 Raspbian Jessie系统中,cmdline.txt 内容为:

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

因此在Jessie系统中应该删除的是以下字段:

console=serial0,115200

Edit file /etc/inittab (如果使用的是Raspbian Jessie 请不要不管这步骤,因为Jessie中没有inittab文件了):

comment the line (找到文件中包含 ttyAMA0的一行,在行前添加 '#' 字符将其注释掉如):

#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

reboot(重启系统):

>>>sudo reboot

理论上串口应该不会输出系统信息了,可是每次reboot后,上位机依旧收到下面信息(原因不明),但是系统启动后串口便没有其他信息输出了,系统运行期间可以正常驱动串口 /dev/ttyAMA0:

Uncompressing Linux... done, booting the kernel.

Welcome to the rescue system

recovery login: Uncompressing Linux... done, booting the kernel.

凡事总有意外,以下补充我在Raspbian Jessie(老一点的系统可能不会碰到这个)下遇到的问题:

http://elinux.org/RPi_Serial_Connection#Connection_to_a_microcontroller_or_other_peripheral

一开始自己其实是按照上面的 Method 1,raspi-config (easiest, try this first) 来设置的即:

Run sudo raspi-config and
check if it has the option advanced options -> serial.
If it has, set it to disabled and you're done.





disable serial 之后,坑爹的你会发现 ttyAMA0 消失了,没错TMD消失了。



在这种情形下,你调用ttyAMA0会报错找不到该设备。网上找解决:
https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=151922

This issue is that when you disable the serial port for boot using raspi-config, the serial
port is also disabled for ANY use.

To fix this you MUST set "enable_uart=1" in /boot/config.txt

This is really a bug in raspi-config.

通过raspi-configdisable serial 并不是不将串口作为系统调试控制端了,它直接修改
/boot/config.txt中的 enable_uart=0了。就是把串口停了,我不用你也别想用?所以想在Raspbian Jessie系统x中使用串口的话,一定要 enable serial不要disable serial,确保/boot/config.txt中 enable_uart=1。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  raspberry pi