2019-07-04 | UNLOCK

2019-7-4-usrpb210环境搭建

usrp b210的环境搭建

我的环境VM14+ubuntu16.04虚拟机
官方文档:https://kb.ettus.com/Building_and_Installing_the_USRP_Open-Source_Toolchain_(UHD_and_GNU_Radio)_on_Linux

新的ubuntu还需要下最新的cmake和python3

cmake15安装:

1
2
3
4
wget https://cmake.org/files/v3.15/cmake-3.15.3-Linux-x86_64.tar.gz
tar zxvf cmake-3.15.3-Linux-x86_64.tar.gz
sudo mv cmake-3.15.3-Linux-x86_64 /opt/cmake-3.15.3
sudo ln -sf /opt/cmake-3.15.3/bin/* /usr/bin/#创建软连接,这样输入cmake命令的时候就是调用/opt/cmake-3.15.3文件下的cmake执行文件了,后面安装环境的时候可能会重新被3.5版本的make覆盖

python3更新(后来发现也不用):

1
2
3
4
5
6
7
8
9
10
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4rc2.tgz
tar zxvf Python-3.7.4rc2.tgz
cd Python-3.7.4rc2
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus libncursesw5-dev libgdbm-dev libc6-dev zlib1g-dev libsqlite3-dev tk-dev libssl-dev openssl libffi-dev#安装python3依赖库
./configure --with-ssl --prefix=/usr/local/python3
make
make install

sudo rm /usr/bin/python3#可能/usr/local/bin下的python3也要删除
sudo ln -s /usr/local/python3/bin/python3 /usr/bin/python3

2019-9-29在实体ubuntu上安装遇到了问题:gnuradio make的时候报错,make test后发现qa_uhd之后的模块全部失败,网上没有这个问题,我怀疑是我ubuntu python的问题,因为之前pip的时候就报错了,后来找到一条命令ctest -V -R qa_uhd可以查看报错信息,是import uhd_swig时报错了,然后无解,重装系统。还是同样的问题,这时候我陷入了迷茫,去安装成功的虚拟机看了一遍history,突然发现uhd也是可以git checkout指定版本的,我实体机都是默认安的uhd3.15.0,然后我的gnuradio并不是默认版本,而是自己改成了maint-3.7,而以前虚拟机安的uhd版本是3.14,我怀疑是版本不兼容,重新安装了uhd3.14果然就成功编译了。

在gnuradio make完后又出现了qa_zeromq_sub fail的问题,还好网上有类似问题,pip install zmq后成功解决。

UHD驱动安装

更新源

1
sudo apt-get update

安装UHD和GNURADIO的必要环境

1
sudo apt-get -y install git swig cmake doxygen build-essential libboost-all-dev libtool libusb-1.0-0 libusb-1.0-0-dev libudev-dev libncurses5-dev libfftw3-bin libfftw3-dev libfftw3-doc libcppunit-1.13-0v5 libcppunit-dev libcppunit-doc ncurses-bin cpufrequtils python-numpy python-numpy-doc python-numpy-dbg python-scipy python-docutils qt4-bin-dbg qt4-default qt4-doc libqt4-dev libqt4-dev-bin python-qt4 python-qt4-dbg python-qt4-dev python-qt4-doc python-qt4-doc libqwt6abi1 libfftw3-bin libfftw3-dev libfftw3-doc ncurses-bin libncurses5 libncurses5-dev libncurses5-dbg libfontconfig1-dev libxrender-dev libpulse-dev swig g++ automake autoconf libtool python-dev libfftw3-dev libcppunit-dev libboost-all-dev libusb-dev libusb-1.0-0-dev fort77 libsdl1.2-dev python-wxgtk3.0 git-core libqt4-dev python-numpy ccache python-opengl libgsl-dev python-cheetah python-mako python-lxml doxygen qt4-default qt4-dev-tools libusb-1.0-0-dev libqwt5-qt4-dev libqwtplot3d-qt4-dev pyqt4-dev-tools python-qwt5-qt4 cmake git-core wget libxi-dev gtk2-engines-pixbuf r-base-dev python-tk liborc-0.4-0 liborc-0.4-dev libasound2-dev python-gtk2 libzmq-dev libzmq1 python-requests python-sphinx libcomedi-dev python-zmq python-setuptools

到这一步都顺利安装,接着便是安装UHD

1
2
3
4
5
6
7
8
9
10
11
12
13
cd $HOME
mkdir workarea-uhd
cd workarea-uhd
git clone https://github.com/EttusResearch/uhd #这里尝试了代理,但是速度依旧只有几K,而且中途容易下载失败,多次失败后发现是公司网络的问题
cd uhd
cd host
mkdir build
cd build
cmake ../
make #这一步大概耗时一个多小时,最后98%的时候因为虚拟机内存过小失败了,把内存从1G调整成2G后就成功make了
make test
sudo make install
sudo ldconfig

avatar
至此UHD安装完成

下面是官网原始过程,包括了各种查错步骤

1
2
3
4
5
cd $HOME
mkdir workarea-uhd
cd workarea-uhd
git clone https://github.com/EttusResearch/uhd
cd uhd

Next, checkout the desired UHD version. You can get a full listing of tagged releases by running the command:

1
git tag -l

Example truncated output of git tag -l:

1
2
3
4
5
$ git tag -l
...
release_003_009_004
release_003_009_005
release_003_010_000_000

Note: As of UHD Version 3.10.0.0, the versioning scheme has changed to be a quadruplet format. Each element and version will follow the format of: Major.API.ABI.Patch. Additional details on this versioning change can be found here.

After identifying the version and corresponding release tag you need, check it out:

1
2
3
4
# Example: For UHD 3.9.5:
git checkout release_003_009_005
# Example: For UHD 3.14.0.0
git checkout v3.14.0.0

Next, create a build folder within the repository.

1
2
3
cd host
mkdir build
cd build

Next, invoke CMake to create the Makefiles.

1
cmake ../

Next, run Make to build UHD.

1
make

Next, you can optionally run some basic tests to verify that the build process completed properly.

1
make test

Next, install UHD, using the default install prefix, which will install UHD under the /usr/local/lib folder. You need to run this as root due to the permissions on that folder.

1
sudo make install

Next, update the system’s shared library cache.

1
sudo ldconfig

Finally, make sure that the LD_LIBRARY_PATH environment variable is defined and includes the folder under which UHD was installed. Most commonly, you can add the line below to the end of your $HOME/.bashrc file:

1
export LD_LIBRARY_PATH=/usr/local/lib

If the LD_LIBRARY_PATH environment variable is already defined with other folders in your $HOME/.bashrc file, then add the line below to the end of your $HOME/.bashrc file to preserve the current settings.

1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

For this change to take effect, you will need to close the current terminal window, and open a new terminal.

At this point, UHD should be installed and ready to use. You can quickly test this, with no USRP device attached, by running uhd_find_devices. You should see something similar to the following.

1
2
3
linux; GNU C++ version 4.8.4; Boost_105400; UHD_003.010.000.HEAD-0-g6e1ac3fc

No UHD Devices Found

下载FPGA images

然后是下载FPGA images,设备运行的时候需要加载,我一开始没有下载就报错了
直接sudo uhd_images_downloader就行了

下面是官网的下载及查错步骤:
Downloading the UHD FPGA Images
You can now download the UHD FPGA Images for this installation. This can be done by running the command uhd_images_downloader.

$ sudo uhd_images_downloader
Note: Since this installation is being installed to a system level directory (e.g. /usr/local), the uhd_images_downloader command requires sudo privileges.

Example ouput for UHD 3.13.3.0:

$ sudo uhd_images_downloader
Images destination: /usr/local/share/uhd/images
Downloading images from: http://files.ettus.com/binaries/images/uhd-images_003.010.003.000-release.zip
Downloading images to: /tmp/tmpm46JDg/uhd-images_003.010.003.000-release.zip
57009 kB / 57009 kB (100%)

Images successfully installed to: /usr/local/share/uhd/images
Example output for UHD 3.13:

$ sudo uhd_images_downloader
[INFO] Images destination: /usr/local/share/uhd/images
[INFO] No inventory file found at /usr/local/share/uhd/images/inventory.json. Creating an empty one.
00006 kB / 00006 kB (100%) usrp1_b100_fw_default-g6bea23d.zip
19484 kB / 19484 kB (100%) x3xx_x310_fpga_default-g494ae8bb.zip
02757 kB / 02757 kB (100%) usrp2_n210_fpga_default-g6bea23d.zip
02109 kB / 02109 kB (100%) n230_n230_fpga_default-g494ae8bb.zip
00522 kB / 00522 kB (100%) usrp1_b100_fpga_default-g6bea23d.zip
00474 kB / 00474 kB (100%) b2xx_b200_fpga_default-g494ae8bb.zip
02415 kB / 02415 kB (100%) usrp2_n200_fpga_default-g6bea23d.zip
05920 kB / 05920 kB (100%) e3xx_e320_fpga_default-g494ae8bb.zip
15883 kB / 15883 kB (100%) n3xx_n310_fpga_default-g494ae8bb.zip
00506 kB / 00506 kB (100%) b2xx_b205mini_fpga_default-g494ae8bb.zip
18676 kB / 18676 kB (100%) x3xx_x300_fpga_default-g494ae8bb.zip
00017 kB / 00017 kB (100%) octoclock_octoclock_fw_default-g14000041.zip
04839 kB / 04839 kB (100%) usb_common_windrv_default-g14000041.zip
00007 kB / 00007 kB (100%) usrp2_usrp2_fw_default-g6bea23d.zip
00009 kB / 00009 kB (100%) usrp2_n200_fw_default-g6bea23d.zip
00450 kB / 00450 kB (100%) usrp2_usrp2_fpga_default-g6bea23d.zip
00142 kB / 00142 kB (100%) b2xx_common_fw_default-g3ff4186b.zip
00460 kB / 00460 kB (100%) b2xx_b200mini_fpga_default-g494ae8bb.zip
00319 kB / 00319 kB (100%) usrp1_usrp1_fpga_default-g6bea23d.zip
00009 kB / 00009 kB (100%) usrp2_n210_fw_default-g6bea23d.zip
11537 kB / 11537 kB (100%) n3xx_n300_fpga_default-g494ae8bb.zip
05349 kB / 05349 kB (100%) e3xx_e310_fpga_default-g494ae8bb.zip
00866 kB / 00866 kB (100%) b2xx_b210_fpga_default-g494ae8bb.zip
[INFO] Images download complete.

安装GNURadio

接下来就是安装GNU

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cd $HOME
mkdir workarea-gnuradio
cd workarea-gnuradio
git clone --recursive https://github.com/gnuradio/gnuradio
cd gnuradio
git checkout v3.7.13.4
git checkout maint-3.7
git submodule update --init --recursive
mkdir build
cd build
cmake ../
make
make test
sudo make install
sudo ldconfig

启动GNURadio命令:gnuradio-companion

下面是官网的安装及查错步骤:
First, make a folder to hold the repository.

1
2
3
cd $HOME
mkdir workarea-gnuradio
cd workarea-gnuradio

Next, clone the repository.

1
git clone --recursive https://github.com/gnuradio/gnuradio

Next, go into the repository and check out the desired GNU Radio version.

1
cd gnuradio

To checkout the v3.7.13.4 branch:

1
git checkout v3.7.13.4

Or to checkout the maint-3.7 branch:

1
git checkout maint-3.7

Next, update the submodules:

1
git submodule update --init --recursive	;这里出现了Submodule path 'volk': checked out,不知道什么原因,但似乎不影响之后的步骤

Next, create a build folder within the repository.

1
2
mkdir build
cd build

Next, invoke CMake to create the Makefiles.

1
cmake ../

Next, run Make to build GNU Radio.

1
make

Next, you can optionally run some basic tests to verify that the build process completed properly.

1
make test

Next, install GNU Radio, using the default install prefix, which will install GNU Radio under the /usr/local/lib folder. You need to run this as root due to the permissions on that folder.

1
sudo make install

Finally, update the system’s shared library cache.

1
sudo ldconfig

At this point, GNU Radio should be installed and ready to use. You can quickly test this, with no USRP device attached, by running the following quick tests.

1
2
3
gnuradio-config-info --version
gnuradio-config-info --prefix
gnuradio-config-info --enabled-components

There is a simple flowgraph that you can run that does not require any USRP hardware. It’s called the dialtone test, and it produces a PSTN dial tone on the computer’s speakers. Running it verifies that all the libraries can be found, and that the GNU Radio run-time is working.

1
python $HOME/workarea-gnuradio/gnuradio/gr-audio/examples/python/dial_tone.py

You can try launching the GNU Radio Companion (GRC) tool, a visual tool for building and running GNU Radio flowgraphs.

1
gnuradio-companion

If “gnuradio-companion” does not start and complains about the PYTHONPATH environment variable, then you may have to set this in your $HOME/.bashrc file, as shown below.

1
export PYTHONPATH=/usr/local/lib/python2.7/dist-packages

运行

UHD和GNU安装好后,插入设备,尝试运行uhd_find_devices,出现了“USB device 2500:0020 无法连接到理想的主机控制器”的报错,我原本以为是设备出了问题,因为官网上似乎说b210的信号是2500:0021,镜像加载也是加载了b200,谷歌了之后发现这是因为usb兼容性的问题,在虚拟机设置的USB控制器里把usb兼容性改为usb3.0后解决了问题

运行正常
avatar
avatar
最后这里有一点搞不懂
uhd_find_devices和uhd_usrp_probe两个命令加载的FPGA images不一样,前者是b200,后者是b210,不过都正确识别出了b210的设备,目前对这个问题没有头绪。

评论加载中