Homepage Wiki Forum Buy

Tutorial API BeagleBoneBlack



GnuBo Prototyp.jpg

Install API

To try installing the API on the BeagleBone Black, you download the most current repository as a zip file and unzip it:

root@beaglebone:~# curl -k -o api.zip https://codeload.github.com/embeddedprojects/gnublin-api/zip/master
root@beaglebone:~# unzip api.zip

Before we can now translate the API for BeaglBone Black has to make a few adjustments in the file API-config.mk

Lines 2, 12, 17 are commented out. For this, the # is removed at the beginning of lines 6, 14, 19th The file looks as follows:

  1. #Crosscompiler for Gnublin
  2. #CXX := arm-linux-gnueabi-g++ 
  3. #Crosscompiler for Raspberry Pi:
  4. #CXX := arm-linux-gnueabihf-g++
  5. #Compiler for onboard compilation:
  6. CXX := g++
  8. #Compilerflags:
  9. CXXFLAGS = -Wall
  11. #Architecture for gnublin:
  12. #Architecture = armel
  13. #Architecture for raspberryPi an beaglebone black:
  14. Architecture = armhf
  16. #Define which Board you want: 

Then you can compile the API

root@beaglebone:~# make

To be able to use the SPI interface, you must first make a few adjustments.

Install GNUBLIN tools

root@beaglebone:~# mkdir -p /usr/local/bin
root@beaglebone:~# cd gnublin-api
root@beaglebone:~# make install


In order to use the API in your own programs you need only the two files 'gnublin.h' and 'gnublin.cpp' at best in the same folder as your project.

The whole works as described with the GNUBLIN.

The only thing that is different, then the attribute is -DBOARD=BEAGLEBONE_BLACK is must specify at compile time, so the API knows that there is a BeagleBone.

The compile command is then:

root@beaglebone:~# g++ -o meinProgramm meinProgramm.cpp gnublin.cpp -DBOARD=BEAGLEBONE_BLACK


[Quelle: https://groups.google.com/d/msg/beagleboard/jYpYHZPl1ig/dkRGcI0wcNYJ ]

The SPI interface is not enabled by default, this must be done manually.

The interface assignment to the individual pins works on the BeagleBone Black called the device tree. It must be inserted in the device tree to activate SPI overlay (method with device tree).

The Black BeagleBone provides two SPI interfaces. We are using SPI0.SPI1 overlaps with the HDMI output and so this is much more complex to set up.

create overlay

For the overlay, we create a file BB_SPI0DEV-00A0.dts with the following content:

 * Copyright (C) 2013 CircuitCo
 * Virtual cape for SPI0 on connector pins P9.22 P9.21 P9.18 P9.17
 * Modified to enable /dev/spidev1.0 by Carl Johnson
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.

/ {
    compatible = "ti,beaglebone", "ti,beaglebone-black";

    /* identification */
    part-number = "BB-SPI0DEV";
    version = "00A0";

    /* state the resources this cape uses */
    exclusive-use =
        /* the pin header uses */
        "P9.17",    /* spi0_cs0 */
        "P9.18",    /* spi0_d1 */
        "P9.21",    /* spi0_d0 */
        "P9.22",    /* spi0_sclk */
        /* the hardware ip uses */

    fragment@0 {
        target = <&am33xx_pinmux>;
        __overlay__ {
            bb_spi0_pins: pinmux_bb_spi0_pins {
                pinctrl-single,pins = <
                    0x150 0x30  /* spi0_sclk.spi0_sclk, INPUT_PULLUP | MODE0 */
                    0x154 0x30  /* spi0_d0.spi0_d0, INPUT_PULLUP | MODE0 */
                    0x158 0x10  /* spi0_d1.spi0_d1, OUTPUT_PULLUP | MODE0 */
                    0x15c 0x10  /* spi0_cs0.spi0_cs0, OUTPUT_PULLUP | MODE0 */

    fragment@1 {
        target = <&spi0>;   /* spi0 is numbered correctly */
        __overlay__ {
            status = "okay";
            pinctrl-names = "default";
            pinctrl-0 = <&bb_spi0_pins>;
            #address-cells = <1>;
            #size-cells = <0>;
            spidev@0 {
                #address-cells = <1>;
                #size-cells = <0>;
                spi-max-frequency = <24000000>;
                reg = <0>;
                compatible = "linux,spidev";

You have to compile this file:

root@beaglebone:~# opkg install dtc
root@beaglebone:~# dtc -O dtb -o /lib/firmware/BB-SPI0DEV-00A0.dtbo -b 0 -@ BB-SPI0DEV-00A0.dts

Now you can enable spi during runtime:

root@beaglbone:~# echo BB-SPI0DEV > /sys/devices/bone_capemgr.*/slots

Now an device called /dev/spidev1.0 should exist. You can check this with ls /dev.

Activate SPI at boot

As of kernel 3.8.13-r23a.17 the SPI overlay can be automatically activated during system startup.

For this we need an entry in the file uEnv.txt which you find in your boot partition.

You can modify the file in two ways:

  • on the desktop when the BeagleBone is connected via USB. There you can find them in the flash drive that creates the Beaglbone
  • on the BeagleBone itself:
root@beaglebone:~# if [ ! -d /mnt/boot ]; then mkdir /mnt/boot; fi
root@beaglebone:~# mount /dev/mmcblk0p1 /mnt/boot

Th file you find here: /mnt/boot/uEnv.txt.

In the of the "optargs" rows add following:


Now on every boot the spi interface should be enabled.

In other languages