Main Content

Set Up Scheduling Options for STM32 Processor-Based Boards

You can run your model using Baremetal or FreeRTOS operating system that you select in Configuration Parameters > Hardware Implementation > Hardware board settings > Operating system/scheduler > Operating system.

To set the scheduling options for your model to run on the target hardware, follow the steps:

  1. In the Configuration Parameters dialog box, select Hardware Implementation.

  2. From the Hardware board drop-down list, select any STM32 processor based board. For example: STM32F7xx Based (Double precision FPU).

  3. Select Baremetal or FreeRTOS in Operating system parameter.

    Note

    When you select FreeRTOS as operating system in Configuration parameters, ensure to select the Interface as CMSIS_V2 under Middleware > FREERTOS > Interface > CMSIS_V2 in STM32CubeMX project.

  4. Select an option from Build action drop-down list for the build process during code generation.

  5. Click Apply.

Baremetal Scheduling

The Baremetal runs the scheduler in multitasking, multirate mode. You can also choose single tasking for your model in the Solver pane. The model blocks run in a periodical fashion clocked by the periodical interrupt whose period is set to the base sample time of the model. Use Baremetal for faster context switching, more efficient use of stack memory, and to gain visibility of the scheduler code.

An example of how the code is generated for the STM32 processor based boards that uses SysTick Scheduler as the Base rate trigger follows:

The SysTick timer is configured so that the base rate sample time of the model corresponds to the interrupt rate. The timer period and prescaler are calculated and set up to produce the desired rate.

BaseRateSampleTime=TimerPeriodTimerClockSpeed

The minimum achievable base rate sample time depends on the model complexity. The maximum value depends on the maximum timer period value (224–1 for SysTick) and the CPU clock speed.

FreeRTOS Scheduling

With FreeRTOS, you can schedule to run your code based on the rates present in your model. The FreeRTOS provides a standard programming interface with functions that support thread management and time management.

FreeRTOS Simulink Configurations

  • When using FreeRTOS, ensure to set your model base rate to a value greater than or equal to 1 ms.

  • The FreeRTOS supports a maximum of 56 thread priorities i.e. between (0 - 55), in which 1 - 40 thread priorities can be used for scheduling model rates. 41-55 thread priorities are reserved for custom used defined higher priority threads. Idle thread priority is reserved for external mode simulation.

    Note

    Software timer is used for scheduling the model rates. The timer task priority should be set to a priority greater than the highest scheduling rate (40 is the base rate).

  • When using the FreeRTOS, the value that you specify in Configuration Parameters > Code Generation > Optimization > Advance parameters > Maximum stack size list applies to each thread. However, the specified stack size may not be fully utilized in some of the threads.

    Note

    The stack size of a thread is set as maximum in Configuration Parameters > Code Generation > Optimization > Advance parameters > Maximum stack size and STM32CubeMX > Middleware > FREERTOS > Kernel settings > Config parameters > Minimal stack size.

FreeRTOS STM32CubeMX Project Configurations

When you select FreeRTOS as operating system, ensure the following settings are configured in STM32CubeMX project.

  • Select the Interface as CMSIS_V2 in STM32CubeMX > Middleware > FREERTOS > Interface.

  • Ensure to allocate enough heap size and timer task priority greater than 40.