сряда, 28 юли 2010 г.

Demo application - serial port and GPIO control.

These days I've made a project for my FriendlyARM 7" board. 
It demonstrates RS232 data transmission/reception and access to the GPIO pins. To test the serial port I used a serial-to-usb cable. The project seems to work as intended so I decided to share it:
http://rapidshare.com/files/409529027/stivlib_serial_gpio_demo_25JUL2010.zip.html
It can be used as starting point for learning.  The code may be modified and used freely without any waranty.

The whole working folder is included in the archive. Here are the files:

stivlib.pro - the Project file. This is a text file. Source and header files are described in it. If new files have to be added to the project  they must be described in this file

stivlib.png - image file used for icone of the desktop launcher
stivlib.desktop - text file. This is the desktop launcher.
stivlib - binary file. Compiled execteable.
In the previous post was described how to upload these files to the board.

serialport.h serialport.cpp - SerialPort class. It allows sending and recieving serial data and also control of RTS,CTS,DSR,DTR,DCD and RI pins.
gpio.h gpio.cpp - GPIO class. Each instance of this class controls one pin of the GPIO header. Refer to the documentation for the pin functions.  For example pin 31 controls the buzzer.

MainWindow.ui - xml file generated by Qt Creator. May be modified with text editor.


MainWindow.h MainWindow.cpp - here is defined the class of the main form dialog frmMainWindow. Connection between the SIGNALS and SLOTS are implemented here. These files are automaticaly generated with formuic script.   Do not modify them.

MainWindowImp.h MainWindowImp.cpp - In these files frmMainWindowImplementation class inherits frmMainWindow. The functionalyty of the application is implemented in this class.

main.cpp - it contains macroses for generating the application.

formuic - this script runs uic - user interface compiler. This script should be run each time modifications to MainForm.ui are made. New MainWindow.h MainWindow.cpp will be generated

build - this script runs the compiler and bilds the application

Makefile - the Mkefile is automaticaly generated. Do not modify it.



To have access to the GPIO the driver must be included to the linux kernel.
This is a link to compiled image with included drivers for GPIO and SPI. I have not tested the SPI yet.  It's for 7" display!
http://rapidshare.com/files/409529369/zImage-2.6.32.2-mini2440_gpio_spi.html
Great thanks to Eric Brombaugh for his page which helped me to compile and upload the kernel.

http://members.cox.net/ebrombaugh1/embedded/mini2440/index.html

неделя, 18 юли 2010 г.

Uploading the application and creating the launcher



Qtopia file system:
/opt/Qtopia/
           |--apps/  
           |    |-Application/  --each folder is a desktop tab.
           |    |-FriendlyARM/    in these folders are .desktop files
           |    |-Games/
           |    |-Settings/
           |
           |--pics/   -applications icone folder
           |--bin/    -applications executables
           |--help/   



1.Preparation
Prepare a .png file for desktop icon of your application.
Place it into the project folder and give it the same name as the binary file:stivlib.png
Create the stivlib.desctop file. This is a text file with the following content:

[Desktop Entry]
Version=1.0
Encoding=UTF-8
Name=StivLib
Comment=An Example Program
Exec=stivlib
Icon=stivlib
Type=Application
GenericName[en_US]=


2. Connect your PC to FriendlyARM witn network cable, and open a terminal.
FriendlyARM board comes with preset IP 192.168.1.230.
Set your IP address, telnet to FriendlyARM and set root password:

# su
# ifconfig eth0 192.168.1.1 netmask 255.255.255.0
# telnet 192.168.1.230
Trying 192.168.1.230...
Connected to 192.168.1.230.
Escape character is '^]'.

Kernel 2.6.32.2-FriendlyARM on (/dev/pts/0)
FriendlyARM login: root
[root@FriendlyARM /]# passwd
Changing password for root
New password:
Retype password:
Password for root changed by root
[root@FriendlyARM /]#

3. Make a folder into /opt/Qtopia/apps for your applications.
These folders appear like desktop tabs.

[root@FriendlyARM /]# cd /opt/Qtopia/apps
[root@FriendlyARM apps]# ls
Applications  FriendlyARM   Games         Settings
[root@FriendlyARM apps]# mkdir STIV
[root@FriendlyARM apps]# ls
Applications  FriendlyARM   Games         STIV          Settings
[root@FriendlyARM apps]# exit


4. Upload binary file to FriendlyARM using ftp. Upload the icone file and the .desktop file
Go to your project folder where is your binary file.

# ftp 192.168.1.230
Connected to 192.168.1.230.
220 FriendlyARM FTP server (Version 6.4/OpenBSD/Linux-ftpd-0.17) ready.
Name (192.168.1.230:svilen): root
331 Password required for root.
Password:
230 User root logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd opt/Qtopia/bin
250 CWD command successful.
ftp> send stivlib
local: stivlib remote: stivlib
200 PORT command successful.
150 Opening BINARY mode data connection for 'stivlib'.
226 Transfer complete.
41481 bytes sent in 0.25 secs (162.7 kB/s)
ftp> cd ..
250 CWD command successful.
ftp> cd pics
250 CWD command successful.
ftp> send stivlib.png
local: stivlib.png remote: stivlib.png
200 PORT command successful.
150 Opening BINARY mode data connection for 'stivlib.png'.
226 Transfer complete.
2743 bytes sent in 0.00 secs (62295.6 kB/s)
ftp> cd ..
250 CWD command successful.
ftp> cd apps/STIV
250 CWD command successful.
ftp> send stivlib.desktop
local: stivlib.desktop remote: stivlib.desktop
200 PORT command successful.
150 Opening BINARY mode data connection for 'stivlib.desktop'.
226 Transfer complete.
146 bytes sent in 0.00 secs (9505.2 kB/s)
ftp> bye
221 Goodbye.
#

5.Now telnet again to FriendlyARM to change the attributes of the uploaded file.
It shoul become executable

# telnet 192.168.1.230
Trying 192.168.1.230...
Connected to 192.168.1.230.
Escape character is '^]'.

Kernel 2.6.32.2-FriendlyARM on (/dev/pts/0)
FriendlyARM login: root
Password:
[root@FriendlyARM /]# cd /opt/Qtopia/bin/
[root@FriendlyARM bin]# chmod a+x stivlib
[root@FriendlyARM bin]# ls


Restart the board.

Useful links:
Read about Qtopia filesystem standarts on http://doc.trolltech.com/qtopia2.2/html/files.html
vi editor quick refference http://www.digilife.be/quickreferences/QRC/vi%20Quick%20Reference.pdf

понеделник, 12 юли 2010 г.

Hello World with GUI application for FrienndlyARM Tutorial


Here are the steps of creating a simple "Hello world" GUI application for FriendlyARM board.   You should have development tools ARM-Linux GCC 4.3.2 and ARM-Qtopia 2.2.0 already installed.  If you don't have them yet you can download them from here: http://www.friendlyarm.net/downloads
My PC is working under Ubuntu 8.04. and the path of Qtopia installation is /usr/local.  I know that my environment is not quite correctly set.That's why I do some steps as root and source some environment variables from file setQpeEnv. But it works.

Here are the steps:
1. With Qt Designer create the main form.

Remark:
Qt Designer comes with the "ARM-Qtopia 2.2.0". It's executable is:
/usr/local/arm-qtopia/qtopia-2.2.0-FriendlyARM/qt2/bin/designer
The screenshot above is from this tool.
Do not try newer versions of Qt Creator. They are not compatible.

From File-New select "Dialog" template.  Change the "name" property to frmMainWindow. This will be the name of the form class.  Save it as MainWindow.ui. This is an XML file. You can view and edit it's contents with text editor.  For example if you want to add tabs to TabWidget this is the only option.

2. Create a script file "build" for building the application with following content:
#!/bin/bash
source /usr/local/arm-qtopia/qtopia-2.2.0-FriendlyARM/setQpeEnv 
qmake -spec /usr/local/arm-qtopia/qtopia-2.2.0-FriendlyARM/qtopia/mkspecs/qws/linux-arm-g++ -o Makefile *.pro 
make clean
make
3.Create a script file "formuic" for compiling the .ui form file with the following content
echo MAIN FORM
echo HEADER
/usr/local/arm-qtopia/qtopia-2.2.0-FriendlyARM/qt2/bin/uic -o MainWindow.h MainWindow.ui
echo CLASS
/usr/local/arm-qtopia/qtopia-2.2.0-FriendlyARM/qt2/bin/uic -i MainWindow.h -o  MainWindow.cpp MainWindow.ui 

Open a terminal window and go to the project folder. Run the script:
    #./formuic
The uic tool (user interface compiler) takes the .ui file. 
When MainWindow.ui is compiled two source files are created - a header and cpp. They content the form class "frmMainWindow".
 
4. Create two files main.cpp , MainWindowImp.h and MainWindowImp.cpp with the following contents:

main.cpp
#include <qtopia/qpeapplication.h>
#include "MainWindowImp.h"

QTOPIA_ADD_APPLICATION("stivlib",frmMainWindowImplementation)
QTOPIA_MAIN
QTOPIA_ADD_APPLICATION macro takes two parameters. The first is "stivlib"  - the name of the project.  The second frmMainWindowImplementation is the name of the class from MainWindowImp.h

MainWindowImp.h
In this file a new class frmMainWindowImplementation is defined which inherits the form class frmMainWindow.  This is done because each time you make changes to you form with Qt Designer and the .ui file is compiled any changes made in MainWindow.h and MainWindow.cpp will be lost. All the functional implementations like new variables definitions and new methods should be done in this new class. 

/****************************************************************************
** Created: Sun Jul 11 18:05:02 2010
**      by:  Svilen Stavrev
** Implementation Class for the main form
****************************************************************************/
#ifndef FRMMAINWINDOWIMP_H
#define FRMMAINWINDOWIMP_H

#include "MainWindow.h"

class frmMainWindowImplementation : public frmMainWindow

    Q_OBJECT

public:
    frmMainWindowImplementation( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ) 
    : frmMainWindow(parent,name,modal,fl)
    {
        //Constructor
    }
};
#endif // FRMMAINWINDOW_H
 
MainWindowImp.cpp
/************************************************
** Created: Sun Jul 11 18:05:02 2010
**      by:  Svilen Stavrev
** Implementation Class for the main form
************************************************/
#include "MainWindowImp.h"

5. Generate the .pro (project) file using the qmake tool:
    $su
    #source  /usr/local/arm-qtopia/qtopia-2.2.0-FriendlyARM/setQpeEnv
    #qmake -project

A project file stivlib.pro has been created.
Open it with the text editor and add these lines:

TARGET=stivlib         <-- This is the exact name of the target executable file. No extension .bin will be added
CONFIG += qtopiaapp
CONFIG -= buildQuicklaunch
5. Build the application
    #./build
Voila! The binary file stivlib is now in the project folder. 
On my next post I'll show how to upload it to the FriendlyARM board and how to create a desktop launcher.