Configuring Matlab Coder, Eclipse IDE and CodeSourcery for Beagleboard development
28 May 2012
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
(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.
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:
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".
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,
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.,
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
In the 'Commands to execute before application' enter the following command:
chmod +x genRnd_m2Beagle.elf
This is to make the *.elf file execuatble.
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.
with Microsoft OneNote 2010
One place for all your notes and information