Programming, Raspberry Pi

Raspberry Pi Without OS (Part 4)

how to use eclipse editor with raspberrypi
  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. Stay tuned. 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. Eclipse editor 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:
  • Netbeans
  • Eclipse CDT
  • Code:Bloks
  • CodeLite
  • Geany
  • Qt Creator
There are more editors than above but I just suggested editors which I have worked with them and support minimums. Our Suggestion: 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.
eclipse editor

ویرایشگر Eclipse

Eclipse Editor You are free to use any editor depends on your needs and feature; we use Eclipse for tutorial because of these features:
  • Open-source
  • Capability to support many languages
  • Capability to install plug-in
  • Capability to run in different OSs
  • Suitable interface
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. How to install Eclipse 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:   How to install Eclipse How to install javaHow to install java After installing finishes, be sure about correctness and version of Java: java version 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. Download_Eclispe_cdt   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: eclipse ide installing eclipse Here, we specify workspace location.  Every workspace, which is different with project, can contains more than one project. Eclipse editor IDE 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. Eclipse editorhow to install Eclipse editor 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. how to install eclipse plugin After loading plugin information, related information show like picture above. Select required packages and click Next. how to install eclipse plugin Here, it shows selected packages; click Next if everything is correct or click Back to edit them. how to install eclipse plugin Here, you have to accept the terms of the license agreement and click Next. how to install eclipse editor Wait until the installing and downloading required sections finish; note that you should confirm every downloaded part likes below. how to install eclipse editor After installing plugin, Eclipse shows a massage to restart; accept it. how to install eclipse editor 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 eclipse version download For installing, just click Next buttons like others. Just memorized the installation path because it must be added to system’s path. eclipse download 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. install eclipse editor Then, click Advanced system settings as below install eclipse editor Then click Environment Variables install eclipse editor Select PATH from “User variables for Zeus” and click Edit button. install eclipse editor 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   install eclipse editor 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 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:   First of all, select C project to build one, as below: install eclipse editor 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

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. install eclipse editor We have nothing to do with this step for now. Click Next. install eclipse editor 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. how to use eclipse 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. how to use eclipse 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. how to use eclipse To adjust settings, select the project then select properties from Project menu. how to use eclipse In opened window, select C/C++ Build from left menu and click Settings to open compililing adjustment. how to use eclipse 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. how to use eclipse Optimization settings cause an optimal program; but we disable it because we don’t need it for now. how to use eclipse Next step is debugging. We set it as default because we don’t want to debug it. how to use eclipse Next setting is about Linker, change this part like the picture below. how to use eclipse Now you should define output format for compiler. It must be binary because program placed in RAM by bootloader. how to use eclipse 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. how to use eclipse After these settings, all you have to do is compiling the project. how to use eclipse If you get somethings like the picture above, we congratulate you on your first successful Raspberry-Pi program. how to write code in eclipse 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. Conclusion 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: Zeus Translate: Golnoosh 

انتشار مطالب با ذکر نام و آدرس وب سایت سیسوگ، بلامانع است.

شما نیز میتوانید یکی از نویسندگان سیسوگ باشید.   همکاری با سیسوگ

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *