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


    在上文中,按照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
  • 相关阅读:
    SpringCloud------获取配置文件属性值
    SpringCloud------MyBatisPlus代码生成器的使用
    Hanoi问题 算法
    常见的时间复杂度按数量级排列
    Java 匿名类
    java内部类
    Java 接口和抽象类
    使用引用类型变量来访问所引用对象的属性和方法时,Java 虚拟机绑定规则
    Python import搜索的路径顺序
    php 多次导入文件导致 Cannot redeclare class
  • 原文地址:https://www.cnblogs.com/feiwatson/p/9478219.html
Copyright © 2020-2023  润新知