Difference between revisions of "Simulink2ARM7"

From ConceptCar
Jump to: navigation, search
(Define CAN binding and marshaling)
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
==Overview==
 
==Overview==
  
This page describes the user interaction with the SimulinkTarget tool. Every step needed in order to get from Simulink Model to the Executable file is described in this page. The first step before getting the model to run in the ARM7 Board is to generate the code that implements the Simulink Model. This process is described here [[Simulink settings for generating code]].
+
This page describes the user actions required to get a Simulink model executed on the ARM7 borad. Every step needed in order to get from Simulink Model to the running Executable file is described in this page. The first step before getting the model to run in the ARM7 Board is to generate the code that implements the Simulink Model. This process is described here [[Simulink settings for generating code]].
  
 
==Create (or load) a project configuration file==
 
==Create (or load) a project configuration file==
Line 90: Line 90:
  
 
==Define output folder and generate code==
 
==Define output folder and generate code==
 +
 +
At this point every information related to the code generation (merge between the RTW code and the base system code) is already setup. The next step is to select the destination folder and the code is generated. The SimulinkTarget creates a folder named CODEGEN_yy-mm-dd_hh-mm-ss inside the selected destination folder.
 +
  
 
:[[image:simulinktarget11.jpg]]
 
:[[image:simulinktarget11.jpg]]
 +
 +
 +
The tool generates a header file that is used by the main execution loop. This header contains definitions about the name of the step function generated by RTW, information about the periodicity of the steps, etc. The user can check what kind of information is generated by opening the file "'''main.h'''" inside the folder "'''include/usr'''".
  
 
==Optionally compile the generated code==
 
==Optionally compile the generated code==
 +
 +
This is the last step in the work flow. Here the user can decide to compile the application within the tool. This step is optional because there is a makefile available for later compilation of the application. Nevertheless the user is able to select parameters for the compilation (such as debug information) and to deploy a binary executable through the SimulinkTarget tool.
 +
  
 
:[[image:simulinktarget12.jpg]]
 
:[[image:simulinktarget12.jpg]]
 +
 +
==Optionally compile the generated code manually==
 +
 +
You can also enter the folder where the code was generated and issue <pre>make simulink_can</pre> manually. This will build the executable with no optimizations and no extra features.
 +
 +
==Running the executable==
 +
 +
When the bootloader is installed on the ARM7 board, you're ready to go. Otherwise you need to install the bootloader first by following these steps: [[Flashing the ARM7 board]].
 +
 +
The bootloader automatically executes the binary from an SD-Card that is inserted into the ARM7's SD card slot at boot time. To boot into the executable make sure the following conditions are met:
 +
# The SD Card is at most 1GB in size (larger Cards are SD-HC and don't work)
 +
# The SD-Card is formatted with FAT32 file system
 +
# The executable is stored as the file <pre>app.bin</pre> inside the SD-Cards root folder
 +
 +
To control the bootloader's work it is easiest to connect to the ARM7 board over UART (115200Baud 8N1) and watch the status messages.

Latest revision as of 06:25, 14 May 2009

Overview

This page describes the user actions required to get a Simulink model executed on the ARM7 borad. Every step needed in order to get from Simulink Model to the running Executable file is described in this page. The first step before getting the model to run in the ARM7 Board is to generate the code that implements the Simulink Model. This process is described here Simulink settings for generating code.

Create (or load) a project configuration file

The SimulinkTarget tool creates a configuration file where all the decisions made during the conversion process are saved. Doing so enables the user to load the configuration file and avoids the overhead of going through all of the steps every time new code is generated. The first step is to either load or create a configuration file.


Error creating thumbnail: Unable to save thumbnail to destination


After loading/creating a configuration file, new tabs are enabled and the user may proceed to the next steps.


Error creating thumbnail: Unable to save thumbnail to destination


As the user can easily note, the tab Simulink Model has been enabled and is intuitively the next step to be taken.

Load the simulink model

The tool needs to load a Simulink Model in order to obtain model specific information, such as port names, model name, etc. After parsing the model necessary information is collected and the tool can go further. The first image shows the select model screen.


Error creating thumbnail: Unable to save thumbnail to destination


The user then selects the MDL file that contains the model that will be executed on the ARM7 platform.


Error creating thumbnail: Unable to save thumbnail to destination


Once again after completing the required steps inside the tab, new tabs are enabled and the user can continue to enter information required to achieve the final executable file.

Load the RTW generated code

In order to complete this step, the user must first execute the Simulink settings for generating code and generate code with the Matlab Simulink Real-Time Workshop.


Error creating thumbnail: Unable to save thumbnail to destination


After the folder containing the RTW generated code is specified, the tool will merge the model code together with the base system code. The base system code is selected in the next step.

Select the base stub code used

The stub code contains both the base system functionality and the main system loop. The main system loop is responsible for the execution of the model. The main loop execution is described in Simulink Execution on the ARM7 target.


Error creating thumbnail: Unable to save thumbnail to destination


The screenshot above presents the user two options. One of them is to use the code provided with the SimulinkTarget tool. In this case the code used is related to a specific SVN release and will contain a version number. The user must be sure to use compatible combinations of software, that is, bootloader version should be the same as the stub code used with the SimulinkTarget.

In case the user has a copy of a newer code that either does not match the version provided by the tool or that is not yet a release, it is possible to select the second option. If this option is chosen, the user must provide the address of the folder containing the stub code.


Error creating thumbnail: Unable to save thumbnail to destination


After selecting one of the two options two tabs are enabled. The user can thereafter walk through the final steps in the process of setting up the configuration for generating a binary executable. The figure below differs from the above regarding the status of the configuration file. After clicking the Save button the tool removes the asterisks from the tittle bar.


Error creating thumbnail: Unable to save thumbnail to destination


The base stub code provided by the tool or the user will be used together with the RTW generated code to compose the final source code, which will then be compiled into an application loaded by the ARM7 board bootloader.

Define CAN binding and marshaling

This part of the work flow defines the CAN port binding. Since in the Concept Car there is a CAN bus responsible for supplying a communication means to all of the boards in the network, all data is transmitted through it. When modeling functionality in a Simulink Data-Flow model, there is only reference to IN ports and OUT ports. The model does not describe how data is input and output to the ports. They are an open link to the environment where the model executes.

For this reason the user must provide a binding of the ports from the model to the Car's communication mechanism, which is a CAN bus. This is done by assigning CAN ids to can messages that will carry the data to and from the model (more specifically, to/from the model ports).


Error creating thumbnail: Unable to save thumbnail to destination


The user is able to define an ID, which will be automatically converted to a Hexadecimal value by the tool. A gradient, which is used to transform the value that the message carries (e.g. to transform a floating point number into an integer number). And a y-intercept parameter used to determine a scaling factor for the message value. These three fields are user configurable and the last two are optional. The optional fields are enabled by the checkboxes.


Error creating thumbnail: Unable to save thumbnail to destination


After defining the configurable fields for all ports the user can move on to the next step where the code will be generated. The information entered here by the user will be used during code generation. When the generator writes the code to get the value from the model (accessing the structure defined by the RTW generated code) it will then use the ID defined by the user to call the base CAN code to send the message on the bus.

The code generator figures the port variable names based on information from the Model and creates code to access them. After that, code is generated to send the values of the variables through the CAN bus using the IDs defined by the user.

Define output folder and generate code

At this point every information related to the code generation (merge between the RTW code and the base system code) is already setup. The next step is to select the destination folder and the code is generated. The SimulinkTarget creates a folder named CODEGEN_yy-mm-dd_hh-mm-ss inside the selected destination folder.


Error creating thumbnail: Unable to save thumbnail to destination


The tool generates a header file that is used by the main execution loop. This header contains definitions about the name of the step function generated by RTW, information about the periodicity of the steps, etc. The user can check what kind of information is generated by opening the file "main.h" inside the folder "include/usr".

Optionally compile the generated code

This is the last step in the work flow. Here the user can decide to compile the application within the tool. This step is optional because there is a makefile available for later compilation of the application. Nevertheless the user is able to select parameters for the compilation (such as debug information) and to deploy a binary executable through the SimulinkTarget tool.


Error creating thumbnail: Unable to save thumbnail to destination

Optionally compile the generated code manually

You can also enter the folder where the code was generated and issue
make simulink_can
manually. This will build the executable with no optimizations and no extra features.

Running the executable

When the bootloader is installed on the ARM7 board, you're ready to go. Otherwise you need to install the bootloader first by following these steps: Flashing the ARM7 board.

The bootloader automatically executes the binary from an SD-Card that is inserted into the ARM7's SD card slot at boot time. To boot into the executable make sure the following conditions are met:

  1. The SD Card is at most 1GB in size (larger Cards are SD-HC and don't work)
  2. The SD-Card is formatted with FAT32 file system
  3. The executable is stored as the file
    app.bin
    inside the SD-Cards root folder

To control the bootloader's work it is easiest to connect to the ARM7 board over UART (115200Baud 8N1) and watch the status messages.