zoukankan      html  css  js  c++  java
  • 树莓派--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
  • 相关阅读:
    MySQL 性能调优之索引
    MySQL 性能调优之存储引擎
    MySQL数据类型优化—整数类型优化选择
    MySQL数据性能优化-修改方法与步骤
    MySQL设计SQL语句优化规范
    MySQL索引的设计、使用和优化
    MySQL的SQL语句优化-group by语句的优化
    SQL性能优化-order by语句的优化
    MySQL查询优化注意下面的四个细节
    优化MySQL性能的几种方法-总结
  • 原文地址:https://www.cnblogs.com/feiwatson/p/9478219.html
Copyright © 2011-2022 走看看