Scuola Superiore S. Anna

Research Teaching Personal Contact


Quick links











Embedded Systems - Model-Based Design


You need to have MATLAB-Simulink (at least version 2007) installed.
In addition, you need to have the following:
  • Microchip MPLAB IDE - from the Microchip web page click here
  • Microchip C30 compiler - (register to get free academic version) click here
  • Erika for DsPIC - from Evidence click here
For using the ReTiS toolset for the ERIKA/Flex environment follow these steps:
  1. Get the Flex blockset from here (zip file)
  2. Unpack it "as is" into a directory on your local hard drive.
  3. Setup the MATLAB path to include the directory "blockset" you just created and all its subdirectories (in the MATLAB menu File->Set Path)
  4. The next time you open Simulink, in the Library browser, you should find an additional Library "Model-Based Design ReTiS"
You are almost there. You should now be able to simulate your systems including the Flex mockup. The missing components relate to the code generation part. for this you need additional component in your computer:
  • Python (2.6.4). Available from here
  • PyQt (2.6). Available from here
  • the libxml library for python libxml2-python (2.7.4). Available from here
  • Install the packages in the following order:
    1. python-2.6.4.msi
    2. libxml2-python-2.7.4.win32-py2.6.exe
    3. PyQt-Py2.6-gpl-4.5.4-1.exe
You also need some small library files and our OIL/task code generator.
  1. Create a directory MBD under C: (C:\MBD)
  2. Get the additional Erika code and the code generator for the task skeleton and the OIL from here (zip file)
  3. Put the contents of the zip file into the MBD directory (C:\MBD). There are three directories: mbd_retis, retis_code_generator, to_be_copied
Finally. This is your procedure for generating the code.
  1. Work on your system model until you are happy with it.
  2. Add the Retis blocks for I/O any time you are connecting parts of your model to the Flex mockup. Remember to give a name to the logical I/O channel using the block parameter!
  3. Wrap all the system model (without the flex mockup) in a subsystem and give it a suitable name (such as Stopwatch).
  4. Configure the code generation as follows:
    1. Open the configuration window in simulink (Simulation->Configuration Parameters)
    2. In the "Solver" section select: Solver options - type: fixed step
    3. In the "Real-Time Workshop" section,
      • For the System target file select: ert.tlc (Real-Time Workshop Embedded Coder)
      • disable/uncheck "Generate Makefile"
      • enable/check "Generate code only"
    4. In the "custom code" section, select "Header file" and add to the right (in the Header file: textbox) the line
      #include "retis.h"
    5. In the "Interface" section
      • disable/uncheck support for non-finite numbers, complex numbers and absolute time.
      • disable/uncheck Terminate function required
    6. in the "Templates" section disable/uncheck "Generate an example main program"
    7. close the configuration window
  5. In your model, select your subsystem, right click on it and select "Real-time workshop->Build subsystem"
  6. After confirmation and a few steps, MATLAB/simulink/RTW will create a new directory for you with the name of the subsystem, followed by _ert_rtw. the directory contains the generated .c and .c files and an additional file (created for our custom blocks).
  7. From the directory "to_be_copied" in C:\MBD copy the two files and matlab_out.xml.
  8. Edit the file matlab_out.xml. Replace the content of the element matlab with the contents of the file
  9. Execute (by double clicking) Fill in the subsystem name, the execution rate, and assign a physical index to all the logical devices. Press the button "Generate code".
  10. the program run_codegen will generate additional files, including: conf.oil, retis.c, retis.h and main.c
  11. Put the files generated from run_codegen together with the files generated by Real-Time workshop embedded coder in an Erika project, compile and upload on the board