树莓派--bcm2835 library (2) 交叉编译BCM2835

31 篇文章 0 订阅
28 篇文章 0 订阅

在上文中,按照guide, 在树莓派目标板上install bcm2835.

因为bcm2835是用户空间应用,所以可以在宿主机上交叉编译,生成binary后在树莓派执行

按照guide: 

Installation

This library consists of a single non-shared library and header file, which will be installed in the usual places by make install

# download the latest version of the library, say bcm2835-1.xx.tar.gz, then:
tar zxvf bcm2835-1.xx.tar.gz
cd bcm2835-1.xx
./configure
make
sudo make check
sudo make install


这里我们不需要安装,只要make生成.a库就可以。

交叉编译:

./configure -host=arm CC=arm-linux-gnueabihf-gcc-4.9.3 ar=arm-linux-gnueabihf-ar

make

在make时出现错误

Bcm2835-1.45$ make
CDPATH="${ZSH_VERSION+.}:" && cd . && aclocal-1.13 -I m4
/bin/bash: aclocal-1.13: command not found
Makefile:327: recipe for target 'aclocal.m4' failed
make: *** [aclocal.m4] Error 127

解决:

1. sudo apt-get install automake

2. sudo autoreconf -ivf

然后make,无报错


在src下生成了.a文件

~/Raspberry/bcm2835-1.56/src$ ls
bcm2835.c  bcm2835.o     Makefile     Makefile.in
bcm2835.h  libbcm2835.a  Makefile.am  test.c

将bcm2835.a 以及头文件 bcm2835.h,  copy到led.c目录下,编译LED测试文件

led.c 如下

#include <bcm2835.h>

#define PIN 26
int main(int argc, char **argv)
{
    if (!bcm2835_init())return 1;
    bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_OUTP);

    while (1)
    {
        bcm2835_gpio_write(PIN, HIGH);
        bcm2835_delay(500);
        bcm2835_gpio_write(PIN, LOW);
        bcm2835_delay(500);
    }
    bcm2835_close();
    return 0;
}

makefile

CC = arm-linux-gnueabihf-gcc-4.9.3
LD = arm-linux-gnueabihf-ld

led:led.c
	$(CC) -Wall -I./ led.c -o led -L./lib -lbcm2835
clean:
	rm led

将生成的led binary文件copy到树莓派执行, LED闪烁


http://www.airspayce.com/mikem/bcm2835/


./configure -host=arm CC=arm-linux-gnueabihf-gcc-4.9.3 ar=arm-linux-gnueabihf-ar
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值