Main Content

Asynchronous Scheduling for STM32F4-Discovery Board

This example shows you how to model asynchronous scheduling using the Hardware Interrupt block for the STMicroelectronics® STM32F4-Discovery board using Asynchronous Scheduling for STM32F4-Discovery Board using Embedded Coder® Support Package for STMicroelectronics STM32 Processors.

Introduction

Interrupts are events that cause changes in the program flow control outside a normal code sequence. When it happens, the program currently executing is suspended and a piece of code associated with the event (Interrupt service routine) is executed. The interrupts occur asynchronously compared to the periodic rates present in the model.

This example explains how to use the Hardware Interrupt block in a Simulink model for asynchronous event handling on the STM32F4-Discovery board. In this model, the ADC1 is used to measure analog input channels 18 (Vbat) and 5 (connected to PB10). The ADC readings are performed on an ADC End of conversion interrupt.

Prerequisites

We recommend completing:

Required Hardware

To run this example you will need the following hardware:

  • STMicroelectronics STM32F4-Discovery board

  • USB type A to Mini-B cable

Serial communication:

  • USB TTL-232 cable - TTL-232R 3.3V

Notes:

  • This example was tested with the FTDI Friend USB TTL-232R 3.3V adapter.

Hardware Connections

Connect PB10 and PA5 pins on STM32F4-Discovery board. PB10 will drive a stimulus signal to channel 5 of ADC1 (PA5).

Description

The Analog to Digital Converter block is configured to measure the voltage at ADC1 channels 18 and 5 then raise an interrupt at the completion of the conversions. The Hardware Interrupt block generates the corresponding ISR triggered by the ADC1 module. The ISR calls the function-call subsystem connected to the Hardware Interrupt block. Inside the function-call subsystem, the ADC block will output the measured channels on its Data1 and Data2 output ports. The output ports will respectively output the battery voltage (Vbat) and the measurement of PB10 via ADC1 channel 5.

The measured signal levels are converted to actual voltages via scaling functions in the "Vbat Conversion" and the "GPIO Voltage Conversion" subsystems connected to the function-call subsystem.

NOTE: To measure Vbat, check 'Enable Vbat channel' under Configuration Parameters > Hardware Implementation > Target Hardware Resources > ADC Common. VBat requires a specific ADC acquisition window size to be properly configured. Select 480 ADCCLK cycles as the sampling time for Channel 5 and Channel 18 under Configuration Parameters > Hardware Implementation > Target Hardware Resources > ADC 1 to ensure proper ADC conversions.

Any exception during the execution of the model on the STM32F4-Discovery board will trigger a hard fault exception, which is set to trigger the 'Exception Handler' function-call subsystem. The red LED turns on when the exception occurs. For instance, this will happen when you terminate the Monitoring and Tune action while using the Baremetal scheduler.

How to Run the Model

Summary

This example illustrated the procedure to create and react to an interrupt service routine on the STM32F4-Discovery board.