Hardware Interrupt
Trigger downstream function-call subsystems from interrupt service routine
Since R2021b
Add-On Required: This feature requires the Embedded Coder Support Package for STMicroelectronics STM32 Processors add-on.
Libraries:
Embedded Coder Support Package for STMicroelectronics STM32 Processors /
STM32F2xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors /
STM32F3xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors /
STM32F4xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors /
STM32F7xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors /
STM32G4xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors /
STM32H7xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors /
STM32L4xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors /
STM32L5xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors /
STM32U5xx Based Boards
Embedded Coder Support Package for STMicroelectronics STM32 Processors /
STM32WBxx Based Boards
Description
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 andADCIRQ_Handler
in the Interrupt name parameter from the hardware interrupt block.Select
ADC1 Reg EoCS
orADC1 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.
Note
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.
LL_GPIO_SetPinMode(GPIOD, LL_GPIO_PIN_3, LL_GPIO_MODE_INPUT);
The ISR's are generated in the model_interrupts.c
file.
To know more about when not to use the custom event, refer to Limitations.
Examples
Ports
Input
Output
Parameters
Limitations
Custom events should not be used, when interrupt or event generation is selected from the block or configuration parameter. You might observe that the generated code when executed on the hardware board can get stuck infinitely in the Hardware Interrupt service routine. Ensure that the supported event generation from the block should not be enabled when using the supported event as custom event.
Also, ensure that enabling of custom event should not be part of initialize subsystem. It should executed during run time.
Extended Capabilities
Version History
Introduced in R2021b