Create a Model

To build your own model, you have to open the Simulink Library browser from within MATLAB:



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.

When the HANcoder STM32 Target expands the HANcoder blocks for the compatible STM32 development boards are visible.


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.

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. 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 that case the signal or parameter can be seen or edited by HANtune.

The HANcoder_Olimexino_startup.m is shown below:

% This m-file will be run automatically when starting model 'HANcoder_Olimexino'
% The name of the m-file must consist of the model name with the addition:
% '_startup'!
% This m-file will be run when loading the model because it is added to the
% model callbacks: see File->Model Properties->Model Properties->Callbacks

% In this m-file the signals and parameters for HANtune can be defined. As
% an example the signal LedValue and parameter HANtuneOverride are already
% defined.
% You can add your own signals and parameters to this m-file below

%% Signals
% Defining signals for viewing in HANtune
LedValue = Simulink.Signal; % Define as signal
LedValue.StorageClass = ‘ExportedGlobal’; % Only Exported Global will be visible in HANtune

% Defining System Information Signals
SI_FreeStack = Simulink.Signal;
SI_FreeStack.StorageClass = ‘ExportedGlobal’;
SI_CPUload = Simulink.Signal;
SI_CPUload.StorageClass = ‘ExportedGlobal’;
SI_FreeHeap = Simulink.Signal;
SI_FreeHeap.StorageClass = ‘ExportedGlobal’;

%% Parameters
% Defining a parameter for editing in HANtune
HANtuneOverride = Simulink.Parameter; % Define as parameter
HANtuneOverride.StorageClass = ‘ExportedGlobal’; % Only Exported Global will be visible in HANtune
HANtuneOverride.Value = 0; % Initial value is set to zero, no override