mbed API for Raspberry Pi boards.

mbedPi

This is an attempt to implement a limited number of mbed APIs for Raspberry Pi single-board computers. The project was inspired by and based on the arduPi library developed for the Arduino by Cooking Hacks .

/media/uploads/hudakz/board01.jpg

Specifications

  • Chip: Broadcom BCM2836 SoC
  • Core architecture: Quad-core ARM Cortex-A7
  • CPU frequency: 900 MHz
  • GPU: Dual Core VideoCore IV® Multimedia Co-Processor
  • Memory: 1GB LPDDR2
  • Operating System: Boots from Micro SD card, running a version of the Linux operating system
  • Power: Micro USB socket 5V, 2A

Connectors

  • Ethernet: 10/100 BaseT Ethernet socket
  • Video Output: HDMI (rev 1.3 & 1.4)
  • Audio Output: 3.5mm jack, HDMI
  • USB: 4 x USB 2.0 Connector
  • GPIO Connector: 40-pin 2.54 mm (100 mil) expansion header: 2x20 strip providing 27 GPIO pins as well as +3.3 V, +5 V and GND supply lines
  • Camera Connector: 15-pin MIPI Camera Serial Interface (CSI-2)
  • JTAG: Not populated
  • Display Connector: Display Serial Interface (DSI) 15 way flat flex cable connector with two data lanes and a clock lane
  • Memory Card Slot: Micro SDIO

GPIO connector pinout

Zoom in /media/uploads/hudakz/mbedpi_pinout02.png

Information

Only the labels printed in blue/white or green/white (i.e. p3, gpio2 ...) must be used in your code. The other labels are given as information (alternate-functions, power pins, ...).


Building programs for the Raspberry Pi with mbedPi

I use Qt Creator for development, however you can use any other IDE available on the Raspberry Pi (e.g. Geany) if you like. For a quick try:

  • Install Qt and the Qt Creator onto your Raspberry Pi. Then create a new "Blinky" Plain non-Qt C++ Project as follows: /media/uploads/hudakz/newproject.png

  • Change the main code as below:

main.cpp

#include "mbedPi.h"

int main()
{
    DigitalOut  myled(p7);

    while(1) {
        myled = 1; // LED is ON
        wait(0.2); // 200 ms
        myled = 0; // LED is OFF
        wait(1.0); // 1 sec
        printf("Blink\r\n");
    }
}


  • Copy the mbedPi.zip file into your project's folder and unzip.
  • Add the mbedPi.h and mbedPi.cpp files to your project by right clicking on the "Blinky" project and then clicking on the "Add Existing Files..." option in the local menu:

    /media/uploads/hudakz/addfiles.png

    /media/uploads/hudakz/addfiles02.png

  • Double click on Blinky.pro to open it for editing and add new libraries by inserting a new line as follows:

    /media/uploads/hudakz/libs.png

  • Compile the project.

  • Connect an LED through a 1k resistor to pin 7 and the ground on the Raspberry Pi GPIO connector.

  • Run the binary as sudo (sudo ./Blinky) and you should see the LED blinking. /media/uploads/hudakz/mbedpi_run.png

  • Press Ctrl+c to stop running the application.
Revision:
2:131555dc6fb7
Parent:
1:1f2d9982fa8c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/raspi_wizard/RpiApplication.qbs	Tue Dec 20 12:16:18 2022 +0000
@@ -0,0 +1,93 @@
+import qbs
+import qbs.Process
+import qbs.File
+import qbs.FileInfo
+import qbs.TextFile
+import "/home/zoli/.config/QtProject/qtcreator/templates/wizards/qbs_rpi/js/helpers.js" as helpers
+
+CppApplication {
+    type: "application"
+    consoleApplication: true
+    Depends { name: "cpp" }
+//    cpp.cppFlags: "-std=c++11"
+//    Depends {
+//        name: "Qt";
+//        submodules: ["core", "gui", "widgets"]
+//    }
+
+    Group {
+        fileTagsFilter: product.type
+        qbs.install: true
+        qbs.installDir: "bin"
+        qbs.installPrefix: "/mnt/workbench"
+    }
+
+    property string     sysPath: "/home/zoli/src/rpi/sys"
+    property stringList sys: [
+        "drivers",
+    ]
+    property pathList   sysPaths: {
+        var l = []
+        for (var i = 0; i < sys.length; i++) {
+            l = l.concat(helpers.dirs(sysPath+"/"+sys[i]))
+        }
+        return l
+    }
+
+    Group {
+        name: "sys"
+        condition: (sysPath != "")
+        files: {
+            var l = []
+            for (var i = 0; i < sys.length; i++) {
+//                l = l.concat(sys[i]+"/**")
+                l = l.concat(sys[i]+"/**/*.cpp")
+                l = l.concat(sys[i]+"/**/*.c")
+                l = l.concat(sys[i]+"/**/*.hpp")
+                l = l.concat(sys[i]+"/**/*.h")
+                l = l.concat(sys[i]+"/**/*.s")
+            }
+            return l
+        }
+        prefix: sysPath + "/"
+    }
+
+    property string     libPath: "/home/zoli/src/rpi/lib"
+    property stringList libs: []
+    property pathList   libPaths: {
+        var l = []
+        for (var i = 0; i < libs.length; i++) {
+            l = l.concat(helpers.dirs(libPath+"/"+libs[i]))
+        }
+        return l
+    }
+
+    Group {
+        name: "libs"
+        condition: (libPath != "")
+        files: {
+            var l = []
+            for (var i = 0; i < libs.length; i++) {
+//                l = l.concat(libs[i]+"/**")
+                l = l.concat(libs[i]+"/**/*.cpp")
+                l = l.concat(libs[i]+"/**/*.c")
+                l = l.concat(libs[i]+"/**/*.hpp")
+                l = l.concat(libs[i]+"/**/*.h")
+                l = l.concat(libs[i]+"/**/*.s")
+            }
+            return l
+        }
+        prefix: libPath + "/"
+    }
+
+    property pathList includePaths: ""
+
+    cpp.compilerIncludePaths: "/home/zoli/toolchain/rpi/arm-bcm2708/arm-bcm2708-linux-gnueabi/arm-bcm2708-linux-gnueabi/include/c++/4.7.1"
+    cpp.compilerFrameworkPaths: "/home/zoli/toolchain/rpi/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/"
+    cpp.compilerLibraryPaths: "/home/zoli/toolchain/rpi/arm-bcm2708/arm-bcm2708-linux-gnueabi/arm-bcm2708-linux-gnueabi/lib"
+    cpp.includePaths: includePaths.concat("/.", sysPaths, libPath)
+   //cpp.staticLibraries: ["mbed"]
+    cpp.dynamicLibraries: ["rt", "pthread"]
+}
+
+