Set Up Scheduling Options for STM32 Processor-Based Boards
You can run your model using
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:
In the Configuration Parameters dialog box, select Hardware Implementation.
From the Hardware board drop-down list, select any STM32 processor based board. For example:
STM32F7xx Based (Double precision FPU).
FreeRTOSin Operating system parameter.
When you select
FreeRTOSas operating system in Configuration parameters, ensure to select the Interface as
CMSIS_V2under Middleware > FREERTOS > Interface > CMSIS_V2 in STM32CubeMX project.
Select an option from Build action drop-down list for the build process during code generation.
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
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.
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, 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
FreeRTOSsupports a maximum of
56thread priorities i.e. between (0 - 55), in which
1 - 40thread priorities can be used for scheduling model rates.
41-55thread priorities are reserved for custom used defined higher priority threads. Idle thread priority is reserved for external mode simulation.
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.
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_V2in STM32CubeMX > Middleware > FREERTOS > Interface.
Ensure to allocate enough heap size and timer task priority greater than