The MATLAB Simulink blockset for the GOcontroll Moduline controllers: the block libraries, the Embedded Coder target and two model templates.
| Controller | Platform |
|---|---|
| Moduline S1 | STM32, FreeRTOS |
| Moduline M1, L4, HMI1 | Linux (ARM64) |
This repository is the blockset only. To start a project, use GOcontroll-Simulink-Starter: a ready project folder that carries this repository as a git submodule. Your models stay in your own repository and you update the blockset with one git command.
Documentation: the GOcontroll knowledge base.
-
MATLAB R2023b or later, with Simulink, Embedded Coder, MATLAB Coder and Simulink Coder. The libraries and templates are saved in R2023b.
-
Git.
-
A compiler for the controller.
GOcontrollInstallCompilersin the MATLAB Command Window downloads and installs the tested versions for the current user, where the build finds them without anyPATHsetting:For Command Compiler Name the blockset calls Moduline S1 GOcontrollInstallCompilers S1Arm GNU Toolchain arm-none-eabi 14.2.rel1 arm-none-eabi-gccModuline M1, L4, HMI1 (Compiler = GCC) GOcontrollInstallCompilers LinuxGCC 9.2-2019.12 aarch64-none-linux-gnu aarch64-none-linux-gnu-gccModuline M1, L4, HMI1 (Compiler = Zig) GOcontrollInstallCompilers ZigZig 0.14.1 zigA compiler is looked up in this order: a folder filled in in
blockset/utility_functions/getInstallationLocation.m, then the compilers installed withGOcontrollInstallCompilers(%LOCALAPPDATA%\GOcontroll\tcon Windows,~/.gocontroll/tcelsewhere), then the systemPATH.
The recommended layout keeps the blockset in a subfolder of your project:
MyProject/ your own repository
├── MyModel.slx your models
├── startup.m puts the blockset on the MATLAB path
├── librarySetup.m forwards to the blockset
└── GOcontroll-Simulink/ this repository, as a submodule
└── blockset/
└── GOcontroll-CodeBase/ the C code base, a submodule of this repository
GOcontroll-Simulink-Starter is exactly this layout. To add the blockset to an existing repository instead:
git submodule add https://github.com/GOcontroll/GOcontroll-Simulink.git GOcontroll-Simulink
git submodule update --init --recursive
and copy startup.m and librarySetup.m from the starter into the root of your project.
Then:
- Start MATLAB in the project folder.
startup.mputs the blockset on the path. - New > Simulink Model, group GOcontroll: choose the template GOcontroll Moduline S1 or GOcontroll Moduline M1 / L4 / HMI1, and save the model in the project folder.
- Choose the controller under Configuration Parameters > Code Generation > GOcontroll options > Target.
- Build (Ctrl+B) with the project folder as MATLAB's current folder.
A project made with blockset 4 can keep its models: see Moving a project from blockset 4 to blockset 5.
A build writes <model>_<major>.<minor>.<patch> with the extensions .elf, .a2l and .map
(Moduline S1 also .srec and .bin) into build/ next to the model. The version comes from
the Software version block in the model.
With GOcontroll options > Use precompiled binary (the default) the first build compiles the
CodeBase and keeps its objects in build/codebase_objs/<platform>-<compiler>/; later builds
link them and compile only the model and GO_xcp.c, which carries the station ID of each
build. When a CodeBase file, the compiler or its flags change,
the next build compiles the CodeBase again by itself. Always recompile compiles it in every
build. test/go_codebase_cache_test.m tests the cache.
From the MATLAB command window, with the newest build in build/:
| Controller | Command | How |
|---|---|---|
| Moduline M1, L4, HMI1 | ManualUpload <model> <controller address> |
The .elf and .a2l go to the go-upload-server on the controller (port 8001; port= for another) |
| Moduline S1 | ManualUpload <model> |
The .bin is packed for the controller and sent over Bluetooth; the controller programs it and restarts |
Or let every build do it (since 5.0.1): Configuration Parameters > Code Generation > GOcontroll
options > Upload > Auto upload. It is off by default. A Linux controller is reached at the
XCP address and the Upload port. An upload that fails leaves the build in build/ and
shows a warning.
For the Moduline S1 (new in 5.0.1):
- Bluetooth must be on, on a Windows or macOS computer, and the controller powered and within a few metres. Only one host can be connected to a controller: disconnect the phone app and the GOcontroll Suite first.
- With one Moduline S1 in range nothing has to be chosen. With more than one, name the controller
by the serial number on its label or by its Bluetooth address: the option S1 controller, or
ManualUpload <model> A4CG-B034-A003-A002. - The package carries the App ID the controller reports and the version of the build. It is not signed: a controller that takes signed software only refuses it, and the upload says so before anything is sent.
test/go_s1_upload_test.m checks the package and the upload without a controller:
runtests('test/go_s1_upload_test.m') in the blockset folder, after librarySetup.
In a project that carries this repository as a submodule:
git submodule update --remote GOcontroll-Simulink
git -C GOcontroll-Simulink submodule update --init --recursive
The first command fetches the newest blockset; the second puts the code base inside it on the version that belongs to that blockset. Restart MATLAB afterwards. Your project records which version of the blockset it uses; commit the changed submodule together with your models once they build with the new version.
Keep one copy of the blockset in MATLAB. When MATLAB also reaches another one, such as the
GOcontroll-Simulink Add-On or another clone on the MATLAB path, Simulink can take the system
target file and the blocks from that copy, and options of this version are missing.
librarySetup then warns and names the other copy; uninstall it or remove it from the path,
and restart MATLAB. test/go_other_blocksets_test.m tests this check.
git clone --recurse-submodules https://github.com/GOcontroll/GOcontroll-Simulink.git
The blockset relies on GOcontroll-CodeBase,
which is a submodule in blockset/GOcontroll-CodeBase. Without --recurse-submodules, run
git submodule update --init --recursive afterwards.
A project made with blockset 4 uses the GOcontroll-Simulink Add-On, or a copy of the blockset
in the project, and its models have the system target file ert_linux.tlc. The models can stay
as they are. They need the blockset as a submodule and the new target ert_gocontroll.tlc. The
blocks stay linked to the same libraries.
1. Before you start. Commit your work and close the models. If blockset 4 is still installed, note the popup values of the GOcontroll blocks first. Step 5 explains why.
mdl = 'MyModel'; % with blockset 4 still on the path
load_system(mdl);
blks = find_system(mdl, 'FollowLinks', 'on', 'LookUnderMasks', 'all', 'Type', 'block');
fid = fopen([mdl '_popups_v4.txt'], 'w');
for k = 1:numel(blks)
m = Simulink.Mask.get(blks{k});
if isempty(m), continue; end
for p = m.Parameters(strcmp({m.Parameters.Type}, 'popup'))
fprintf(fid, '%s | %s | %s\n', getfullname(blks{k}), p.Name, p.Value);
end
end
fclose(fid);2. Remove blockset 4. Uninstall the GOcontroll-Simulink Add-On (Home > Add-Ons > Manage
Add-Ons), or delete the copy of the blockset and take it off the MATLAB path. Also remove
start-up code that switches the Add-On on, such as matlab.addons.enableAddon('GOcontroll-Simulink')
in a start-up file of a MATLAB project. Then restart MATLAB.
3. Add blockset 5 to the project. In the project folder:
git submodule add -b main https://github.com/GOcontroll/GOcontroll-Simulink.git GOcontroll-Simulink
git submodule update --init --recursive
Copy startup.m and librarySetup.m from
GOcontroll-Simulink-Starter into
the project folder, and add the lines of its .gitignore to your own. If the project is a
MATLAB project (.prj), also add librarySetup.m as a start-up file (Project > Startup
Shutdown), so that the blockset is on the path before a model opens. Close and reopen the
project, or start MATLAB in the project folder. which ert_gocontroll.tlc must show the file in
GOcontroll-Simulink.
4. Switch each model to the new target. Run this in the project folder for each model. The
model must be saved and closed first. Set target to the controller of the model.
mdl = 'MyModel';
target = 'Moduline L4'; % 'Moduline M1', 'Moduline L4' or 'Moduline HMI1'
load_system(mdl);
cs = getActiveConfigSet(mdl);
keep = {'tlcXcpTcpAddress', 'tlcXcpTcpPort', 'tlcLinuxPriority', 'tlcLinuxCompiler'};
old = cellfun(@(n) get_param(cs, n), keep, 'UniformOutput', false);
% Switching the target resets general settings (solver, optimisation, code style, ...) to the
% Embedded Coder defaults. Note them all and put them back afterwards.
names = fieldnames(get_param(cs, 'ObjectParameters'));
before = {};
for k = 1:numel(names)
try, before(end+1, :) = {names{k}, get_param(cs, names{k})}; catch, end %#ok<AGROW>
end
set_param(cs, 'SystemTargetFile', 'ert_gocontroll.tlc');
targetOwn = {'SystemTargetFile', 'TemplateMakefile', 'ERTCustomFileTemplate', 'Description', 'GenerateMakefile'};
for k = 1:size(before, 1)
n = before{k, 1};
if startsWith(n, {'tlc', 'Prod', 'Target'}) || any(strcmp(n, targetOwn)), continue; end
try
if ~isequal(get_param(cs, n), before{k, 2}), set_param(cs, n, before{k, 2}); end
catch
end
end
set_param(cs, 'tlcGOcontrollTarget', target);
set_param(cs, 'tlcGOcontrollPlatformLock', 'Linux');
for k = 1:numel(keep), set_param(cs, keep{k}, old{k}); end
go_sync_target_options(mdl);
% The model callbacks of the templates: load the blockset, and repair the options when
% another blockset shadowed the target file.
if isempty(strtrim(get_param(mdl, 'PreLoadFcn'))), set_param(mdl, 'PreLoadFcn', 'librarySetup;'); end
set_param(mdl, 'PostLoadFcn', sprintf('go_repair_target_options(bdroot, true);\n%s', get_param(mdl, 'PostLoadFcn')));
set_param(mdl, 'SimulationCommand', 'update'); % runs every mask initialization
save_system(mdl);Upload is Do not upload after the switch. Set Auto upload again if the model used it.
5. Check the popup values. Blockset 5 renamed some popup options. When a saved value no
longer exists, Simulink takes the first option. It gives no error and the model builds, but
for example a different pin is used. Each case shows up once as a warning
Invalid setting in <block> (mask) '<name>' for parameter '<parameter>'. Ignore the warnings
for canBus and can_if: the mask initialization fills those lists itself. Set every other
reported parameter to the value it had. If you made the list in step 1, run the same code again
with _popups_v5.txt and compare the two files. Otherwise use the old model file from git
(git show HEAD~1:MyModel.slx). Known renames from 4.6.0 to 5:
| Block | Parameter | Blockset 4 | Blockset 5 |
|---|---|---|---|
| K15 Voltage | k15pin |
K15-1 (Connector C pin 2) and so on |
K15-1 Connector C pin 2 and so on (without the brackets) |
| CAN Receive, CAN Send | ContrType |
GOcontroll Moduline IV / Mini / Display |
Moduline L4 / M1 / HMI1 |
| Output Module (6 channel), before 4.6.0 | C1flmod … C6flmod |
Moduleslot 1 … |
Module 1 … |
The ContrType popup of the module blocks, K15 Voltage and K30 Voltage is gone. It now
follows Target by itself.
6. Own blocks that call the code base. Blockset 5 comes with
GOcontroll-CodeBase, which has other
names. An S-function, a TLC file or C code of your own that calls the code base of blockset 4
has to use the new names. module_common.tlc keeps its functions. For example:
| Blockset 4 | Blockset 5 |
|---|---|
#include "GocontrollProcessorboard.h" |
#include "GO_board.h" and #include "GO_communication_modules.h" |
GocontrollProcessorboard_SendSpi(...) |
GO_communication_modules_send_spi(...) (same arguments) |
GocontrollProcessorboard_SendReceiveSpi(...) |
GO_communication_modules_send_receive_spi(...) (same arguments) |
GocontrollProcessorboard_ModuleInitialize(slot) |
GO_communication_modules_initialize(slot) |
GocontrollProcessorboard_GetHardwareVersion() |
GO_board_get_hardware_version() |
#include "GocontrollLin.h" |
#include "GO_communication_lin.h" |
GocontrollLin_InitializeInterface() |
GO_communication_lin_initialize_interface() |
For other functions, look in the headers in blockset/GOcontroll-CodeBase/code. Driver state
that was global in blockset 4 is private now (static), for example sl of the LIN driver.
Code that used it gets a link error (undefined reference) and has to keep its own handle, for
example by opening the serial port itself.
7. Build and commit. First delete the build results of blockset 4: slprj/,
<model>_generated_code/ and <model>.slxc. With those still in place, the first build stops
before it starts with Dot indexing is not supported for variables of this type. Then build
with Ctrl+B. The .elf, .a2l and .map are now written to
build/, so a calibration tool that opened the .a2l next to the model has to open the one in
build/. Commit the models, the submodule (GOcontroll-Simulink and .gitmodules) and the new
files together.
Blockset 4.x is on the branch gps
(release V4.6.0). Version 5 has a different folder layout and one target for all controllers.
A project made with 4.x can be moved over: see
Moving a project from blockset 4 to blockset 5.
MIT, see LICENSE. The model templates carry a disclaimer: read it before use.