Skip to main content
LVara.1
Associate III
April 10, 2022
Question

External IRQ control via Cortex library or via HAL library

  • April 10, 2022
  • 7 replies
  • 4455 views

Hi, I'm trying to use IRQ Software calls with Nucleo-F4 boards in STMCubeMx 1.8 environment.

The UM1725 - Rev 7, pag. 346, tells me to use the HAL_Generate_SWI.

The call, included in stm32f4xx_hal_exti, requires you to define two simple structures: EXTI_HandleTypeDef and EXTI_ConfigTypeDef and the test program seems to work.

I have noticed that when I generate the configuration code with MX, the NVIC libraries are still used for interrupts , present in stm32f4xx_hal_cortex. In the Cortex Library there in no SW IRQ generation call.

The questions are these:

for external interrupts, when to use the library in stm32f4xx_hal_exti and when to use those in stm32f4xx_hal_cortex?

 Anyone have an example of SWI interrupt handling for F4 models? (nothing in the web)

 Many Thanks.

LV

This topic has been closed for replies.

7 replies

Pavel A.
April 10, 2022

@Community member​ From your questions it looks like you are very new to STM32.

If so, you can find helpful online STM32 education materials on STM32L4.

The STM32L4 family is similar to F4.

See the NVIC and EXTI presentations.

Tesla DeLorean
Guru
April 10, 2022

The HAL EXTI functions program the unit that signals the NVIC hardware. It generates several interrupt signals, from pin or other resources. Mapping individual or blocks of pins.

The NVIC is used for all the other interrupt sources too.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
LVara.1
LVara.1Author
Associate III
April 11, 2022

Thank you for the interesting emails, but maybe I'm not clear in my doubts.

In trying to generate a software interrupt, I wanted to use tools

high-level like HAL libraries (register programming is possible as I used to 30 or 40 years ago, but now it's a bit boring, and maybe I'm not old enough anymore).

In fact, in the file stm32f7xx_hal_exti (NOT in stm32f4xx_hal_cortex) I found a useful call:

HAL_Exti_GenerateExti (), and I tried to read up on UM1725.

In the 2017 version of this document it does not mention it. Strange.

In the 2021 version I found some pages.

But here are some notes:

a)

the documentation talks about "line_X", not GPIO_PIN_X. No problem it's about doing some simple #define (me, not MX).

b)

The documentation talks about defining a CallBack of type void ..mmm .. the call back in use with the HAL_GPIO_EXTI_IRQHandler calls use one parameter: the GPIO_PIN_X. I'll make my own callBack.

c)

The documentation does NOT clarify how to recognize the HW call from the SW calls ... mmmm ....

In short, perhaps with an example project (perhaps STM) I could clarify some doubts.

Note: Document UM1725 - Rev 7 there are several silly errors; for example at 25.2.2 point 3 (I didn't have time to read it all).

Thanks

LV

Tesla DeLorean
Guru
April 11, 2022

 __HAL_GPIO_EXTI_GENERATE_SWIT(pinmask) // For pins 0 thru 15, arguable EXTI[0..21] on an L4

__HAL_GPIO_EXTI_GENERATE_SWIT(1 << 8); // -> EXTI9_5_IRQHandler

LL_EXTI_GenerateSWI_0_31(uint32_t ExtiLine); // large subset of these

LL_EXTI_GenerateSWI_32_63(uint32_t ExtiLine) // typically some subset of these

HAL_EXTI_GenerateSWI(EXTI_HandleTypeDef *hexti) // subset of the EXTI source 0..63

These will go into the EXTIxx_IRQHandlers (say EXTI1, or EXTI_PVD(16), TAMP(21), RTC)

You can generate ANY NVIC interrupt via NVIC->STIR, ie USART6_IRQHandler

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
LVara.1
LVara.1Author
Associate III
April 12, 2022

It could be the right way. But from which document (or which documents) did you get the information? I always wish to be well documented, there are always side effects.

I would like to deepen the study on HAL_EXTI_GenerateSWI (); if I understand correctly, there MUST exist an external pin to be used as a possible sw interrupt generator, but this raises numerous practical questions: a) who generated the interrupt? the HW or the SW? b) how to manage a possible callback? (read my clarification carefully)

Many thanks

Pavel A.
April 11, 2022

> In trying to generate a software interrupt

Trigger an EXTI interrupt by software? Trigger some other interrupt by software? Trigger SWI?

You may be having A/B problem.

LVara.1
LVara.1Author
Associate III
April 12, 2022

I don't quite understand your A / B concerns. Can you clarify better? Do you mean conflicts on the BUS? I accept all suggestions, I am trying to create a document on SW interrupt on M4micro Thanks LV

LVara.1
LVara.1Author
Associate III
April 12, 2022

To clarify the matter, I wrote a simple project for STM32F401RE. The pin, twice involved, is the one reserved for the BLUE key (PC13). If it is pressed (I do not take into account problems related to bouncing here) it generates a HW interrupt and requests a status inversion to the green LED. However, every 3000 msec a SW call is generated which does the same thing (I could have done another thing but I only have one led on the board ...). If you have a Cube development environment (I used 1.8) you can download it from this link, import it and try it. How did I check if it was a SW or HW interrupt? stupidly, checking the status of the button, after the call .... It is certainly a source of errors, but this is not the question, I would say a little more complex and general. LV

Pavel A.
April 12, 2022

> I don't quite understand your A / B concerns

Sorry I meant X/Y problem :) Perhaps triggering EXTI line interrupts does not help to achieve your actual goal/need.

What is the "SW call"? how do you measure 3000 ms - with a timer?

if you want to toggle the LED just toggle it, you don't have to simulate a button press.

LVara.1
LVara.1Author
Associate III
April 13, 2022

Yes, I smulate a pression af the botton press with the STM HAL call HAL_Generate_SWI(13).

LV

Pavel A.
April 14, 2022

What is HAL_Generate_SWI? STM32F4 is Cortex-M4. Maybe you mean HAL_EXTI_GenerateSWI ? or SVC?

Here is an article explaining use of SVC, it allows to pass parameters to the "service" interrupt handlers.

LVara.1
LVara.1Author
Associate III
April 14, 2022

  for HAL_Generate_SWI, as I say, read at STM UM1725 - Rev 7, pag. 346