Hello world at Beagleboard (native toolchain gcc)

Created on 04 May 2012 14:51

(Part 1) Pre<     Return to: Embedded Code Generation Home    Next> (Part 2)

    1. Install Ubuntu 11.04 at Beagleboard
    2. Connect host computer to Beagleboard via serial terminal
    3. Install gcc compiler for ARM
    4. Edit Hello World program at terminal window
    5. Set IP configuration
    6. Transfer files from Windows to beagleboard over Ethernet


     

    As the first step of my journey, this step-by-step guide is that I used to set up a native toolchain  (a gcc complier) at Beagleboard and compile/build the program to get executable file locally at the Beagleboard. Since I mainly use Windows and running the Matlab at 64-bit Windows 7,  my first choice is to set up a Windows-based development environment for Beagleboard. (I tried a VMwavre virtual machine with ubuntu, but it failed to install Matlab on a virtual machine. I guess this is because the Matlab need to check the series number of harddrive and Enternet MAC address, whileas the series number of MAC address in a virtual machine seems different from those in the host windows. That is another long story. If you have solution to this, it will be really appreciated to let me know.) 

     

    Writing a hello world programme, building it and run it is always the first step for a programmer. Although there are have been instructions on how to build  a image to start the Beagleboard,  It is a technical-intensive and deep learning curve. Too deep to build a Hello world easily. Since the Beagleboard has come with a SD card with a linux, it is more exciting to build your own programme and run it at BB.  I have spending nearly ten days to find how can I do this. Thanks to Gerard Marull Paretas and his introduction document (www.teslabs.com/wp-content/uploads/2010/02/beagleboard.pdf) which gives me a good  starting point.

     

      The instructions below assume a 64bit PC (intel) running Windows 7 and a Beagleboard-xM running linux unbuntu 11.04.If you have a different Windows/Linux distribution, the menus and other details may vary. Also I have wholesale copied instructions from various websites that showed how to do some of the individual bits. I originally wrote this for my own memory and I tried to keep the links to these website and people, but apologize for not properly attributing all of these, since I have forgotten where I borrowed from.)

     

     

    1.   Install Ubuntu 11.04 at Beagleboard

    There has been a lot of step-by-step tutorial on installing a linux on the Beagleboard. I'll save that for another day, as I am interested in build your own application programm and run it on your beagle board.

     

    For a simple installation, I used the Matlab 2012a to build the ubuntu for my BB. Simply type ">> targetInstaller" at the Mablab command window and follow the instruction there.  (More details see  Install Target for Use with BeagleBoard Hardware, http://www.mathworks.co.uk/help/simulink/ug/install-target-for-beagleboard-hardware.html).

     

    1.   Connect host computer to Beagleboard via serial terminal.

     

    In my case, the host computer is a PC running Win7. The steps are summarized as follows, for more details, see Open a Serial Command Line Session with the BeagleBoard Hardware.

     

    (2a)  Use a USB-Serial cable to connect the usb port of the host computer to the DB9 port of the beagle board.

    (2b) If it is your first time to use the USB-serial cable, you need install a driver for the USB-serial cable.

    (2c) Identify the COM port for your serial connection. In Win7, search and open the 'Device Manger' and expand Ports (COM&LPT) to see the list of serial connections. Usually, you will find a device called "Prolific USB-to-Serial Comm Port (COM#)", where '#' is a number.

    (2d) Start PuTTY by typing 'Putty' at the 'Search Programmes and files' box in the Start menu and click the

    Machine generated alternative text: Programs (5)
e3.
s PUlELcaton putty (C:\F’rogram iies (xb)\Vu II Y) I
PuTTY Web Site
ý Pu1T/gen
ý PuTTYgen
Documents (1)
!i Linux.docx
Microsoft OneNote (1)
Li Hello world
Files (22)
j putty.exe
j puttytel,exe
NI
‘rj EmbeddedSys.one
L WPuTTYCD-O.6010,zip
WPuTIYCD.dll
j WPuflVCD.dII
r
P See more results
Shut down

    (2e) In the PuTTY window, select the Serial Category and configure the selected COM port to:

    Serial line to connect to: COM# (in my laptop, it is COM6)

    Speed (baud)  115200

    flow control: None

    Machine generated alternative text: PuTTY Configuration
Category:
9 Session J Options controlling local seilal lines
Logging Select a serial line
9.. Terminal
Keyboard SerraI line to connect to COM1
Features Configure the serial line
Q.. Window Speed firaud) 115200
Appearance
. Databits B
Behaviour
[ Tran&ation Stop bits 1
Selection
Colours Panty [None V j
8 Connection Row control [None .]
Data
Telnet
f Riogin
Ë SSH
j bout ] [ Open ][ Cancel ]

    (2f)  In the PuTTY dialog box, select the Session category.

    Machine generated alternative text: PuTTY Configuration
Category:
Session
Logging
E Terminal
Keyboard
Bell
Features
E Window
Appearance
Behaviour
Translation
Selection
Colours
E Connection
Data
Proxy
Telnet
Rlogin
SSH
• Serial
Always
Never O Only on clean exit
j Open j [ Cancel j
Basic options for your PuTTY session
Specify the destination you want to connect to
Serial line Speed
COM6 115200
Connection type:
Raw Telnet Riogin SSH O Serial
Load, save or delete a stored session
Saved Sessions
MyBeagle
efaultSethngs [ Load
_________ .
MyBeagle_COM7 [ Save J
MyBeagle_SSH __________
[ Delete j
Close window on exit
L About J L Help j

    You may type in a name in the 'Saved Sessions' and click 'Save' button for future use. The next time when you start PuTTY, you can select the session you saved and click 'Load' and then 'Open' to start serial session straightforward.

    (2g) When a terminal window opens, press the Enter. Then type in the user name ubuntu and the password temppwd to login.

    Machine generated alternative text: 4) COM7 - Pum Ic aa1
A
Thuntu 11.04 omap ttyO2
omap login: ubuntu
Password:
Last login: Fri Jan 27 18:27:12 EST 2012 on ttyO2
Welcome to Ubuntu 11.04 (GNU/Linux 3.l.4-x6 armv7L’
* Documentation: https: I/help. ubuntu. com/
ubuntu@omap:—$ •

     

     

     

    1. Install gcc compiler for ARM

    To install ARM GNU/LINUX compiler collection from Ubuntu, enter the following at the command line.

     

    $ sudo apt-get install gcc-4.5-arm-linux-gnueabi

     

    You may choose other compilers, such as the CodeSourcery ARM/LINUX Lite compiler, etc. The good thing of CodeSourcery is that they provide a free lite version that runs in Windows 7 without any Cygwin/MingWin etc. That is great for me (I use Linux from time to time, Linux is great, but I feel more comfortable when using  windows. In particular, installing a programme in Windows is straightforwad, you do not need keep googling to sort out the dependences of packages).  I save it for another day. More details, see http://elinux.org/BeagleBoard_Ubuntu_%26_DSP_From_Sources

     

    You can verify that the gcc is set up correctly by entering

    $ gcc

    You should get an error message

    "gcc: no input files"

    This suggests that the compiler has been installed sucessfuly and beagleboard can find the gcc compiler.

     

    1. Edit hello world program at the terminal window

     

    Use nano to edit the "hello world" programme. Click here to download the main.c source code.

    main.c(hello world)

    ____________________________________________

    #include <stdio.h>

    int

    main (void)

    {

    printf("Hello Xuewu Dai\n");

    return 0;

    }

    ____________________________________________

     

    Machine generated alternative text: COM7 - PuTTY

     

    Press Ctrl+x.
    Enter
    Y to save the modified buffer.
    For "File Name to Write: main.c", press Enter.

     

    Then, enter

    $ ls

    You will see a file 'main.c' at your current folder.

    To compile your programme and generate an executable file, enter

    $ gcc main.c -o helloworld

    I name the output executable file to helloworld.

    Run the programme by entering

    $ ./helloworld

     

    Great! You will see

    'Hello Xuewu  Dai'

     

    Machine generated alternative text: COM7 - PuTTY

     

    1. Set IP configuration

    I feel difficult to edit program in nano. A better way is to edit the program at the windows host PC and transfer the file to the beagleboard. You can use usb drive, but it would be more convient to use Ethernet connection without a lot of plug-in-and-plug-out. I decide to use SSH+WinSCP to transfer the file vis Ethernet.

     

    Before transfering the file at WinSCP, we need set up the IP configuration at both Beagleboard and the host PC (Windows 7).

     

    If you want edit your program at the terminal window, you do not need do this step.

     

    The IP address of the Beagleboard is configured by the interfaces file at

    /etc/network/interfaces. You need to edit the file to modify the IP configuration.

    At the terminal window of PuTTY,

    (3a) Display the conetents of the /etc/network/interfaces file. Enter

        $ cat  /etc/network/interfaces

    (3b) Create a backup of the interfaces file. Enter

        $ sudo cp /etc/network/interfaces /etc/network/interfaces.backup

    (3c) Change the permissions of interfaces so you can edit the file. Enter:
         $sudo chmod 777 /etc/network/interfaces
         Enter the root password when prompted (default: temppwd).

    (3d)Edit interfaces using a simple editor called nano. Enter:
        $ nano interfaces

    (3e) Edit the last word of line that starts with iface eth0 inet.
    To use DHCP services, edit the line to say:
    iface eth0 inet dhcp

    For static IP settings, add lines for address, netmask, and gateway. For example:
    iface eth0 inet static
        address 192.168.
    2.2
        netmask 255.255.255.0
        gateway 192.168.
    2.1

    Machine generated alternative text: &--- -iiY
‘:—$ nano /etc/network/interfaces
GNU nano 2.2.6 File: /etc/network/interfaces ‘
friified I
auto lo
iface lo met loopback
* The primary network interface
auto ethO
iface ethO met static
address 192.168.2.2
netmask 255.255.255.0
gateway 192.168.2.1
* Example to keep MAC address between reboots
*hwaddress ether DE:AD:BE:EF:CA:FE
%jve modified buffer (ANSWERING “No” WILL DESTROY CI-LANGES) ?

     

    (3f) Tell nano to exit and save the changes:
    Press
    Ctrl+x.
    Enter
    Y to save the modified buffer.
    For "File Name to Write: interfaces", press Enter.
    The nano editor confirms that it "Wrote # lines" and returns control to the command line.

    (3g) Restore the original file permissions. Enter:
       $ sudo chmod u=rw,g=r,o=r interfaces
    Enter the root password when prompted. (default: temppwd)

    Check the ip seetings. Enter

       $ Ifconfig

    Machine generated alternative text: COM7 - Pum
ubuntu@omap: -4 ifconfig
ethO Link encap:Ethernet HWaddr 46:d6:Oe:09:b2:3e
met addr:l92.l68 .2.2 Bcast:l92.168 .2.255 Mask:255.255.255.0
inet6 addr: fe8O::44d6:ett:teU9:b23e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1488 Metric:l
RX packets:427625 errors:O dropped:135 overruns:O frane:O
TX packets:47283 errors:0 dropped:0 overruns:O carrier:O
collisions: O txqueuelen: 1000
RX bytes:313016666 (313.0 MB) TX bytes:3869947 (3.8 MB)
Link encap:Local Loopback
met addr:127 .0.0.1 Mask:255.0.0.0
inet6 aððr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:31 errors:O dropped:O overruns:O frame:O
TX packets:31 errors:0 dropped:0 overruns:0 carrier:0
collisions: O txqueuelen: O
RX bytes:2621 (2.6 KB) TX bytes:2621 (2.6 KB)
ubuntu@omap:-$ •

    (3h) If the inet addr, netmask and gateway is not as same as the interferces, you need to refresh the network configuration. Enter

    $ /etc/init.d/networking restart

     

    And then check the IP settings to confirm the modification has taken effect.

     

    (3i) Use a Ethernet cable to connect the BB to a hub or directly to your computer's LAN port.

    Open a DOS command window at the host computer (note, it is the DOS command window at your host Win 7 computer,  not the PuTTY window) and Enter

    Ping 192.168.2.2

     

    1. Transfer files from Windows to beagleboard over Ethernet

     

    Easiest method is probably going to be SFTP/SCP.

    (6a) On the BeagleBoard

    Install ssh if not already installed:

    $ sudo apt-get install ssh

     

    (6b) On the Windows Host computer,

     You can grab a copy of WinSCP or the Portable version for your windows machine. Then in WinSCP, put the linux machine name as the server (or IP if you can't connect via name). Once connected, navigate to preferred/necessary directories and drag and drop as desired.

    For more "permanent" solution, you could install samba on your linux machine and then connect from the windows machine, but that would require learning how to configure samba so that the two systems can connect to each other.

     

     <http://superuser.com/questions/315566/transfer-files-from-windows-to-linux-over-the-network>

     

    Machine generated alternative text: WinSCP Login I  11
Session Session
Stored sessions Host name: Post number
Environment
192.168.2.2 22
Directories
SSH
ijser name: Eassword:
Preferences
ubuntu
Private hey file:
Protocol
Eue protocol: [SFTP ‘rj LAllowSCPfallback
[_Select color_]
D Advanced options ______
L AbouL. J Languagesj 1n L Save... J L Close J

     

    Machine generated alternative text: ‘h Documents - ubuntu@192.168.2.2 - WinSCP I [icn 
Local Mark Files Commands Session Options Remote Help
ojijm-   i[fi—&:i[:1rø:HDefault
Mydocuments - r ubuntu -E 
w e
C:U sersdanDocuments ihome/ubuntu
F F
Name Ext  Name Ext
. myTestModel_rtt
. Bluetooth Exchange Folder bash_history
. Dell WebCam Central .bash_logout
. IEEEtran .bashrc
. MATLAB .esd_auth
¡b My Music  profile
, My Pictures pulse-cookie
I My Videos .sudo_as_admin_successful
. Notes arm-2011.03-41-arm-none-linux-gnueabi.bin
. OneNote Notebooks hello_world L
. Tencent Files Ecmain.c
OBof3S,883KiBinOof3O OBofl3SMiBinOofl3
* i F7 Create Directory Ê F10 Quit
ô SFTP-3 “ 0:00:25

    You can check the files at your home directory of Beagleboard through the PuTTY serial session. At the PuTTY window, enter

    $ cd ~

    $ pwd

    $ ls -l

    You will find the new file main.c

    Machine generated alternative text: 4) COM7 - PuUY
ubuntu@omap:
ubuntu@omap: -$
ubuntu@omap: -$
ubuntu@omap:
ubuntu@omap:—$ cd -
ubuntu@omap:-$ pwcL
/home/ubuntu
ubuntu@omap:—$ is —i
total 142308
—rw—r——r—— 1 ubuntu ubuntu 145703744 2012—05—04 09:47 arm—2011.03—41—a
rm—none—linux—gnueabi . bin
—rwxr—xr—x 1 root root 7701 2012—05—04 10:07 helio_world
—rw—r——r—— 1 ubuntu ubuntu 223 2012—05—04 09:02 main.c
drwxr—xr—x 3 ubuntu ubuntu 4096 2012—01—27 18:14 myTestModelau
ubuntu@omap:—$ •

     

     

 

Created with Microsoft OneNote 2010
One place for all your notes and information