Getting Started Guide Build Test

From OpenMBD
Jump to: navigation, search


Explanation of the template model

Open the Simulink model by starting MATLAB® and navigating to the HANcoder directory where the Simulink models are located, the ‘Target’ directory. By double-clicking the provided model file, i.e. ‘HANcoder_Olimexino.slx’, from within MATLAB® the model is started. The right directory can easily be found with the browse for folder button.
GettingStartedGuideSTM32 BrowseFolderMatlab.jpeg


Make sure that the Target folder is selected. Otherwise MATLAB® will have trouble finding the necessary files to build HANcoder models.
GettingStartedGuideSTM32 TargetFolder.jpeg


NOTE: MATLAB® versions prior to the 2013b release cannot open the .slx files and instead the .mdl files for these earlier versions can be found in the zip file: Template models for older versions.zip.

If the template model is used, the following screen will appear:
GettingStartedGuideSTM32 ModelStartScreen.png
Nothing in this part of the model can be changed, otherwise the code generation will no longer work!

When double-clicked on the picture of the controller, the content of this block is shown:
GettingStartedGuideSTM32 ModelMainView.jpeg

The figure above shows the template model. This is the base of every new project. This simple project makes the green LED blink at 5Hz when the button isn’t pressed and at 10Hz when it is. It is advised to keep this functionality in your project so you can always check if the software is still responsive. The template model consists of:
- The inputs subsystem
- The algorithm subsystem
- The outputs subsystem
- The configuration blocks
- The system Information subsystem

The inputs subsystem

GettingStartedGuideSTM32 InputsSubsystem.png
The inputs of the model are placed inside the Inputs subsystem. The inputs are connected with the Algorithm through Outport blocks (the block with ‘Button’ below it in the figure above).

The algorithm subsystem

GettingStartedGuideSTM32 AlgorithmSubsystem.png
In the algorithm subsystem the functionality is placed. The subsystem is connected with the inputs and outputs through In- and Outport blocks. The functionality can easily be transferred to another hardware platform because there are no in- or outputs in this part, it is recommended to work the same way in your own projects.

The outputs subsystem

GettingStartedGuideSTM32 OutputsSubsystem.png
In here the outputs of your model are located.

The configuration blocks

GettingStartedGuideSTM32 SystemConfigblocks.png
These blocks are the settings of the model.
The Base Sample Time config determines the interval at which the model is run. You can add blocks to the model which run at lower rates but not faster. In the template model the base sample time is 10ms so the model can run at a 100Hz.
The XCP on USB config block configures the Olimexino to communicate to HANtune over USB.
The Custom ID config block lets you choose a name and version number for your model, this will be used when connecting with HANtune.
With the Build settings you can let HANcoder automatically add all signals and parameters in the workspace of the project. This is important to communicate with HANtune.
The Auto Flash function flashes the software automatically after a successful build.

The system information subsystem

GettingStartedGuideSTM32 SystemInformationSubsystem.png
The system information subsystem gives you information about the Load, Heap and Stack of the system once the model is running. This way you can monitor how many resources your software program uses. The signals are already defined by HANcoder and will be visible in HANtune.

Build your own model

To build your own model, you will need some new blocks from the Simulink Library browser, click the icon shown below:
GettingStartedGuideSTM32 LibraryBrowserIcon.jpeg


GettingStartedGuideSTM32 LibraryBrowser.jpeg

Open the ‘HANcoder STM32 Target’ toolbox by clicking on it.

If the library isn’t visible try refreshing the library tree view by pressing F5. If there is a Pop up bar that says ‘Some libraries are missing repository information. Fix’ Click on Fix. Turn on ‘Generate repositories in memory’ in the pop up.
GettingStartedGuideSTM32 LibrarbyBrowserMissingRepoInformation.pngGettingStartedGuideSTM32 GenerateRepositoryInMem.png

When the HANcoder STM32 Target expands the HANcoder blocks for the compatible STM32 development boards are visible.
GettingStartedGuideSTM32 HANcoderLibrary.jpeg
To the right, the content of the toolbox is placed. This content is sorted in a tree like view for easy access. Use the help files to determine the proper use of a block. These are accessible by right clicking on a block and then selecting “Help”.

Working with m-scripts

The best option to define the parameters is by using m-scripts. An m-script is useful for a series of MATLAB® commands. In HANcoder an m-script is used for defining both signals and parameters. The template model automatically calls the startup m-script when it opens. This is done by adding it to the model properties: callbacks. Go to Simulink model-> File -> Model properties -> Callbacks. The Model pre-load function runs every command that is written in the section before the model starts.
GettingStartedGuideSTM32 ModelCallbacks.jpeg
As can be seen in the figure above, the call for the startup file is made with the following command:
eval([bdroot,'_startup']) (This calls the HANcoder_Olimexino_startup.m script)

It is advisable to define all parameters in the startup script. If this is done, the parameters will be added to the workspace every time the model is opened. When a parameter is added in the m-script, the m-script can be run manually by clicking run. The parameter will be added to the workspace.

The HANcoder_Olimexino_startup.m is shown below:
GettingStartedGuideSTM32 StartupMscript.png

Signals and parameters can be added in this file. If the storage class is set to ‘ExportedGlobal’ the value is set as a global variable. In this case the signal or parameter can be seen by HANtune.

Code generation

To generate C code from the Simulink model use CLTR-B on the keyboard when the model is opened. The model will ‘grey’ out during the build procedure.
In MATLAB® versions earlier than 2014a the progress can be observed in the MATLAB® command window. From 2014a this can only be viewed by clicking View diagnostics on the bottom of the model.
GettingStartedGuideSTM32 CodeGenerationProgress.jpeg

Once the model indicates ready in the lower left corner, the software program is built and flashed (if Auto Flash is on). In the target directory two new files appear.
Please see the troubleshooting guide if there are any errors.


Previous step (GNU ARM Installation)
Next step (Flashing with the bootloader)
Alternative next step (Flashing with the ST-Link)