Ubilinux on the Intel Galileo: Tmrh20's RF24 Library for nRF24L01+ radios (Part II)

[Deprecated - Updated post is here]

Hey all,
So, today I continue my little anecdote about getting the RF24 library up and running on the Ubilinux distro running on the Intel Galileo.
From the last post, I ran: make -B RF24_MRAA=1 but got an error about WProgram.h not being found. After some knocking about, I figured that editing the RF24_config.h file and adding these defines:

#define MRAA
#define RF24_LINUX

To the section titled "/***** User Defines*****/"

Would make it possible to compile it. Thus, after editing the file, I ran make -B RF24_MRAA=1 again, and the compilation began in earnest. Please note that at this point, I had downloaded, compiled and installed the MRAA library as described in this post.
Sadly, I didn't set the CC and CXX variables in the make invocation, so make defaulted to using gcc and g++, and I got the "illegal compiler instruction" error once again. Re-running make as: make CC=clang CXX=clang++ -B RF24_MRAA=1 still ended up invoking gcc and g++ for some reason, and I was once again, back to zero.
I then looked at the makefile and realized that it was explicitly written to use gcc and g++, rather than relying on the definitions of the CC and CXX variables like most Makefiles do. No problem. I simply replaced all occurrences of gcc with clang and c++ with clang++, and then re-ran the process. This time, it actually completed with no errors. The build generated a file named librf24-bcm.so.1.0, which is the RF24 shared library file. Thus, any applications of mine (or yours) would include the RF24 header file and link against this shared library.
Obviously, the proof was in the pudding, so I took this shared library and the gettingstarted.cpp file from the examples_Rpi folder, and put them together in a folder I called test. I also added the RF24_config.h file, and the entire "arch" folder not just its contents. These files were taken from the RF24 source tree I got off of Github. I could've make install'd, but I wasn;t sure if it'd work so I didn't want to take the chance.
I edited the gettingstarted.cpp file, specifically changing the constructor for the RF24 object instance to: RF24 radio(9,1). The first argument to the constructor is the MRAA pin number for the pin connected to the CE pin on the radio. The MRAA pin number on the Galileo is similar to the Arduino pin numbering. Simply put, pin 9 in the context of MRAA is labelled "9" on the Galileo physically. The second argument is the SPI bus number, as each SPI bus has its own Cable Select / Slave Select pin (which is connected to the CSN pin on the radio). The SPI bus exposed on the Galileo is bus 1, which explains why I used 1 as the value of the second parameter. Once that was done, I had to edit the /etc/ld.so.conf.d/libc.conf file and include the following path:


To it. This is to ensure that the system would search that directory for the librf24-bcm.so.1.0 file when linking any program or loading shared libraries during program execution. Its a dirty hack but it was sufficient for my purposes. After doing that, I renamed the librf24-bcm.so.1.0 file to librf24-bcm.so, then ran the ldconfig command to refresh the system's list of shared libraries. Once this was done, I compiled the gettingstarted.cpp file as follows:

clang++ gettingstarted.cpp -o program -L. -lrf24-bcm

Which produced an executable called program. When I tried to run the program, I got an error that read: "illegal instruction". Aaaargh!!!!!!

We'll continue this in Part III.....


Popular posts from this blog

Enabling SPI1 on the Raspberry Pi B+/Zero/2/3

Bitbanging SPI on the Raspberry Pi (via spi-gpio)

Getting Started with Logic Analyzers and Pulseview