We explained configuration, installing required software for compiling program and running the first program as third article. In this article we want to teach you how to install Eclipse that is an editor. Writing program and making it ready for running hardware cause feeling lack of a powerful editor, which not only makes coding easy but also interesting.
Types of Editors
It’s still possible to write program in notepad or other simple editors but readability and speed of writing is important. As the program gets bigger and has more functions, it’s harder to memorize names of functions and variable; and after finding the name, you have to find input parameters, which is super hard and exhausting. besides, the special editors for programming change the color of different parts of code, which improve readability.
difference between professional and simple editors
Left image is a simple editor and right image is a professional one with many capabilities.
There are many editors for every programming language. Some editors support more than one language. Usually for hardware and systematic programming, C and C++ is used; we need an editor which support these two languages. There’s a lot of commercial editors with suitable features but, due to the sisoog policy, we only introduce and use free and open-source editors.
Some examples of popular and open-source editors:
There are more editors than above but I just suggested editors which I have worked with them and support minimums.
There’s lots of Editors, which is hard to choose, but supportive features are so important. We chose Eclipse.
Eclipse is more popular as a Java editor but it can support 44 programming languages and it is available for 4 operating systems: Linux, Windows, Mac and Solaris.
You are free to use any editor depends on your needs and feature; we use Eclipse for tutorial because of these features:
Capability to support many languages
Capability to install plug-in
Capability to run in different OSs
How to install Eclipse?
Before installing Eclipse, you have to install Java(JRE). Depends on Eclipse version, proper Java version is needed; in this tutorial we use the last version of Eclipse named Oxygen, which needs java 1.8.
The first Step:
Before downloading and installing Java, you can check, maybe, it is installed with other software.
Type “java-version” in command line (terminal or command prompt)
If java is installed, output must be like below; pay attention that its version must be 1.8.
Otherwise you can download Java 1.8 from this link and follow the steps below:
After installing finishes, be sure about correctness and version of Java:
The second step: download and install Eclipse
Fortunately, there’s no need to install Eclipse because it uses Java virtual machine; just download executable file and extract it.
There’s two ways for setting up Eclipse. The first, downloading Eclipse, then download and install Plugin (for C language must use CDT plugin); this way lets you using Eclipse by more than one programming languages.
The second way is easier, you can download and install special version of Eclipse that each popular language Plugin has been installed on it.
Here we used the second one. Go to Eclipse website and click on C/C++ icon.
Then, extract the downloaded file.
The third step: install ARM development plugin
It is needed to install another plugin named GNU ARM for running program in the ARM platform easily. This also adds some examples and samples to project wizard, which makes building and configuring ARM project easy. First of all, run Eclipse and follow steps below:
Here, we specify workspace location. Every workspace, which is different with project, can contains more than one project.
After running Eclipse successfully, you see welcoming page, that introduce Eclipse and gives some guidance for using it. For installing plugin, select “Install New Software” form “Help” menu.
In opened page, click Add button.
At “Name” field, enter GNU ARM and at “Location” field enter the following value. Then, click OK button.
So Eclipse tries to load plugin information. Wait till the end of loading.
After loading plugin information, related information show like picture above. Select required packages and click Next.
Here, it shows selected packages; click Next if everything is correct or click Back to edit them.
Here, you have to accept the terms of the license agreement and click Next.
Wait until the installing and downloading required sections finish; note that you should confirm every downloaded part likes below.
After installing plugin, Eclipse shows a massage to restart; accept it.
Install Linux tools:
This is true, we need free GNU tools for writing and compiling program in windows. For this purpose, we should install necessary tools which are ready as packages and you can download them; go to the link below.
Download the latest version
For installing, just click Next buttons like others. Just memorized the installation path because it must be added to system’s path.
Default destination path is defined as the picture above
As we said you should add destination address to system’s path; right-click on My Computer and select Properties.
Then, click Advanced system settings as below
Then click Environment Variables
Select PATH from “User variables for Zeus” and click Edit button.
In opened window, at Variable Value, add a “;” at end of line, then add address of make.exe file.
This file is usually in bin folder in installation location as below
At the end, close all opened windows by clicking OK button.
To make sure about path, run command line and type this command
The output must be as below
Copyright(C)2006Free Software Foundation,Inc.
Thisisfree software;see the source forcopying conditions.
There isNO warranty;noteven forMERCHANTABILITY orFITNESS FORA
Thisprogram built fori386-pc-mingw32
It means installation and configuration of needed tools have done correctly.
Creating the first Raspberry-pi project
Now, we want to program Raspberry-Pi 2 using Eclipse editor. We use blinking LED project, which was taught at the second tutorial.
Here is the code:
/* The base address of the GPIO peripheral (ARM Physical Address) */
#define GPIO_BASE 0x3F200000UL
#define GPIO_GPFSEL4 4
#define GPIO_GPSET1 8
#define GPIO_GPCLR1 11
#define LED_GPFSEL GPIO_GPFSEL4
#define LED_GPFBIT 21
#define LED_GPSET GPIO_GPSET1
#define LED_GPCLR GPIO_GPCLR1
#define LED_GPIO_BIT 15
/** GPIO Register set */
/** Simple loop variable */
/** Main function - we'll never return from here */
/* Assign the address of the GPIO peripheral (Using ARM Physical Address) */
/* Write 1 to the GPIO16 init nibble in the Function Select 1 GPIO
peripheral register to enable GPIO16 as an output */
/* Never exit as there is no OS to exit to! */
/* Set the LED GPIO pin low ( Turn OK LED on for original Pi)*/
/* Set the LED GPIO pin high ( Turn OK LED off for original Pi)*/
First of all, select C project to build one, as below:
Choose a name for your project. just be careful, it shouldn’t contain space character. You can use underline character “_” for separating words. For example, type “Start_Raspberry” instead of “Start Raspberry”.
There may be more choices for Project Type, depends on your installed plugin. For example, there’s some ready project for STM32; but we want to create a project for Cortex-a7, so we choose Hello Word ARM C project.
Choose Cross ARM GCC from Toolchains. This part depends on different installed compiler may has other options.
Then click Next button.
install eclipse editor
In the next step, you can type your name as author or creator, this cause your name to be default for future projects. However, it is optional.
But remember to delete all at “Linker semi-hosting Options”. For this project these are not needed. Click Next.
We have nothing to do with this step for now. Click Next.
This is an important step which we choose compiler installation address.
Given that Eclipse supports wild range of compilers, we have to define compiler and its path folder. We want to write program for Raspberry-Pi, so we have to use ARM compiler. If you don’t have Raspberry-Pi compiler you can go to the third part of Raspberry-Pi tutorial.
Type the first part as the picture below. In the second part you should enter “arm-none-eabi-gcc.exe” file path; for this you can click Browse button and choose the folder.
By clicking Finish button, you create the first project.
Then you face an environment as below. you can see project files at the right side of picture that you can edit each of them by clicking.
For compiling codes click on hammer icon or use Ctrl + B buttons.
It is completely predictable that it doesn’t compile and has errors as below. replace your program with created default program; then, you have to adjust settings so that proper outputs become ready to be run on Raspberry-Pi.
To adjust settings, select the project then select properties from Project menu.
In opened window, select C/C++ Build from left menu and click Settings to open compililing adjustment.
At “Target Processor” we can configure processor type, its architecture and extra options like FPU, so output will be compatible with hardware. Adjust Raspberry-Pi 2 settings as shown below.
Optimization settings cause an optimal program; but we disable it because we don’t need it for now.
Next step is debugging. We set it as default because we don’t want to debug it.
Next setting is about Linker, change this part like the picture below.
Now you should define output format for compiler. It must be binary because program placed in RAM by bootloader.
At last you should define final output format for compiler. As you know from previews articles, it must be kernel.img, so bootloader is able to boot it.
Put following command in “Command line pattern” as it shows in the picture blow.
After these settings, all you have to do is compiling the project.
If you get somethings like the picture above, we congratulate you on your first successful Raspberry-Pi program.
To get the output file, select Kernel.img from Debug folder, which is created inside of project, and use Ctrl + C bottoms for copying it.
We finished the first series of Raspberry-Pi articles.
We tried to teach basic concepts of hardware, booting methods and hardware functionality.
Besides them we prepare necessary tools for compiling and creating codes. In the second series, we’re going to teach you how to set up different parts of hardware like GPIO and URT, and getting acquainted with creating startup files and using IRQ.
Dear followers, we are glad to share your experienced. Send pictures of your hardware, so we will share them on your name on sisoog Instagram.
Author: ZeusTranslate: Golnoosh