Configuring Matlab Coder, Eclipse IDE and CodeSourcery for Beagleboard development

28 May 2012

15:56

The process of setting up Matlab Coder and Eclipse for BealgeBoard development is similar to the setting up process for host PC (win7), except we need to create an ARM Windows Sourcery GCC project in Eclipse, rather than a Cygwin GCC project.

 

In this tutorial, we have a m file (getRand.m) in MATLAB to generate a normal distributed random number with mean of 10 and variance of 2. We generate C codes from the m file (getRand.m) by using the MATLAB coder.  Then we integrate these C codes into an Eclipse ARM cross target application project in Eclipse, buid the Beagle-compatible execute file by the CodeSourcery cross-compiler and finally run the executable file at Beagleboard remotely.

1. Generating C Code Using MATLAB Coder

Same as 'Generating C Code Using MATLAB Coder' in 'Configuring Matlab Coder, Eclipse IDE and Cygwin GCC for host PC'

2. Create a C project (ARM Cross Target Application) in Eclipse.

 

(2.1) Create a C project

Sine the final executable file is for the embedded target system (here, the Beagleboard), we need an ARM Cross Target Application C/C++ project . Select File > New > C project, a 'C Project' dialog opens. Select 'ARM Cross Target Application' and toolchain ARM  Windows GCC (Sourcery G++ Lite). Note that, in order to have the option of 'ARM Cross Target Application'  in the project type list, an ARM plugin is required. See xxx

Machine generated alternative text: Project type:
- ARM Cross Target Application
• Empty Project
ARM Cross Target Static Library
Executable
c± Shared Library
Oz, Statir I ihraru
E?1 Show project types and toolchains only if they are supported on the platform
<Back Ne> Finish Cancel J
Project name: genRnd_m2Beagle
Use default location
Location: E:\Beagle\Eclipseworkspace\genRnd_m2ßeagle
Choose file system: [default .rj
Browse...
Toolchains:
ARM Windows CCC (GNUARM, WinARM)
[ ARM Windows CCC (Sourcery C++ Lite)
ARM Windows CCC (Summon)
ARM Windows CCC (Yagarto)
ARM Windows CCC (devkitPro)

 

 

(2.2) Integrate the C codes from Matlab into the Eclipse project

This is done by a link folder. The Link folder links to the folder <matlabprojectroot>\codegen\lib\<matlabprojectname> where the C codes generated by the Matlab Coder are stored.  There two ways to add a source folder into the project:

 

Approach 1:  Add the folder of the generated C codes into the Eclipse project's build path. This is done by right-click project -> Properties -> C/C++ General -> Paths and Symbols, select 'Source Location' tab. Click 'Link Folder' to add the source files into the Eclipse project.

Machine generated alternative text: J Properties for coderand2 L 2 j’
type filter text Paths and Symbols w w V
Resource
Linked Resources
Resource Filters Configuration: Debug [Active] lE [Manage Configurations...]
Builders
C/C++ Build
C/C++ General [Includes [ # Symbols a Libraries [Library Paths š eLocationi References
Code Analysis Source folders on build path: [Add Folder...]
Code Style ___________
j [ /coderand2 [Link Folder...]
Documentation I I
I I  /coderand2/Frommatlabcoder ____________
File Types I I I 
Indexer J New Folder ___________
Language Mappings [ Delete ]
Paths and Symbols Folder name: Frommatlabcode
Project References
Run/Debug Settings [__«Advanced__[
Task Repository Ru Link to folder in the file system
WikiText
E:\Beagle\Test\MatlabCoder\helloworl d\codegen\exe\coderand [ Browse... ] [ Variables... [
Choose file system: [default w]
Location E:\Beagle\Test\MatlabCoder\helloworld\cod...r resource. This can cause unexpected side-effects.
OK Cancel [
1 LRestore Defayj [ Apply ]
LE OK JE] j Cancel [

 

Once set add the source folders into the build path, It is worth setting file 'filter' to add only the *.c/*.h files into the project by excluding other files, like *.bat, *.prj

 

 

3. Configure the ARM Cross Target Application project for Beagleboard

See the configuration at  XX

 

4. Build the project

Select Project > Build All. Then you will get the ARM executable file projName.elf.

 

Possible compiling errors  and trouble shooting:

(1) target pattern contains no `%' STOP 

This is due to Cygwin's new make.exe (3.82) does not recognise the windows path separated by '\'. Rollback to make 3.80 (Geant4) by following commands in Cygwin command window:

  • cd /usr/bin
  • mv make.exe make_381.exe
  • chmod +x make.exe

You may also need to install libintl2 package from cygwin setup for the required cygintl-2.dll

(2) "math.h" and "undefined reference to ..."

You can get "undefined reference to ..." error while you're trying to use math.h functions such as (log, logf, exp...), although the "math.h" library has been included in your code. The reason behind that is these functions being not implemented in libc. Thus, you have to compile your code with "-lm" parameter. For instance:

 

arm-none-linux-gnueabi-gcc -lm -Wall -pedantic -ansi -o foo foo.c

 

In Eclipse, add the flag "-lm" at Project Properties > C/C++ Build > Settings, in the Tool Settings tab, select ARM Sourcery Windows GCC Linker > Miscellaneous. In the dialog box 'Linker flags', click the icon '+' at the top right comer to add the flag "-lm".

 

Machine generated alternative text: 3 Properties for BeagleCOM2
j   j
Configuration: [pug [Active]
Tool Settings  Build StepsfBuild Artifact 1i Binary Parsers O Error Parsers
Target Processor
Debugging
L Additional Tools
ARM Sourcery Windows GCC Assembler
Preprocessor
ç Directories
Warnings
ç Miscellaneous
® ARM Sourcery Windows CCC C Compiler
ç Preprocessor
Directories
ç Optimization
Warnings
ç Miscellaneous
€ ARM Sourcery Windows CCC C Linker
ç General
Libraries
ç Miscellaneous
type filter text
Settings
Resource
Builders
C/C++ Build
Build Variables
Discovery Options
Environment
Logging
Settings
Tool Chain Editor
C/C++ General
Cit
Project References
Run/Debug Settings
Task Repository
WikiText
-‘
Manage Configurations...] S
Linker flags (-Xlinker [option])
I I Gi]
Other objects
LI

 

 

5. Run the programme at Beagle remotely

We need to create a Run Configuration for running programme remotely.  Select Run > Run Configurations, a new windows opens. In the left panel, right click 'C/C++ Remote Application' and select new,

Machine generated alternative text: 3 Run Configurations
Create, manage, and run configurations
—
t
Filter matched 10 of 19 items
Configure launch settings from this dialog:
J [5 - Press the New button to create a configuration of the selected type.
- Press the Duplicate button to copy the selected configuration.
s the Delete button to remove the selected configuration.
s the Filter button to configure filtering options.
- tui or view an existing configuration by selecting it.
Configure launch perspective settings from the PersQectives preference
page.
[ Run [[ Close j
I type filter text
C/C++ Application
C/C++ Remote APPIir
BeagleCOM2 Deb’ L
• Eclipse Application  Duplicate
Java Applet  Delete
Java Application
Ju Junit
.1t JUnit Plug-in Test
Launch Croup
• OSGi Framework

 

Enter the name of the run configuration, for example, genRnd_m2Beagle_RemoteRun.

Select the connection, e.g., Beagleboard_via_IP. More details on setting up the IP connection to Beagleboard, please see

Select the project to the project we want to run at Beagle, e.g., genRnd_m2Beagle

In 'C/C++ Application' box, click 'Browse' button to select the executable file from the project (local location), e.g.,

E:\Beagle\Eclipseworkspace\genRnd_m2Beagle\Debug\genRnd_m2Beagle.elf

 

In 'Remote Absolute File Path for C/C++ Application', we need to specify which executable file at remote location (Beagleboard) we want to run.  Click 'Browse' button, the 'Select Remote C/C++ Application File' dialog box opens. Select the connection for Beagleboard, if the connection is valid, when you click and expand 'MyHome' tree, you will see the files at the Beagle. Usually, we prefer to create a new subfolder at Home directory to maintain the files. Right click 'MyHome', select 'New', and  enter the name of the folder, e.g., genRnd_m2Beagle. Click Finish.

 

As the default output file of the build process is <ElcipseProjectName>.elf, add the executable file at the end of the remote location. The 'Remote Absolute File Path for C/C++ Application' now is

/root/genRnd_m2Beagle/genRnd_m2Beagle.elf

 

In the 'Commands to execute before application' enter the following command:

chmod +x genRnd_m2Beagle.elf

This is to make the *.elf file execuatble.

Machine generated alternative text: 3RunConflgurations — — — - — — — .—.- ‘Lit
Create, manage, and run configurations
pe filter text
C/C++ Application
C/C++ Remote Application
genRnd_m2Beagle Debug
• Eclipse Application
Java Applet
rn Java Application
Ju JUnit
i JUnit Plug-in Test
b Launch Group
* OSGi Framework
3 Select Remote C/C++ Application File
Select a file
Connection: [Beagleboard_viaJP
My Home
) My Home
BeagleCOM
BeagleCOM2
,i a.out
,1 BeagleCOM.elf
,i BeagleCOM2.elf
Debug
Select configuration using ‘C/C++ Application’
[ Browse_ ]
ri2Beagle.elf E:\genRnd_m2Beagle.elf
? Listing
nd_m2Beagle .elf > “genRnd_m2Beagle.lst”
Name: genRnd_m2Beagle Debug
Main *.A.guments]_fl Common
Connection: [gleboard_viaJP
Project:
genRnd_m2Beagle
Build configuration:
New... Properties... J
[ Browse... ]
C/C++ Application:
E:\Beagle\Eclipseworkspace\genRnd_m2Beagle\Debug\genRnd_m2Be [Search Project... [[ Browse...
V.
Remote Absolute File Path for C/C++ Application:
/root/genRnd_m2Beagle/genRnd_m2Beagle.elf
Commands to execute before application
chmod +x genRnd_m2Beagle.elf
LI Skip download to tarqet path.
3 New Folder
H
Remote Folder
Create a New Folder —
Connection name: Beagleboard_viaJP
Parent folder /root
New folder name: genRnd_m2Beagle
OK Can
[ Apply jj Revert [
Run ][ Close ]
©  Finish  [ Cancel ]
‘1tYSLhT na!

 

Click 'Apply' and then 'Run' to run the programme remotely at Beagle. At the Console window, you will see the output results of the programme.

 

Machine generated alternative text: Problems tTasks  Console  Properties J Git Repositories History. Error Log Problem Details
genRnd_m2ßeagle Debug [C/C÷ + Remote Application] E:\Beagle\Eclipseworkspace\genRnd...m2Beagle\Debug\genRnd_m2Beagle.elf (31/10/2012 ]
____________ __
Last login: Fri Jan 27 19:59:07 2012 from 10.2.1.1
echo $PWD’>’
chmod +x genRnd_m2Beagle.elf;/root/genRnd_m2Beagle/genRnd_m2Beagle.elf;exit
root@omap :
echo $PWD’>’
I/root>
root@omap :
root@omap:’# chmod +x genRnd_m2Beagle.elf;/root/genRnd_m2Beagle/genRnd_m2Beagle. elf;ex
chmod: cannot access genRnd_m2Beagle.elf’: No such file or directory
Start mainQ...
exp(1. eeeeee)=2. 718282
getRnd=11 .075334
getRnd=13 .667770
get Rnd=5 .482386
get Rnd=11.724347
get Rnd=1e.637538
get Rnd=7. 384623
get Rnd=9.132816
get Rnd=10.685249
getRnd=17.156794

 

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