Main Content

Hardware Interrupt

Trigger downstream function-call subsystems from interrupt service routine

  • Library:
  • Embedded Coder Support Package for STMicroelectronics Discovery Boards/STM32F4xx Based Boards

    Embedded Coder Support Package for STMicroelectronics Discovery Boards/STM32F7xx Based Boards

    Embedded Coder Support Package for STMicroelectronics Discovery Boards/STM32G4xx Based Boards

    Embedded Coder Support Package for STMicroelectronics Discovery Boards/STM32H7xx Based Boards

  • Hardware Interrupt block


Use the Hardware Interrupt block to create an interrupt service routine (ISR) automatically in the generated code of your model to react to the events selected. The ISR executes the downstream function-call subsystem associated with event ports of the block.

The function call subsystem associated with the event output port run at same priority as that of ISR priority.

Using this block you can:

  • Create ISRs on STM32 Processor Based Boards.

  • Set ISR priority.

  • Enable or disable interrupt preemption.

This block generates code only for the specified ISR and selected events. To change the configuration, enable the interrupt and specific triggering options use the settings of the chosen peripheral.

For example, to create an ISR for the ADC peripheral on the Hardware Interrupt block:

  • Model must have an Analog to digital Converter (ADC) block.

  • To trigger an ISR from a ADC, select the Enable Regular EoCS Interrupt or Enable Injected EoCS Interrupt check box in Configuration Parameters > Hardware Implementation > Target Hardware Resources > ADC1. Selecting this check box has no effect if your model does not have a Analog to Digital Converter block.

  • Select Analog to digital converter (ADC) in the Interrupt group parameter and ADCIRQ_Handler in the Interrupt name parameter from the hardware interrupt block.

  • Select ADC1 Reg EoCS or ADC1 Inj EoCS event name in the Events to serve parameter.

An ISR for a DMA and Watchdog interrupt is automatically triggered when you choose the necessary Hardware Interrupt block settings because the DMA transfer complete interrupt is enabled and Watchdog interrupt is enabled check box is selected by default in Configuration Parameters > Hardware Implementation > Target Hardware Resources > ADC.


For STM32H7xx based processors, the code generated by STM32CubeMX 6.2.0 version for enabling external interrupt does not configure the selected GPIO pin in input mode. To trigger the external interrupt on selected GPIO pin, add custom code to configure the pin mode as input.

You can use System Initialize block in the model to add the custom code.

For example, to enable the EXTI3 interrupt on pin PD3.

  • Configure PD3 pin as GPIO_EXTI3 in STM32CubeMX project.

  • Add a System Initialize block in your model.

  • Specify the following custom code in the System Initialize Function Execution Code section of the System Initialize block. This configures the pin PD3 in input mode.


The ISR's are generated in the model_interrupts.c file.



expand all

The simulation-only message input port, when connected to an Function-Call Generator block, the block acts as pass-through with the output emitted on the name Event port in simulation.


To enable this port, select the Enable simulation port parameter.


expand all

The output of this block is a function-call. The number of function call outputs will be same as events selected to serve in an ISR.


expand all

Interrupt group lists all the ISR for a same type of peripherals available for STM32 Processor Based Boards. Selecting an interrupt group changes the list of values in the Interrupt name parameter.

The interrupt name specifies the ISR to be generated for the hardware interrupt block. The Interrupt name corresponds to the specific entry in the processor's interrupt vector table. The available ISRs depend on the interrupt group.

This read-only parameter indicates the position of the selected ISR in the interrupt vector table of your target hardware.

Select events or custom event and there respective events execution order from the Events to serve group to service events for the selected Interrupt name. You can select custom events to execute along with the other selected events.

The value you specify in this parameter sets the priority of the downstream function-call subsystem. The simulink task priority of the selected (ISR) is relative to the model base rate priority.


The default model base sample rate priority is set to 40 with a lower priority value indicating a higher priority task. To achieve this the Higher priority value indicates higher task priority option must be enabled in Configuration Parameters > Solver pane.

By default, an interrupt can be preempted by a higher priority interrupt. Selecting this option allows low priority interrupts to complete their execution without being preempted by other interrupts.

Select this option to clear all the interrupt status flags after the events service.

Select this parameter to add an SoC Blockset™ compatible simulation input port.

Version History

Introduced in R2021b