2017年2月26日 星期日

OpenCV cross compile for BBB

 I had been thinking of using OpenCV on embedded devices long time ago. OpenCV is a very powerful free image processing library, developers can use the library to process their images without writing the algorithm from scratch.
 There are 2 methods to compile and install OpenCV on BBB. The first one is to download, compile and install OpenCV directly on BBB, I won't use this method since this method is very time consuming and you need to re-compile again whenever you have a new BBB. The second method is what I am going to explain in this article; in this method, I downloaded and compiled OpenCV on my Linux host computer then install the library to my BBB.
 The host OS I used is Ubuntu Linux, this is also the system I used to cross-compiled my BBB programs.  Before we start cross-compiling OpenCV library,

 Cmake_gui is a very powerful tool to help user to generate necessary file for cross-compiling, in this article I use cmake_gui to demonstrate crsoo-compile of OpenCV.
The steps to cross compile OpenCV is shown below,
  1. Download OpenCV source code for Linux from www.opencv.com, the version I downloaded is OpenCV3.1.0 
  2. Unzip downloaded OpenCV file. 
  3. Create another directory named OpenCV_build (Fig. 1)
  4. Download cmake_gui by typing atp-get install cmake_gui from Linux console. 
  5. Click on cmake_gui, cmake_gui will pop up shown in figure 2. In "where is source code" filed, select unzipped OpenCV source folder from step 2. 
In "where to build the sources", select the new directory created in step 3.
  1. Click on "Configure" button, then select "Unix Makefiles" and "Specify options for cross-compiling" to specify cross-compile tool chain shown in figure 3 then click next. 
  2. Specify crsoo-compile tool chain shown in figure 4, c compiler is under /your-compiler-directory/bin/gcc, c++ compiler is under /your-compiler-directory/bin/g++ and target root is under /your-compiler-directory/bin, enter Linux in "Operating System" filed then click finish. 
  3. In "Install_prefix" field shown inf figure 2, select /usr/local/bin. In "config_file_include_dir", select the directory in step 3 then click "Generate". 
  4. Enter directory created in step 3, type make then make install to compile and install OpenCV library, the entire compilation time may vary from different machines, in my case, 1 hour. 
  5. After compilation is done, you will find OpenCV library in /usr/local/lib directory, this means you have done compilation. 
Fig. 1






                                     Fig. 2

                                      Fig. 3 


                                     Fig. 4

Copy all related libraries from host side to ARM. 

  1. Copy files in /usr/local/lib on host side to /usr/local/lib on ARM 
  2. Copy files in /usr/local/include on host side to /usr/local/include on ARM
  3. Copy files in /usr/local/bin on host side to /usr/local/bin on ARM
  4. Copy files in /usr/local/share on host side to /usr/local/share on ARM.
This is done for cross-compile OpenCV, in the next post, I will explain how to write an simple OpenCV application for ARM. 

















2016年6月26日 星期日

Host interface

There are many ways to display data to end users. The first one is to show data on a 7'' LCD panel for BBB, the second one is to pass the data to a PC and display the data on computer screen. I chose the second for my bad eyesight.
Few articles back I mentioned about Qt and network, now, I combine all the previous results together to display the final outcome. The data acquisition procedures are:

  1. Qt program sends operation mode command to BBB through UDP. 
  2. Convert audio data by WM8731 ADC then save to SRAM through FPGA.
  3. Once SRAM is full, FPGA generates a hardware interrupt to AM335X. 
  4. AM335X starts reading data from SRAM through GPMC. 
  5. When reading is done, AM335X starts sending data to PC through UDP. 
  6. Qt program captures and displays the received data. 
The final Qt program is shown below.


2016年6月10日 星期五

9 Axis sensor system

I found a 9-Axis sensor module few months ago when I was moving and packing up my stuff. I used the module on my Cortex-M3 STM32 MCU development board Now I am thinking to plug the module to my BBB and turn my BBB to a sensor system board. 
Here is the main features of the my sensor module:
  • Analog Device ADX345 3-Axis accelerate-meter sensor
  • ST L3G4200 3-Axis angular velocity sensor
  • HoneyWell HMC5843 3-Axis magnetic field sensor
  • BOSH BMP085 pressure sensor 
All the sensors on this modules implements I2C interface, what I need to do for my BBB is to find a 3.3V power for the module and turn on the I2C interface on Linux. The I2C addresses of above sensors are 0x53, 0x69, 0x1E and 0x77 respectively. I pick up I2C-2 on BBB for no obvious reason, I2C-1 should be find as well. I2C-2 is pin 19/20 on BBB header 9. 

Communication with Qt

For days, I had been working on how to establish communication between BBB and my Windows PC through Ethernet, I had little experience programming a PC side software, after scratching my head and surfing through the Internet, I pick up Qt for its rich resources. I planed to have a thread in Qt to wait for incoming data from BBB, but I realized the way Qt uses a terminology called "signal and slot"; a simple way to put this is "a incoming signal trigger the slot to do a task".
Here is the example of how Qt link incoming Ethernet signal to a function, "readyRead" is the incoming signal while rxPacket is the function to process the UDP packet when triggered.
connect(udpSocket, SIGNAL(readyRead()), this, SLOT(rxPacket()));
Below is the snap of my Qt data acquisition interface, I will explain the functions of program later.
 

2016年5月25日 星期三

UDP connection programming

Although I plan to use BBB as my embedded host, I want to transfer data from BBB to my host PC as well for one major reason; data verification and display. Simply because coding on desktop computer is easier to setup and rich ready to use library can be used to display my data. 
There are many ways to communicate with BBB such as TCP/ UDP, USB, UART, I chose UDP to be my main communication method for its simplicity and speed. UDP libraries are already in GCC, allI have to do is to implement the libraries.  

You just have to put the data pointer, number of bytes to be sent and destination IP address, the data will be sent from BBB to PC. 

size_t udpTXClient(const void *bData, int nSize, char *IP){
struct sockaddr_in serv_addr;
    int sockfd, i, servLen;
size_t nTxLen; 
size_t nWriteLen; 
    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0))==-1)
        err("socket");
servLen = sizeof(serv_addr);
    bzero(&serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr(IP);
    serv_addr.sin_port = htons(1111);
//printf("UDP sender enabled\r\n") ;
if((nTxLen = sendto(sockfd, (void *)bData, nSize, 0, (struct sockaddr *) &serv_addr, servLen))==-1)
printf("UDP TX client fail\r\n");
    close(sockfd);
return nTxLen; 
}


2016年5月14日 星期六

GPMC registers setup

A quick snap of my GPMC registers setup on AM335X, I reconfigure the register values through Kernel Module programming and display the value by using prink. The the signal analyzer diagram from my previous article is the result of this setup.

GPMC logic analysis

After struggling a bit (actually a lot), I manage to extract data from BBB on FPGA, the following graph is the output captured by Quartus II SignalTap2 analyzer. Here I use multiplexed mode in GPMC to conserve GPIOs, this means that address and data are share the same signal path.
The second graph is the timing diagram I copied from AM335X datasheet, address is latched into FPGA on rising edge of ADVN signal, then data is latched or send on falling edge of wen/ oen signal.
At the stage, I have basically connect my BBB to FPGA successfully which means my Linux OS is able to control external device to perform different hardware functions.