Main Content

Set Up Scheduling Options

You can run your model usingBaremetalorCMSIS-RTOS RTXoperating system that you can select inConfiguration Parameters>Coder Target>Operating system options>Operating system.

By default, theBaremetal在多任务调度程序运行,multirate mode. You can also choose single tasking for your model in theSolverpane. WithBaremetal, you can run the generated code with the scheduler selected in theConfiguration Parameters>Coder Target>Scheduler options>Base rate triggerfor your model. 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. UseBaremetalfor 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 STM32F4-Discovery board that usesSysTick Scheduler作为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.

B a s e R a t e S a m p l e T i m e = T i m e r P e r i o d T i m e r C l o c k S p e e d

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. The CPU clock speed is 168 MHz for the STMicroelectronics Discovery board. If the blocks in the model inherit their sample time value, and a sample time is not explicitly defined, the default value is 0.2 s.

WithCMSIS-RTOS RTX, you can schedule to run your code based on the rates present in your model. The RTOS provides a standard programming interface with functions that support thread management and time management. Use RTOS to integrate with legacy code that depends on the RTOS, such as device driver code.

When using RTOS, make sure to set your model base rate to a value greater than or equal to 1 ms. The RTOS supports a maximum of seven thread priorities, in which the highest six thread priorities are used for scheduling model rates and the idle thread priority is reserved for the external mode simulation. When using the RTOS, the value that you specify inConfiguration Parameters>Optimization>Signals and Parameters>Maximum stack sizedrop-down list applies to each thread. However, the specified stack size may not be fully utilized in some of the threads.

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

  1. In the Configuration Parameters dialog box, selectHardware Implementation.

  2. From theHardware boarddrop-down list, selectSTM32F4–Discovery.

  3. SelectBaremetalorCMSIS-RTOS RTXin Operating system parameter.

  4. If you have selectedBaremetal作为the operating system, select a scheduler option from theBase rate triggerdrop-down list.

  5. Select an option fromBuild actiondrop-down list for the build process during code generation.

  6. ClickApply.

For more information see,Getting Started with Embedded Coder Support Package for STMicroelectronics Discovery Boards.