How to develop a Linux binary for the BeagleBone (any colour) on Windows in CCS, using BB guru Derek Molloy's GPIO lib. This blog has a history. I was working with my very good friend martinvalencia to get this working. This blog shows the end result: how we got it working. Not shown: all our failures when discussing this over Hangouts. |
Derek Molloy is arguably the best source for BB tutorials. His libraries are well designed too. Here's an instruciblo on how to use his GPIO lib with CCS.
The goal - in the theme of my previous BB blogs: build a linux executable for the BB on your laptop in CCS and debug it from there.
I will not build the library from source - that's another interesting exercise, maybe for another blog. I'll reuse the shared library that Derek hosts on github.
That library, in binary form, can be downloaded from here: https://github.com/derekmolloy/exploringBB/blob/version2/library/libEBBLibrary.so?raw=true.
You will need it on your development PC and on the BB.
Download it to your PC first and move it to a directory of preference. We'll link to it later in CCS.
Also download the GPIO header file, and copy it on your development PC, where you downloaded the .so file, in a subdirectory GPIO.
Then copy the .so file to the BB, to the /usr/lib folder. You'll need root rights for that, so easiest is to copy it to your home (e.g.: with winSCP), then move it in Linux.
cd /usr/lib sudo mv ~/libEBBLibrary.so . ldconfig -n -v /usr/lib
Your BeagleBone is now ready to run the library and you have the dependency on your development PC. Let's start CCS and create a new project.
File -> New - > Project -> C++ Project
Name it GPIOTest. Select Empty Project, Cross GCC (we use the Linaro GCC cross-platform compiler).
Make a new folder, called src
In that folder, create a new C++ file called main.cpp
Copy the following source (I got it from martinvalencia - It's the source he uses to test the library, I don't know where it is coming from)
#include<iostream> #include<unistd.h> // required for usleep - microsecond sleep #include"GPIO.h" // using user-include syntax using namespace exploringBB; // bring in everything from this namespace using namespace std; // bring in standard namespace int main() { GPIO outGPIO(49), inGPIO(115); //P9_23 and P9_27 respectively // Basic Output - Flash the LED 10 times, once per second outGPIO.setDirection(GPIO::OUTPUT); for (int i = 0; i < 10; i++) { outGPIO.setValue(GPIO::HIGH); // LED on usleep(500000); // sleep 0.5 seconds outGPIO.setValue(GPIO::LOW); // LED off usleep(500000); } // Basic Input example inGPIO.setDirection(GPIO::INPUT); // is the button pressed? cout << "The value of the input is: " << inGPIO.getValue() << endl; // Fast write to the GPIO 1 million times outGPIO.streamOpen(); for (int i = 0; i < 1000000; i++) { outGPIO.streamWrite(GPIO::HIGH); // no sleep. As fast as possible. outGPIO.streamWrite(GPIO::LOW); } outGPIO.streamClose(); // close the stream and exit return 0; }
Then start configuring the project.
Set the builder to Internal:
Got to the Build settings, and add the GPIO header file directory:
On my PC: "D:\users\jancu\Documents\elektronica\Texas Instruments\bbb\exploringBB\GPIO".
Then tell the linker where the shared library is.
On my PC: "D:\users\jancu\Documents\elektronica\Texas Instruments\bbb\exploringBB"
That's it. Build it.
Now it's time to debug. Copy one of your working debug configurations and adapt it for this project.
If you don't get something like this, you may want to re-read this blog: BeagleBone: Build and Debug a Linux C++ Program with Code Composer Studio
Good luck!
Top Comments