BeagleBone Black 尝试

  cheney

公司给买了Beaglebone Black的开发板,打算以后转移到Cortex-A8平台上来,让我先做一些准备工作。近来单板计算机是很火喽,但是拿到手还是很惊讶这么小的东西已经达到一般PC的能力了。

  • 硬件参数:

    • 1GHz XAM3359AZCZ
    • 512MB DDR3L
    • 32KB EEPROM I2C0
    • 2G eMMC
  • boot 方式支持:

    • eMMC boot (默认)
    • SD boot
    • 串口 用来下载软件

不按键 eMMC方式,如果eMMC为空,自动切换到SD,没有SD,切换到串口。
按下boot键,跳过eMMC,检查SD,没有SD,切换到串口。

  • HDMI 支持分辨率
    • 1280 x 1024
    • 1440 x 900
    • 1024 x 768
    • 1280 x 720

阵容不可谓不强大,但是有个地方还是让人觉得好笑哦,J1插针里面有一根跳线,哈哈,这么畅销全球的东西尽然也跟我做的东西似的要拉跳线,外国人就是这么搞。官方的解释是:“Added a 100K pull down resistor from J1 pin 1 to J1 pin 4 to fix the unterminated serial port issue.”为了串口电平默认情况下保持稳态。我以后也要注意这个。

Beaglebone black 开机接上鼠标显示器就是一台电脑。默认操作系统是Angstrom,默认GCC版本


	root@beaglebone:~# gcc -v
	
	Using built-in specs.
	
	COLLECT_GCC=gcc
	
	COLLECT_LTO_WRAPPER=/usr/libexec/gcc/arm-angstrom-linux-gnueabi/4.7.3/lto-wrapper
	
	Target: arm-angstrom-linux-gnueabi
	
	Configured with: /build/v2012.12/build/tmp-angstrom_v2012_12-eglibc/work-shared/gcc-linaro-4.7-r9/gcc-linaro-4.7-2013.02-01/configure --build=x86_64-linux --host=arm-angstrom-linux-gnueabi --target=arm-angstrom-linux-gnueabi --prefix=/usr --exec_prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/libexec --datadir=/usr/share --sysconfdir=/etc --sharedstatedir=/com --localstatedir=/var --libdir=/usr/lib --includedir=/usr/include --oldincludedir=/usr/include --infodir=/usr/share/info --mandir=/usr/share/man --disable-silent-rules --disable-dependency-tracking --with-libtool-sysroot=/build/v2012.12/build/tmp-angstrom_v2012_12-eglibc/sysroots/beaglebone --with-gnu-ld --enable-shared --enable-languages=c,c++ --enable-threads=posix --disable-multilib --enable-c99 --enable-long-long --enable-symvers=gnu --enable-libstdcxx-pch --program-prefix=arm-angstrom-linux-gnueabi- --without-local-prefix --enable-target-optspace --enable-lto --enable-libssp --disable-bootstrap --disable-libgomp --disable-libmudflap --with-system-zlib --with-linker-hash-style=gnu --with-ppl=no --with-cloog=no --enable-checking=release --enable-cheaders=c_global --with-sysroot=/ --with-build-sysroot=/build/v2012.12/build/tmp-angstrom_v2012_12-eglibc/sysroots/beaglebone --with-native-system-header-dir=/build/v2012.12/build/tmp-angstrom_v2012_12-eglibc/sysroots/beaglebone/usr/include --with-gxx-include-dir=/usr/include/c++/ --enable-nls
	
	Thread model: posix
	
	gcc version 4.7.3 20130205 (prerelease) (Linaro GCC 4.7-2013.02-01)

自带GCC,不需要别的交叉编译的PC就能自己写程序了。

默认的是纯英文界面,如果需要中文需要自己添加:

	opkg install eglibc-localedata-zh-cn eglibc-binary-localedata-zh-cn

开机的时候会有语言选择界面。

如果要自己编译一份自己的系统,手册里都写的很清楚了,我用UBUNTU系统:

获取UBOOT源码:git clone git://git.denx.de/u-boot.git

获取内核换吗:git clone git://github.com/beagleboard/kernel.git

源码预处理:

	cd ~/kernel
	
	git checkout origin/3.8 –b 3.8
	
	./patch.sh

安装交叉编译工具

	wget https://sourcery.mentor.com/sgpp/portal/package7851/public/arm-none-linux-gnueabi/arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
	
	tar jxvf arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2

交叉编译用的GCC版本:

	channe@channe-desktop:~/arm-2010.09/bin$ arm-none-linux-gnueabi-gcc -v
	
	Using built-in specs.
	
	COLLECT_GCC=arm-none-linux-gnueabi-gcc
	
	COLLECT_LTO_WRAPPER=/home/channe/arm-2010.09/bin/../libexec/gcc/arm-none-linux-g nueabi/4.5.1/lto-wrapper
	
	Target: arm-none-linux-gnueabi
	
	Configured with: /scratch/nathan/arm-lite/src/gcc-4.5-2010.09/configure --build= i686-pc-linux-gnu --host=i686-pc-linux-gnu --target=arm-none-linux-gnueabi --ena ble-threads --disable-libmudflap --disable-libssp --disable-libstdcxx-pch --enab le-extra-sgxxlite-multilibs --with-arch=armv5te --with-gnu-as --with-gnu-ld --wi th-specs='%{save-temps: -fverbose-asm} %{funwind-tables|fno-unwind-tables|mabi=* |ffreestanding|nostdlib:;:-funwind-tables} -D__CS_SOURCERYGXX_MAJ__=2010 -D__CS_ SOURCERYGXX_MIN__=9 -D__CS_SOURCERYGXX_REV__=50 %{O2:%{!fno-remove-local-statics : -fremove-local-statics}} %{O*:%{O|O0|O1|O2|Os:;:%{!fno-remove-local-statics: - fremove-local-statics}}}' --enable-languages=c,c++ --enable-shared --enable-lto --enable-symvers=gnu --enable-__cxa_atexit --with-pkgversion='Sourcery G++ Lite 2010.09-50' --with-bugurl=https://support.codesourcery.com/GNUToolchain/ --disab le-nls --prefix=/opt/codesourcery --with-sysroot=/opt/codesourcery/arm-none-linu x-gnueabi/libc --with-build-sysroot=/scratch/nathan/arm-lite/install/arm-none-li nux-gnueabi/libc --with-gmp=/scratch/nathan/arm-lite/obj/host-libs-2010.09-50-ar m-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-mpfr=/scratch/nathan/arm-lite/ obj/host-libs-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-mpc =/scratch/nathan/arm-lite/obj/host-libs-2010.09-50-arm-none-linux-gnueabi-i686-p c-linux-gnu/usr --with-ppl=/scratch/nathan/arm-lite/obj/host-libs-2010.09-50-arm -none-linux-gnueabi-i686-pc-linux-gnu/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-cloog=/scratch/nathan/arm-lite/obj/h ost-libs-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu/usr --with-libelf=/ scratch/nathan/arm-lite/obj/host-libs-2010.09-50-arm-none-linux-gnueabi-i686-pc- linux-gnu/usr --disable-libgomp --enable-poison-system-directories --with-build- time-tools=/scratch/nathan/arm-lite/install/arm-none-linux-gnueabi/bin --with-bu ild-time-tools=/scratch/nathan/arm-lite/install/arm-none-linux-gnueabi/bin
	
	Thread model: posix
	
	gcc version 4.5.1 (Sourcery G++ Lite 2010.09-50)
	
	export PATH=~/arm-2010.09/bin:$PATH

执行以下命令来为mkimage添加环境变量

	export PATH=~/u-boot/am335x/tools:$PATH

编译u-boot

	$ cd ~/u-boot
	
	$ [ -d ./am335x ] && rm -rf ./am335x
	
	$ make O=am335x CROSS_COMPILE=arm-none-linux-gnueabi- ARCH=arm am335x_evm

编译内核

	$ cd ~/kernel/kernel
	
	$ cp ../configs/beaglebone .config
	
	$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- uImage dtbs

内核目录下有一份README文档,有更详细的步骤,按照这个来,不然有错误。因为有一部分是要直接用am335x-pm-firmware.bin

Beaglebone Black 外设控制

学习控制外设总是从GPIO开始。Beaglebone Black板上在并不是所有的IO口都能随便用的。有些是专用引脚,不能作为GPIO口,有些已经作为其他用途了,更改模式可能带来无法预料的错误。不过一个牛人已经列了一个表,点这里下载

看了表之后看到P9-11 P9-12 就是够用作GPIO。

定义两个环境变量方便后面操作:

	export SLOTS=/sys/devices/bone_capemgr.9/slots
	
	export PINS=/sys/kernel/debug/pinctrl/44e10800.pinmux/pins

也可以写到.profile文件,这样每次都会有了。

	root@beaglebone:~# cat $SLOTS
	0: 54:PF---
	1: 55:PF---
	2: 56:PF---
	3: 57:PF---
	4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
	5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI

4和5,关于EMMC和HDMI的配置

	root@beaglebone:~# more $PINS
	registered pins: 142
	pin 0 (44e10800) 00000031 pinctrl-single
	pin 1 (44e10804) 00000031 pinctrl-single
	pin 2 (44e10808) 00000031 pinctrl-single
	pin 3 (44e1080c) 00000031 pinctrl-single
	pin 4 (44e10810) 00000031 pinctrl-single
	pin 5 (44e10814) 00000031 pinctrl-single
	pin 6 (44e10818) 00000031 pinctrl-single
	pin 7 (44e1081c) 00000031 pinctrl-single
	pin 8 (44e10820) 00000027 pinctrl-single
	pin 9 (44e10824) 00000027 pinctrl-single
	pin 10 (44e10828) 00000027 pinctrl-single
	pin 11 (44e1082c) 00000027 pinctrl-single
	pin 12 (44e10830) 00000027 pinctrl-single
	pin 13 (44e10834) 00000027 pinctrl-single
	pin 14 (44e10838) 00000027 pinctrl-single
	pin 15 (44e1083c) 00000027 pinctrl-single
	pin 16 (44e10840) 00000027 pinctrl-single
	pin 17 (44e10844) 00000027 pinctrl-single
	pin 18 (44e10848) 00000027 pinctrl-single
	pin 19 (44e1084c) 00000027 pinctrl-single
	pin 20 (44e10850) 00000017 pinctrl-single
	pin 21 (44e10854) 00000007 pinctrl-single

显示出142个引脚的寄存器地址和配置。

0x7 下拉输出;0x17 上拉输出;0x27下拉输入;0x37上拉输入。末尾的7如果是F表示没有上下拉。

我们需要把P9-11,也就是 28号引脚,同时也是GPIO30 这个引脚配置为上拉输入 0x37。把P9-12,也就是30号引脚,同时也是GPIO60 的引脚配置为输出 0xF。

要把这个模式写到芯片里,需要便编写.dts


	/*
	* Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
	
	* This program is free software; you can redistribute it and/or modify
	
	* it under the terms of the GNU General Purpose License Version 2 as
	
	* published by the Free Software Foundation
	
	* Original from: github.com/jadonk/validation-scripts/blob/master/test-capemgr/
	
	* Modified by Derek Molloy for the example on www.derekmolloy.ie
	
	* that maps GPIO pins for the example
	*/
	 
	  /dts-v1/;
	 
	  /plugin/;
	 
	  /{
	 
	  compatible = "ti,beaglebone", "ti,beaglebone-black";
	 
	  part-number = "GPIO-DTEST";
	 
	  version = "0A00";
	 
	  fragment@0 {
	  
		  target = <&am33xx_pinmux>;
		 
		  __overlay__ {
		  
			  pinctrl_test: GPIO_DTEST {
			 
				  pinctrl-single,pins = <
				 
				  0x70 0x2F  /* P9_11 15 Button */
				  0x78 0x07  /* P9_12 60  LED  */
				 
				  >
			  };
		  };
	  };
	  
	  fragment@1 {
	 
		  target = &lt;&amp;ocp&gt;;
		 
		  __overlay__ {
		 
			  test_helper: helper {
			 
				  compatible = "bone-pinmux-helper";
				  
				  pinctrl-names = "default";
				  
				  pinctrl-0 = <&GPIO_DTEST>;
				  status = "OK";
			  };
		  };
	  };
	  };

用命令可以编译出设备树文件

	  dtc –O dtb –o GPIO-DTEST-00A0.dtbo –b 0 –@ GPIO-DTEST.dts

把设备树文件拷贝到 /lib/firmware 目录下

注册进slots文件


	echo GPIO-DTEST &gt; $SLOTS

重新查看引脚配置应该已经改变。

用一个SHELL脚本可以简单的实现效果。


 	#!/bin/sh -
 
	GPIO=/sys/class/gpio
	
	echo 30 > $GPIO/export
	
	echo "in" > $GPIO/gpio30/direction
	
	echo 60 > $GPIO/export
	
	echo "out" > $GPIO/gpio60/direction
	
	while true
	
	do
	
	cat $GPIO/gpio30/value > $GPIO/gpio60/value
	
	cat $GPIO/gpio30/value
	
	sleep 1
	
	done

这种方法是基于已有的驱动,操作设备虚拟文件的方式来控制的。另外还有别的控制方法,写到下一篇。